Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,17 @@ input Hello {
{ line: 2, column: 33 },
);
});

it('Option: allowLegacySDLEmptyFields supports type with empty fields', () => {
const body = 'type Hello { }';
expect(() => parse(body)).to.throw('Syntax Error: Expected Name, found }');
const doc = parse(body, { allowLegacySDLEmptyFields: true });
expect(doc).to.containSubset({
definitions: [
{
fields: [],
},
],
});
});
});
20 changes: 20 additions & 0 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ export type ParseOptions = {
*/
noLocation?: boolean,

/**
* If enabled, the parser will parse empty fields sets in the Schema
* Definition Language. Otherwise, the parser will follow the current
* specification.
*
* This option is provided to ease adoption of the final SDL specification
* and will be removed in a future major release.
*/
allowLegacySDLEmptyFields?: boolean,

/**
* EXPERIMENTAL:
*
Expand Down Expand Up @@ -929,6 +939,16 @@ function parseImplementsInterfaces(lexer: Lexer<*>): Array<NamedTypeNode> {
* FieldsDefinition : { FieldDefinition+ }
*/
function parseFieldsDefinition(lexer: Lexer<*>): Array<FieldDefinitionNode> {
// Legacy support for the SDL?
if (
lexer.options.allowLegacySDLEmptyFields &&
peek(lexer, TokenKind.BRACE_L) &&
lexer.lookahead().kind === TokenKind.BRACE_R
) {
lexer.advance();
lexer.advance();
return [];
}
return peek(lexer, TokenKind.BRACE_L)
? many(lexer, TokenKind.BRACE_L, parseFieldDefinition, TokenKind.BRACE_R)
: [];
Expand Down