Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/afraid-oranges-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'graphql-language-service': patch
---

Align schema-language parser bodies with the GraphQL spec.

The online parser previously required a body in several places where
the spec marks it as optional, causing valid schema documents to fail
to tokenize cleanly when a definition or extension omitted its body.
The following are now parsed correctly:

- `extend schema` with no root operation type definitions
- `type` / `extend type` with no fields body
- `interface` / `extend interface` with no fields body
- `union` / `extend union` with no member list
- `enum` / `extend enum` with no values body
- `input` / `extend input` with no fields body
39 changes: 16 additions & 23 deletions packages/graphql-language-service/src/parser/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,32 +232,23 @@ export const ParseRules: { [name: string]: ParseRule } = {
name('atom'),
opt('Implements'),
list('Directive'),
p('{'),
list('FieldDef'),
p('}'),
opt('FieldDefs'),
],
Implements: [word('implements'), list('NamedType', p('&'))],
DirectiveLocation: [name('string-2')],
// GraphQL schema language
SchemaDef: [
word('schema'),
list('Directive'),
p('{'),
list('OperationTypeDef'),
p('}'),
],

SchemaDef: [word('schema'), list('Directive'), 'OperationTypeDefs'],
OperationTypeDefs: [p('{'), list('OperationTypeDef'), p('}')],
OperationTypeDef: [name('keyword'), p(':'), name('atom')],
ScalarDef: [word('scalar'), name('atom'), list('Directive')],
ObjectTypeDef: [
word('type'),
name('atom'),
opt('Implements'),
list('Directive'),
p('{'),
list('FieldDef'),
p('}'),
opt('FieldDefs'),
],
FieldDefs: [p('{'), list('FieldDef'), p('}')],

FieldDef: [
name('property'),
Expand All @@ -280,29 +271,27 @@ export const ParseRules: { [name: string]: ParseRule } = {
word('union'),
name('atom'),
list('Directive'),
p('='),
list('UnionMember', p('|')),
opt('UnionMembers'),
],
UnionMembers: [p('='), list('UnionMember', p('|'))],

UnionMember: ['NamedType'],
EnumDef: [
word('enum'),
name('atom'),
list('Directive'),
p('{'),
list('EnumValueDef'),
p('}'),
opt('EnumValueDefs'),
],
EnumValueDefs: [p('{'), list('EnumValueDef'), p('}')],

EnumValueDef: [name('string-2'), list('Directive')],
InputDef: [
word('input'),
name('atom'),
list('Directive'),
p('{'),
list('InputValueDef'),
p('}'),
opt('InputValueDefs'),
],
InputValueDefs: [p('{'), list('InputValueDef'), p('}')],
ExtendDef: [word('extend'), 'ExtensionDefinition'],
ExtensionDefinition(token: Token): RuleKind | void {
switch (token.value) {
Expand All @@ -322,7 +311,11 @@ export const ParseRules: { [name: string]: ParseRule } = {
return Kind.INPUT_OBJECT_TYPE_EXTENSION;
}
},
[Kind.SCHEMA_EXTENSION]: ['SchemaDef'],
[Kind.SCHEMA_EXTENSION]: [
word('schema'),
list('Directive'),
opt('OperationTypeDefs'),
],
[Kind.SCALAR_TYPE_EXTENSION]: ['ScalarDef'],
[Kind.OBJECT_TYPE_EXTENSION]: ['ObjectTypeDef'],
[Kind.INTERFACE_TYPE_EXTENSION]: ['InterfaceDef'],
Expand Down
Loading
Loading