@@ -39,13 +39,14 @@ import type {
39
39
Type ,
40
40
NamedType ,
41
41
42
- TypeDefinition ,
42
+ TypeSystemDefinition ,
43
+
44
+ ScalarTypeDefinition ,
43
45
ObjectTypeDefinition ,
44
46
FieldDefinition ,
45
47
InputValueDefinition ,
46
48
InterfaceTypeDefinition ,
47
49
UnionTypeDefinition ,
48
- ScalarTypeDefinition ,
49
50
EnumTypeDefinition ,
50
51
EnumValueDefinition ,
51
52
InputObjectTypeDefinition ,
@@ -85,12 +86,12 @@ import {
85
86
LIST_TYPE ,
86
87
NON_NULL_TYPE ,
87
88
89
+ SCALAR_TYPE_DEFINITION ,
88
90
OBJECT_TYPE_DEFINITION ,
89
91
FIELD_DEFINITION ,
90
92
INPUT_VALUE_DEFINITION ,
91
93
INTERFACE_TYPE_DEFINITION ,
92
94
UNION_TYPE_DEFINITION ,
93
- SCALAR_TYPE_DEFINITION ,
94
95
ENUM_TYPE_DEFINITION ,
95
96
ENUM_VALUE_DEFINITION ,
96
97
INPUT_OBJECT_TYPE_DEFINITION ,
@@ -185,8 +186,7 @@ function parseDocument(parser: Parser): Document {
185
186
* Definition :
186
187
* - OperationDefinition
187
188
* - FragmentDefinition
188
- * - TypeDefinition
189
- * - TypeExtensionDefinition
189
+ * - TypeSystemDefinition
190
190
*/
191
191
function parseDefinition ( parser : Parser ) : Definition {
192
192
if ( peek ( parser , TokenKind . BRACE_L ) ) {
@@ -202,14 +202,15 @@ function parseDefinition(parser: Parser): Definition {
202
202
203
203
case 'fragment' : return parseFragmentDefinition ( parser ) ;
204
204
205
+ // Note: the Type System IDL is an experimental non-spec addition.
206
+ case 'scalar' :
205
207
case 'type' :
206
208
case 'interface' :
207
209
case 'union' :
208
- case 'scalar' :
209
210
case 'enum' :
210
- case 'input' : return parseTypeDefinition ( parser ) ;
211
- case 'extend' : return parseTypeExtensionDefinition ( parser ) ;
212
- case 'directive' : return parseDirectiveDefinition ( parser ) ;
211
+ case 'input' :
212
+ case 'extend' :
213
+ case 'directive' : return parseTypeSystemDefinition ( parser ) ;
213
214
}
214
215
}
215
216
@@ -649,34 +650,48 @@ export function parseNamedType(parser: Parser): NamedType {
649
650
// Implements the parsing rules in the Type Definition section.
650
651
651
652
/**
653
+ * TypeSystemDefinition :
654
+ * - TypeDefinition
655
+ * - TypeExtensionDefinition
656
+ * - DirectiveDefinition
657
+ *
652
658
* TypeDefinition :
659
+ * - ScalarTypeDefinition
653
660
* - ObjectTypeDefinition
654
661
* - InterfaceTypeDefinition
655
662
* - UnionTypeDefinition
656
- * - ScalarTypeDefinition
657
663
* - EnumTypeDefinition
658
664
* - InputObjectTypeDefinition
659
665
*/
660
- function parseTypeDefinition ( parser : Parser ) : TypeDefinition {
661
- if ( ! peek ( parser , TokenKind . NAME ) ) {
662
- throw unexpected ( parser ) ;
663
- }
664
- switch ( parser . token . value ) {
665
- case 'type' :
666
- return parseObjectTypeDefinition ( parser ) ;
667
- case 'interface' :
668
- return parseInterfaceTypeDefinition ( parser ) ;
669
- case 'union' :
670
- return parseUnionTypeDefinition ( parser ) ;
671
- case 'scalar' :
672
- return parseScalarTypeDefinition ( parser ) ;
673
- case 'enum' :
674
- return parseEnumTypeDefinition ( parser ) ;
675
- case 'input' :
676
- return parseInputObjectTypeDefinition ( parser ) ;
677
- default :
678
- throw unexpected ( parser ) ;
666
+ function parseTypeSystemDefinition ( parser : Parser ) : TypeSystemDefinition {
667
+ if ( peek ( parser , TokenKind . NAME ) ) {
668
+ switch ( parser . token . value ) {
669
+ case 'scalar' : return parseScalarTypeDefinition ( parser ) ;
670
+ case 'type' : return parseObjectTypeDefinition ( parser ) ;
671
+ case 'interface' : return parseInterfaceTypeDefinition ( parser ) ;
672
+ case 'union' : return parseUnionTypeDefinition ( parser ) ;
673
+ case 'enum' : return parseEnumTypeDefinition ( parser ) ;
674
+ case 'input' : return parseInputObjectTypeDefinition ( parser ) ;
675
+ case 'extend' : return parseTypeExtensionDefinition ( parser ) ;
676
+ case 'directive' : return parseDirectiveDefinition ( parser ) ;
677
+ }
679
678
}
679
+
680
+ throw unexpected ( parser ) ;
681
+ }
682
+
683
+ /**
684
+ * ScalarTypeDefinition : scalar Name
685
+ */
686
+ function parseScalarTypeDefinition ( parser : Parser ) : ScalarTypeDefinition {
687
+ const start = parser . token . start ;
688
+ expectKeyword ( parser , 'scalar' ) ;
689
+ const name = parseName ( parser ) ;
690
+ return {
691
+ kind : SCALAR_TYPE_DEFINITION ,
692
+ name,
693
+ loc : loc ( parser , start ) ,
694
+ } ;
680
695
}
681
696
682
697
/**
@@ -816,20 +831,6 @@ function parseUnionMembers(parser: Parser): Array<NamedType> {
816
831
return members ;
817
832
}
818
833
819
- /**
820
- * ScalarTypeDefinition : scalar Name
821
- */
822
- function parseScalarTypeDefinition ( parser : Parser ) : ScalarTypeDefinition {
823
- const start = parser . token . start ;
824
- expectKeyword ( parser , 'scalar' ) ;
825
- const name = parseName ( parser ) ;
826
- return {
827
- kind : SCALAR_TYPE_DEFINITION ,
828
- name,
829
- loc : loc ( parser , start ) ,
830
- } ;
831
- }
832
-
833
834
/**
834
835
* EnumTypeDefinition : enum Name { EnumValueDefinition+ }
835
836
*/
0 commit comments