Skip to content

Commit 0111863

Browse files
authored
fix ExecutorSchema isNullType (#128)
1 parent feb7888 commit 0111863

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

.changeset/moody-trees-give.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'graphql-executor': patch
3+
---
4+
5+
Fix ExecutorSchema isNonNullType method
6+
7+
Client documents may wrap input types with non-nullable wrapper types not present in the schema. The ExecutorSchema should recognize these non-nullable types as such.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
4+
import type { GraphQLNonNull, NamedTypeNode, NonNullTypeNode } from 'graphql';
5+
import {
6+
GraphQLInputObjectType,
7+
GraphQLObjectType,
8+
GraphQLSchema,
9+
GraphQLString,
10+
Kind,
11+
} from 'graphql';
12+
13+
import { toExecutorSchema } from '..';
14+
15+
describe('ExecutorSchema:', () => {
16+
const input = new GraphQLInputObjectType({
17+
name: 'Input',
18+
fields: {
19+
inputField: {
20+
type: GraphQLString,
21+
},
22+
},
23+
});
24+
const query = new GraphQLObjectType({
25+
name: 'Query',
26+
fields: {
27+
field: {
28+
type: GraphQLString,
29+
args: {
30+
arg: {
31+
type: input,
32+
},
33+
},
34+
},
35+
},
36+
});
37+
const schema = new GraphQLSchema({
38+
query,
39+
});
40+
41+
it('does not throw', () => {
42+
expect(() => toExecutorSchema(schema)).not.to.throw();
43+
});
44+
45+
it('allows retrieving output types', () => {
46+
const executorSchema = toExecutorSchema(schema);
47+
const namedTypeNode: NamedTypeNode = {
48+
kind: Kind.NAMED_TYPE,
49+
name: {
50+
kind: Kind.NAME,
51+
value: 'Query',
52+
},
53+
};
54+
const type = executorSchema.getType(namedTypeNode);
55+
expect(type).to.equal(query);
56+
});
57+
58+
it('allows retrieving input types', () => {
59+
const executorSchema = toExecutorSchema(schema);
60+
const namedTypeNode: NamedTypeNode = {
61+
kind: Kind.NAMED_TYPE,
62+
name: {
63+
kind: Kind.NAME,
64+
value: 'Input',
65+
},
66+
};
67+
const type = executorSchema.getType(namedTypeNode);
68+
expect(type).to.equal(input);
69+
expect(executorSchema.isInputType(type)).to.equal(true);
70+
});
71+
72+
it('allows retrieving input types defined in schema wrapped with non-null', () => {
73+
const executorSchema = toExecutorSchema(schema);
74+
const nonNullTypeNode: NonNullTypeNode = {
75+
kind: Kind.NON_NULL_TYPE,
76+
type: {
77+
kind: Kind.NAMED_TYPE,
78+
name: {
79+
kind: Kind.NAME,
80+
value: 'Input',
81+
},
82+
},
83+
};
84+
const type = executorSchema.getType(nonNullTypeNode);
85+
expect(type).to.not.equal(undefined);
86+
expect(executorSchema.isNonNullType(type)).to.equal(true);
87+
expect(executorSchema.isInputType(type)).to.equal(true);
88+
expect((type as GraphQLNonNull<any>).ofType).to.equal(input);
89+
});
90+
});

src/execution/toExecutorSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ function _toExecutorSchema(schema: GraphQLSchema): ExecutorSchema {
351351

352352
for (const directive of [...schema.getDirectives()]) {
353353
for (const arg of directive.args) {
354-
inputTypes.add(arg.type);
355354
addInputType(arg.type);
356355
processType(arg.type);
357356
}
@@ -365,6 +364,7 @@ function _toExecutorSchema(schema: GraphQLSchema): ExecutorSchema {
365364
const typeString = possibleInputType.toString();
366365
if (!typeTree.has(typeString)) {
367366
addInputType(possibleInputType);
367+
processType(possibleInputType);
368368
}
369369
}
370370
}

0 commit comments

Comments
 (0)