Skip to content

Commit 74a8536

Browse files
committed
Update to match SDL changes
This changes the parsing grammar and validation rules to more correctly implement the current state of the GraphQL SDL proposal (graphql/graphql-spec#90)
1 parent 37717b8 commit 74a8536

20 files changed

+353
-129
lines changed

src/execution/__tests__/executor-test.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,11 @@ describe('Execute: Handles basic execution tasks', () => {
965965
]);
966966
});
967967

968-
it('fails to execute a query containing a type definition', async () => {
968+
it('executes ignoring invalid non-executable definitions', async () => {
969969
const query = parse(`
970970
{ foo }
971971
972-
type Query { foo: String }
972+
type Query { bar: String }
973973
`);
974974

975975
const schema = new GraphQLSchema({
@@ -983,14 +983,9 @@ describe('Execute: Handles basic execution tasks', () => {
983983

984984
const result = await execute(schema, query);
985985
expect(result).to.deep.equal({
986-
errors: [
987-
{
988-
message: 'GraphQL cannot execute a request containing a ' +
989-
'ObjectTypeDefinition.',
990-
locations: [ { line: 4, column: 7 } ],
991-
path: undefined,
992-
}
993-
]
986+
data: {
987+
foo: null,
988+
},
994989
});
995990
});
996991

src/execution/execute.js

-4
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,6 @@ export function buildExecutionContext(
302302
case Kind.FRAGMENT_DEFINITION:
303303
fragments[definition.name.value] = definition;
304304
break;
305-
default: throw new GraphQLError(
306-
`GraphQL cannot execute a request containing a ${definition.kind}.`,
307-
[ definition ]
308-
);
309305
}
310306
});
311307
if (!operation) {

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ export type {
226226
EnumTypeDefinitionNode,
227227
EnumValueDefinitionNode,
228228
InputObjectTypeDefinitionNode,
229-
TypeExtensionDefinitionNode,
229+
TypeExtensionNode,
230+
ObjectTypeExtensionNode,
230231
DirectiveDefinitionNode,
231232
} from './language';
232233

src/language/__tests__/schema-kitchen-sink.graphql

+1-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ extend type Foo {
6868
seven(argument: [String]): Type
6969
}
7070

71-
extend type Foo @onType {}
72-
73-
type NoFields {}
71+
extend type Foo @onType
7472

7573
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
7674

src/language/__tests__/schema-parser-test.js

+58-25
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,17 @@ extend type Hello {
154154
kind: 'Document',
155155
definitions: [
156156
{
157-
kind: 'TypeExtensionDefinition',
158-
definition: {
159-
kind: 'ObjectTypeDefinition',
160-
name: nameNode('Hello', { start: 13, end: 18 }),
161-
interfaces: [],
162-
directives: [],
163-
fields: [
164-
fieldNode(
165-
nameNode('world', { start: 23, end: 28 }),
166-
typeNode('String', { start: 30, end: 36 }),
167-
{ start: 23, end: 36 }
168-
)
169-
],
170-
loc: { start: 8, end: 38 },
171-
},
157+
kind: 'ObjectTypeExtension',
158+
name: nameNode('Hello', { start: 13, end: 18 }),
159+
interfaces: [],
160+
directives: [],
161+
fields: [
162+
fieldNode(
163+
nameNode('world', { start: 23, end: 28 }),
164+
typeNode('String', { start: 30, end: 36 }),
165+
{ start: 23, end: 36 }
166+
)
167+
],
172168
loc: { start: 1, end: 38 },
173169
}
174170
],
@@ -177,13 +173,39 @@ extend type Hello {
177173
expect(printJson(doc)).to.equal(printJson(expected));
178174
});
179175

176+
it('Extension without fields', () => {
177+
const body = 'extend type Hello implements Greeting';
178+
const doc = parse(body);
179+
const expected = {
180+
kind: 'Document',
181+
definitions: [
182+
{
183+
kind: 'ObjectTypeExtension',
184+
name: nameNode('Hello', { start: 12, end: 17 }),
185+
interfaces: [ typeNode('Greeting', { start: 29, end: 37 }) ],
186+
directives: [],
187+
fields: [],
188+
loc: { start: 0, end: 37 },
189+
}
190+
],
191+
loc: { start: 0, end: 37 }
192+
};
193+
expect(printJson(doc)).to.equal(printJson(expected));
194+
});
195+
180196
it('Extension do not include descriptions', () => {
181197
expect(() => parse(`
182198
"Description"
183199
extend type Hello {
184200
world: String
185201
}
186-
`)).to.throw('Syntax Error GraphQL request (2:7)');
202+
`)).to.throw('Syntax Error GraphQL request (3:7)');
203+
204+
expect(() => parse(`
205+
extend "Description" type Hello {
206+
world: String
207+
}
208+
`)).to.throw('Syntax Error GraphQL request (2:14)');
187209
});
188210

189211
it('Simple non-null type', () => {
@@ -219,9 +241,8 @@ type Hello {
219241
expect(printJson(doc)).to.equal(printJson(expected));
220242
});
221243

222-
223244
it('Simple type inheriting interface', () => {
224-
const body = 'type Hello implements World { }';
245+
const body = 'type Hello implements World { field: String }';
225246
const doc = parse(body);
226247
const expected = {
227248
kind: 'Document',
@@ -231,17 +252,23 @@ type Hello {
231252
name: nameNode('Hello', { start: 5, end: 10 }),
232253
interfaces: [ typeNode('World', { start: 22, end: 27 }) ],
233254
directives: [],
234-
fields: [],
235-
loc: { start: 0, end: 31 },
255+
fields: [
256+
fieldNode(
257+
nameNode('field', { start: 30, end: 35 }),
258+
typeNode('String', { start: 37, end: 43 }),
259+
{ start: 30, end: 43 }
260+
)
261+
],
262+
loc: { start: 0, end: 45 },
236263
}
237264
],
238-
loc: { start: 0, end: 31 },
265+
loc: { start: 0, end: 45 },
239266
};
240267
expect(printJson(doc)).to.equal(printJson(expected));
241268
});
242269

243270
it('Simple type inheriting multiple interfaces', () => {
244-
const body = 'type Hello implements Wo, rld { }';
271+
const body = 'type Hello implements Wo, rld { field: String }';
245272
const doc = parse(body);
246273
const expected = {
247274
kind: 'Document',
@@ -254,11 +281,17 @@ type Hello {
254281
typeNode('rld', { start: 26, end: 29 })
255282
],
256283
directives: [],
257-
fields: [],
258-
loc: { start: 0, end: 33 },
284+
fields: [
285+
fieldNode(
286+
nameNode('field', { start: 32, end: 37 }),
287+
typeNode('String', { start: 39, end: 45 }),
288+
{ start: 32, end: 45 }
289+
)
290+
],
291+
loc: { start: 0, end: 47 },
259292
}
260293
],
261-
loc: { start: 0, end: 33 },
294+
loc: { start: 0, end: 47 },
262295
};
263296
expect(printJson(doc)).to.equal(printJson(expected));
264297
});

src/language/__tests__/schema-printer-test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ extend type Foo {
114114
seven(argument: [String]): Type
115115
}
116116
117-
extend type Foo @onType {}
118-
119-
type NoFields {}
117+
extend type Foo @onType
120118
121119
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
122120

src/language/ast.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export type ASTNode =
153153
| EnumTypeDefinitionNode
154154
| EnumValueDefinitionNode
155155
| InputObjectTypeDefinitionNode
156-
| TypeExtensionDefinitionNode
156+
| ObjectTypeExtensionNode
157157
| DirectiveDefinitionNode;
158158

159159
// Name
@@ -363,12 +363,13 @@ export type NonNullTypeNode = {
363363
type: NamedTypeNode | ListTypeNode;
364364
};
365365

366+
366367
// Type System Definition
367368

368369
export type TypeSystemDefinitionNode =
369370
| SchemaDefinitionNode
370371
| TypeDefinitionNode
371-
| TypeExtensionDefinitionNode
372+
| TypeExtensionNode
372373
| DirectiveDefinitionNode;
373374

374375
export type SchemaDefinitionNode = {
@@ -385,6 +386,9 @@ export type OperationTypeDefinitionNode = {
385386
type: NamedTypeNode;
386387
};
387388

389+
390+
// Type Definition
391+
388392
export type TypeDefinitionNode =
389393
| ScalarTypeDefinitionNode
390394
| ObjectTypeDefinitionNode
@@ -475,12 +479,24 @@ export type InputObjectTypeDefinitionNode = {
475479
fields: Array<InputValueDefinitionNode>;
476480
};
477481

478-
export type TypeExtensionDefinitionNode = {
479-
kind: 'TypeExtensionDefinition';
482+
483+
// Type Extensions
484+
485+
export type TypeExtensionNode =
486+
| ObjectTypeExtensionNode;
487+
488+
export type ObjectTypeExtensionNode = {
489+
kind: 'ObjectTypeExtension';
480490
loc?: Location;
481-
definition: ObjectTypeDefinitionNode;
491+
name: NameNode;
492+
interfaces?: ?Array<NamedTypeNode>;
493+
directives?: ?Array<DirectiveNode>;
494+
fields?: ?Array<FieldDefinitionNode>;
482495
};
483496

497+
498+
// Directive Definitions
499+
484500
export type DirectiveDefinitionNode = {
485501
kind: 'DirectiveDefinition';
486502
loc?: Location;

src/language/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export type {
7373
EnumTypeDefinitionNode,
7474
EnumValueDefinitionNode,
7575
InputObjectTypeDefinitionNode,
76-
TypeExtensionDefinitionNode,
76+
TypeExtensionNode,
77+
ObjectTypeExtensionNode,
7778
DirectiveDefinitionNode,
7879
} from './ast';

src/language/kinds.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition';
6868

6969
// Type Extensions
7070

71-
export const TYPE_EXTENSION_DEFINITION = 'TypeExtensionDefinition';
71+
export const OBJECT_TYPE_EXTENSION = 'ObjectTypeExtension';
7272

7373
// Directive Definitions
7474

0 commit comments

Comments
 (0)