Skip to content

Commit

Permalink
Fix parser and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Sep 30, 2024
1 parent 36afde3 commit 6938c31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
16 changes: 7 additions & 9 deletions packages/graphql-language-service/src/parser/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,8 @@ export const ParseRules: { [name: string]: ParseRule } = {
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: [
Expand Down Expand Up @@ -322,7 +316,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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('onlineParser', () => {
`);

t.keyword('schema', { kind: 'SchemaDef' });
t.punctuation('{');
t.punctuation('{', { kind: 'OperationTypeDefs' });

t.keyword('query', { kind: 'OperationTypeDef' });
t.punctuation(':');
Expand All @@ -73,7 +73,7 @@ describe('onlineParser', () => {
`);

t.keyword('extend', { kind: 'ExtendDef' });
t.keyword('schema', { kind: 'SchemaDef' });
t.keyword('schema', { kind: 'SchemaExtension' });

t.eol();
});
Expand All @@ -86,8 +86,8 @@ describe('onlineParser', () => {
`);

t.keyword('extend', { kind: 'ExtendDef' });
t.keyword('schema', { kind: 'SchemaDef' });
t.punctuation('{');
t.keyword('schema', { kind: 'SchemaExtension' });
t.punctuation('{', { kind: 'OperationTypeDefs' });

t.keyword('query', { kind: 'OperationTypeDef' });
t.punctuation(':');
Expand All @@ -104,7 +104,7 @@ describe('onlineParser', () => {
`);

t.keyword('extend', { kind: 'ExtendDef' });
t.keyword('schema', { kind: 'SchemaDef' });
t.keyword('schema', { kind: 'SchemaExtension' });
expectDirective({ t }, { name: 'someDirective' });

t.eol();
Expand All @@ -118,7 +118,7 @@ describe('onlineParser', () => {
`);

t.keyword('extend', { kind: 'ExtendDef' });
t.keyword('schema', { kind: 'SchemaDef' });
t.keyword('schema', { kind: 'SchemaExtension' });
expectDirective({ t }, { name: 'someDirective' });

t.keyword('type', { kind: 'ObjectTypeDef' });
Expand All @@ -127,7 +127,7 @@ describe('onlineParser', () => {
t.property('field', { kind: 'FieldDef' });
t.punctuation(':');
t.name('String', { kind: 'NamedType' });
t.punctuation('}');
t.punctuation('}', { kind: 'Document' });

t.eol();
});
Expand Down

0 comments on commit 6938c31

Please sign in to comment.