Skip to content

Commit b49653f

Browse files
committed
add implements to SDL for unions
1 parent 5f247e0 commit b49653f

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

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

+21
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ describe('Schema Parser', () => {
230230
});
231231
});
232232

233+
it('Union extension without types', () => {
234+
const doc = parse('extend union HelloOrGoodbye implements Greeting');
235+
expectJSON(doc).toDeepEqual({
236+
kind: 'Document',
237+
definitions: [
238+
{
239+
kind: 'UnionTypeExtension',
240+
name: nameNode('HelloOrGoodbye', { start: 13, end: 27 }),
241+
interfaces: [typeNode('Greeting', { start: 39, end: 47 })],
242+
directives: [],
243+
types: [],
244+
loc: { start: 0, end: 47 },
245+
},
246+
],
247+
loc: { start: 0, end: 47 },
248+
});
249+
});
250+
233251
it('Object extension without fields followed by extension', () => {
234252
const doc = parse(`
235253
extend type Hello implements Greeting
@@ -880,6 +898,7 @@ describe('Schema Parser', () => {
880898
kind: 'UnionTypeDefinition',
881899
name: nameNode('Hello', { start: 6, end: 11 }),
882900
description: undefined,
901+
interfaces: [],
883902
directives: [],
884903
types: [typeNode('World', { start: 14, end: 19 })],
885904
loc: { start: 0, end: 19 },
@@ -899,6 +918,7 @@ describe('Schema Parser', () => {
899918
kind: 'UnionTypeDefinition',
900919
name: nameNode('Hello', { start: 6, end: 11 }),
901920
description: undefined,
921+
interfaces: [],
902922
directives: [],
903923
types: [
904924
typeNode('Wo', { start: 14, end: 16 }),
@@ -921,6 +941,7 @@ describe('Schema Parser', () => {
921941
kind: 'UnionTypeDefinition',
922942
name: nameNode('Hello', { start: 6, end: 11 }),
923943
description: undefined,
944+
interfaces: [],
924945
directives: [],
925946
types: [
926947
typeNode('Wo', { start: 16, end: 18 }),

src/language/ast.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,13 @@ export const QueryDocumentKeys: {
262262
'directives',
263263
'fields',
264264
],
265-
UnionTypeDefinition: ['description', 'name', 'directives', 'types'],
265+
UnionTypeDefinition: [
266+
'description',
267+
'name',
268+
'interfaces',
269+
'directives',
270+
'types',
271+
],
266272
EnumTypeDefinition: ['description', 'name', 'directives', 'values'],
267273
EnumValueDefinition: ['description', 'name', 'directives'],
268274
InputObjectTypeDefinition: ['description', 'name', 'directives', 'fields'],
@@ -274,7 +280,7 @@ export const QueryDocumentKeys: {
274280
ScalarTypeExtension: ['name', 'directives'],
275281
ObjectTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
276282
InterfaceTypeExtension: ['name', 'interfaces', 'directives', 'fields'],
277-
UnionTypeExtension: ['name', 'directives', 'types'],
283+
UnionTypeExtension: ['name', 'interfaces', 'directives', 'types'],
278284
EnumTypeExtension: ['name', 'directives', 'values'],
279285
InputObjectTypeExtension: ['name', 'directives', 'fields'],
280286
};
@@ -624,6 +630,7 @@ export interface UnionTypeDefinitionNode {
624630
readonly loc?: Location;
625631
readonly description?: StringValueNode;
626632
readonly name: NameNode;
633+
readonly interfaces?: ReadonlyArray<NamedTypeNode>;
627634
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
628635
readonly types?: ReadonlyArray<NamedTypeNode>;
629636
}
@@ -716,6 +723,7 @@ export interface UnionTypeExtensionNode {
716723
readonly kind: Kind.UNION_TYPE_EXTENSION;
717724
readonly loc?: Location;
718725
readonly name: NameNode;
726+
readonly interfaces?: ReadonlyArray<NamedTypeNode>;
719727
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
720728
readonly types?: ReadonlyArray<NamedTypeNode>;
721729
}

src/language/parser.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,14 @@ export class Parser {
970970
const description = this.parseDescription();
971971
this.expectKeyword('union');
972972
const name = this.parseName();
973+
const interfaces = this.parseImplementsInterfaces();
973974
const directives = this.parseConstDirectives();
974975
const types = this.parseUnionMemberTypes();
975976
return this.node<UnionTypeDefinitionNode>(start, {
976977
kind: Kind.UNION_TYPE_DEFINITION,
977978
description,
978979
name,
980+
interfaces,
979981
directives,
980982
types,
981983
});
@@ -1249,14 +1251,20 @@ export class Parser {
12491251
this.expectKeyword('extend');
12501252
this.expectKeyword('union');
12511253
const name = this.parseName();
1254+
const interfaces = this.parseImplementsInterfaces();
12521255
const directives = this.parseConstDirectives();
12531256
const types = this.parseUnionMemberTypes();
1254-
if (directives.length === 0 && types.length === 0) {
1257+
if (
1258+
interfaces.length === 0 &&
1259+
directives.length === 0 &&
1260+
types.length === 0
1261+
) {
12551262
throw this.unexpected();
12561263
}
12571264
return this.node<UnionTypeExtensionNode>(start, {
12581265
kind: Kind.UNION_TYPE_EXTENSION,
12591266
name,
1267+
interfaces,
12601268
directives,
12611269
types,
12621270
});

0 commit comments

Comments
 (0)