Skip to content

Commit 84adacf

Browse files
committed
Add tests for type and enum resolvers
1 parent 1b0f68a commit 84adacf

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/utilities/__tests__/buildASTSchema-test.js

+48
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,54 @@ describe('Schema Builder', () => {
7474
});
7575
});
7676

77+
it('can lookup type resolvers', () => {
78+
const schema = buildSchema(
79+
`
80+
type Query {
81+
mult(a: Int!, b: Int!): Int!
82+
}
83+
`,
84+
{
85+
resolvers: {
86+
Query: {
87+
mult: (_: { ... }, { a, b }) => a * b,
88+
},
89+
},
90+
},
91+
);
92+
93+
expect(graphqlSync(schema, '{ mult(a: 3, b: 4) }', null)).to.deep.equal({
94+
data: { mult: 12 },
95+
});
96+
});
97+
98+
it('can lookup enum values', () => {
99+
const schema = buildSchema(
100+
`
101+
enum Color { RED, GREEN, BLUE }
102+
type Query {
103+
colors: [Color!]!
104+
}
105+
`,
106+
{
107+
resolvers: {
108+
Query: {
109+
colors: () => [4, 2, 1],
110+
},
111+
Color: {
112+
RED: 1,
113+
GREEN: 2,
114+
BLUE: 4,
115+
},
116+
},
117+
},
118+
);
119+
120+
expect(graphqlSync(schema, '{ colors }', null)).to.deep.equal({
121+
data: { colors: ['BLUE', 'GREEN', 'RED'] },
122+
});
123+
});
124+
77125
it('Empty type', () => {
78126
const sdl = dedent`
79127
type EmptyType

0 commit comments

Comments
 (0)