Skip to content

Commit c70ea78

Browse files
authored
Update to June 2018 schema
Update the grammar to June 2018 schema
1 parent 8aae72b commit c70ea78

File tree

1 file changed

+81
-60
lines changed

1 file changed

+81
-60
lines changed

graphql/GraphQL.g4

+81-60
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
/*
22
The MIT License (MIT)
3-
3+
44
Copyright (c) 2015 Joseph T. McBride
5-
5+
66
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
77
associated documentation files (the "Software"), to deal in the Software without restriction,
88
including without limitation the rights to use, copy, modify, merge, publish, distribute,
99
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
11-
11+
1212
The above copyright notice and this permission notice shall be included in all copies or
1313
substantial portions of the Software.
14-
14+
1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
1616
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1717
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1818
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
1919
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20-
20+
2121
GraphQL grammar derived from:
22-
22+
2323
GraphQL Draft Specification - July 2015
24-
25-
http://facebook.github.io/graphql/ https://github.com/facebook/graphql
26-
24+
25+
http://facebook.github.io/graphql/ https://github.com/facebook/graphql
26+
2727
AB:10-sep19: replaced type with type_ to resolve conflict for golang generator
28-
28+
2929
AB: 13-oct-19: added type system as per June 2018 specs
3030
AB: 26-oct-19: added ID type
3131
AB: 30-Oct-19: description, boolean, schema & Block string fix.
@@ -34,7 +34,7 @@
3434
*/
3535
grammar GraphQL;
3636

37-
document: description* definition+;
37+
document: definition+;
3838

3939
definition:
4040
execDefinition
@@ -50,12 +50,8 @@ typeSystemDefinition:
5050

5151
// https://graphql.github.io/graphql-spec/June2018/#sec-Schema
5252
schemaDefinition:
53-
'schema' directives? rootOperationTypeDefinitionList;
53+
'schema' directives? '{' rootOperationTypeDefinition+ '}';
5454

55-
rootOperationTypeDefinitionList:
56-
'{' rootOperationTypeDefinition (
57-
','? rootOperationTypeDefinition
58-
)* '}';
5955
rootOperationTypeDefinition: operationType ':' namedType;
6056
namedType: NAME;
6157

@@ -68,38 +64,39 @@ typeDefinition:
6864
| enumTypeDefinition
6965
| inputObjectTypeDefinition;
7066

71-
scalarTypeDefinition: description? 'scalar' NAME directives;
67+
scalarTypeDefinition: description? 'scalar' NAME directives?;
7268
description: String_;
7369

7470
// https://graphql.github.io/graphql-spec/June2018/#sec-Objects
75-
objectTypeDefinition
76-
: description? 'type' NAME
77-
implementsInterfaces?
78-
directives?
79-
fieldsDefinitions?;
80-
81-
implementsInterfaces: 'implements' '&'? type_ |
82-
implementsInterfaces '&' type_;
71+
objectTypeDefinition : description?
72+
'type' NAME
73+
implementsInterfaces?
74+
directives?
75+
fieldsDefinition?;
76+
77+
implementsInterfaces: 'implements' '&'? namedType
78+
| implementsInterfaces '&' namedType
79+
;
8380

8481

85-
fieldsDefinitions: '{' fieldsDefinition+'}';
86-
fieldsDefinition: description? NAME argumentsDefinition? ':' type_ directives? ;
87-
argumentsDefinition: '(' inputValueDefinition (',' inputValueDefinition)* ')';
82+
fieldsDefinition: '{' fieldDefinition+ '}';
83+
fieldDefinition: description? NAME argumentsDefinition? ':' type_ directives? ;
84+
argumentsDefinition: '(' inputValueDefinition+ ')';
8885
inputValueDefinition: description? NAME ':' type_ defaultValue? directives?;
8986

9087
//https://graphql.github.io/graphql-spec/June2018/#sec-Interfaces
9188
interfaceTypeDefinition
92-
: description? 'interface' NAME directives? fieldsDefinitions?;
89+
: description? 'interface' NAME directives? fieldsDefinition?;
9390

9491
// https://graphql.github.io/graphql-spec/June2018/#sec-Unions
9592
unionTypeDefinition: description? 'union' NAME directives? unionMemberTypes?;
96-
unionMemberTypes: '=' type_ ('|' type_)* ;
93+
unionMemberTypes: '=' '|'? type_ ('|' type_)* ;
9794

9895
unionTypeExtension : 'extend' unionTypeDefinition;
9996

100-
enumTypeDefinition: description? 'enum' NAME directives? enumValuesDefinitions?;
101-
enumValuesDefinitions: '{' ( description? enumElementValue directives?)+ '}';
102-
enumElementValue: NAME ;// not (nullValue | booleanValue)
97+
enumTypeDefinition: description? 'enum' NAME directives? enumValuesDefinition?;
98+
enumValuesDefinition: '{' ( description? enumValue directives?)+ '}';
99+
enumValue: NAME; //{ not (nullValue | booleanValue) };
103100

104101
enumTypeExtension: 'extend' enumTypeDefinition;
105102

@@ -112,7 +109,7 @@ directiveDefinition: description? 'directive' '@' NAME argumentsDefinition? 'on'
112109
directiveLocations: directiveLocation ('|' directiveLocations)*;
113110
directiveLocation: executableDirectiveLocation | typeSystemDirectiveLocation;
114111

115-
executableDirectiveLocation:
112+
executableDirectiveLocation:
116113
'QUERY' |
117114
'MUTATION' |
118115
'SUBSCRIPTION' |
@@ -140,29 +137,29 @@ typeSystemExtension: schemaExtension | typeExtension;
140137
schemaExtension: 'extend' schemaDefinition ;
141138
typeExtension: 'extend' typeDefinition;
142139

143-
// original code: execution definitions
140+
// original code: execution definitions
144141
// GraphQL Draft Specification - July 2015
145142
execDefinition: operationDefinition | fragmentDefinition;
146143

147144
operationDefinition:
148145
selectionSet
149-
| operationType NAME variableDefinitions? directives? selectionSet;
146+
| operationType NAME? variableDefinitions? directives? selectionSet;
150147

151-
selectionSet: '{' selection ( ','? selection)* '}';
148+
selectionSet: '{' selection+ '}';
152149

153150
operationType: 'query' | 'mutation' | 'subscription';
154151

155152
selection: field | fragmentSpread | inlineFragment;
156153

157-
field: fieldName arguments? directives? selectionSet?;
154+
field: alias? fieldName arguments? directives? selectionSet?;
158155

159-
fieldName: alias | NAME;
156+
fieldName: NAME;
160157

161-
alias: NAME ':' NAME;
158+
alias: NAME ':';
162159

163-
arguments: '(' argument ( ',' argument)* ')';
160+
arguments: '(' argument+ ')';
164161

165-
argument: NAME ':' valueOrVariable;
162+
argument: NAME ':' value;
166163

167164
fragmentSpread: '...' fragmentName directives?;
168165

@@ -177,47 +174,51 @@ fragmentName: NAME;
177174
directives: directive+;
178175

179176
directive:
180-
'@' NAME ':' valueOrVariable
181-
| '@' NAME
182-
| '@' NAME '(' argument ')';
177+
'@' NAME arguments?;
183178

184179
typeCondition: typeName;
185180

186-
variableDefinitions:
187-
'(' variableDefinition (',' variableDefinition)* ')';
181+
variableDefinitions: '(' variableDefinition+ ')';
188182

189183
variableDefinition: variable ':' type_ defaultValue?;
190184

191185
variable: '$' NAME;
192186

193187
defaultValue: '=' value;
194188

195-
valueOrVariable: value | variable;
196-
197189
value:
198-
String_ # stringValue
199-
| NAME # enumValue
200-
| NUMBER # numberValue
190+
variable # variableValue
191+
| NUMBER # numberValue
192+
| String_ # stringValue
201193
| BooleanLiteral # booleanValue
202-
| array # arrayValue
203-
| ID # idValue //The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable.
204-
| 'null' # nullValue
194+
| 'null' # nullValue
195+
| enumValue # constValue
196+
| array # arrayValue
197+
| object # objectValue
205198
;
206199

200+
object: '{' '}'
201+
| '{' objectField '}'
202+
;
203+
204+
objectField: NAME ':' value;
205+
207206
BooleanLiteral
208207
: 'true'
209208
| 'false'
210209
;
211210

212-
type_: typeName nonNullType? | listType nonNullType?;
211+
type_: typeName nonNull? | listType nonNull?;
213212

214213
typeName: NAME;
215214

216215
listType: '[' type_ ']';
217216

218-
nonNullType: '!';
217+
nonNull: '!';
219218

220-
array: '[' value ( ',' value)* ']' | '[' ']';
219+
array: '[' value+ ']'
220+
| '[' ']'
221+
;
221222

222223
NAME: [_A-Za-z] [_0-9A-Za-z]*;
223224

@@ -231,14 +232,24 @@ BLOCK_STRING
231232
232233
ID: STRING;
233234
234-
235235
fragment ESC: '\\' ( ["\\/bfnrt] | UNICODE);
236236
237237
fragment UNICODE: 'u' HEX HEX HEX HEX;
238238
239239
fragment HEX: [0-9a-fA-F];
240240
241241
NUMBER: '-'? INT '.' [0-9]+ EXP? | '-'? INT EXP | '-'? INT;
242+
PUNCTUATOR: '!'
243+
| '$'
244+
| '(' | ')'
245+
| '...'
246+
| ':'
247+
| '='
248+
| '@'
249+
| '[' | ']'
250+
| '{' | '}'
251+
| '|'
252+
;
242253
243254
fragment INT: '0' | [1-9] [0-9]*;
244255
@@ -249,8 +260,18 @@ fragment EXP: [Ee] [+\-]? INT;
249260
// \- since - means "range" inside [...]
250261
251262
WS: [ \t\n\r]+ -> skip;
252-
263+
COMMA: ',' -> skip;
253264
LineComment
254265
: '#' ~[\r\n]*
255266
-> skip
256267
;
268+
269+
UNICODE_BOM: (UTF8_BOM
270+
| UTF16_BOM
271+
| UTF32_BOM
272+
) -> skip
273+
;
274+
275+
UTF8_BOM: '\uEFBBBF';
276+
UTF16_BOM: '\uFEFF';
277+
UTF32_BOM: '\u0000FEFF';

0 commit comments

Comments
 (0)