From 0d2bd5499bf05921a8dcbfdfc40089a7992e53a4 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 31 Jan 2021 14:40:29 +0200 Subject: [PATCH] Removed parser support for legacy syntax (#2903) --- src/language/__tests__/schema-parser-test.js | 25 ---------- src/language/parser.d.ts | 20 -------- src/language/parser.js | 51 ++------------------ src/utilities/buildASTSchema.js | 3 -- 4 files changed, 3 insertions(+), 96 deletions(-) diff --git a/src/language/__tests__/schema-parser-test.js b/src/language/__tests__/schema-parser-test.js index 02dab56622..2e6ffbd745 100644 --- a/src/language/__tests__/schema-parser-test.js +++ b/src/language/__tests__/schema-parser-test.js @@ -1106,29 +1106,4 @@ input Hello { it('parses kitchen sink schema', () => { expect(() => parse(kitchenSinkSDL)).to.not.throw(); }); - - it('Option: allowLegacySDLEmptyFields supports type with empty fields', () => { - const body = 'type Hello { }'; - expectSyntaxError(body).to.include({ - message: 'Syntax Error: Expected Name, found "}".', - }); - - const doc = parse(body, { allowLegacySDLEmptyFields: true }); - expect(doc).to.have.deep.nested.property('definitions[0].fields', []); - }); - - it('Option: allowLegacySDLImplementsInterfaces', () => { - const body = 'type Hello implements Wo rld { field: String }'; - expectSyntaxError(body).to.include({ - message: 'Syntax Error: Unexpected Name "rld".', - }); - - const doc = parse(body, { allowLegacySDLImplementsInterfaces: true }); - expect( - toJSONDeep(doc), - ).to.have.deep.nested.property('definitions[0].interfaces', [ - typeNode('Wo', { start: 22, end: 24 }), - typeNode('rld', { start: 25, end: 28 }), - ]); - }); }); diff --git a/src/language/parser.d.ts b/src/language/parser.d.ts index 368c6f8a73..80686cb537 100644 --- a/src/language/parser.d.ts +++ b/src/language/parser.d.ts @@ -12,26 +12,6 @@ export interface 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 v16. - */ - allowLegacySDLEmptyFields?: boolean; - - /** - * If enabled, the parser will parse implemented interfaces with no `&` - * character between each interface. 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 v16. - */ - allowLegacySDLImplementsInterfaces?: boolean; - /** * EXPERIMENTAL: * diff --git a/src/language/parser.js b/src/language/parser.js index 5d7b16186d..2f1ff29828 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -66,26 +66,6 @@ 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 v16. - */ - allowLegacySDLEmptyFields?: boolean, - - /** - * If enabled, the parser will parse implemented interfaces with no `&` - * character between each interface. 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 v16. - */ - allowLegacySDLImplementsInterfaces?: boolean, - /** * EXPERIMENTAL: * @@ -855,40 +835,15 @@ export class Parser { * - ImplementsInterfaces & NamedType */ parseImplementsInterfaces(): Array { - if (!this.expectOptionalKeyword('implements')) { - return []; - } - - if (this._options?.allowLegacySDLImplementsInterfaces === true) { - const types = []; - // Optional leading ampersand - this.expectOptionalToken(TokenKind.AMP); - do { - types.push(this.parseNamedType()); - } while ( - this.expectOptionalToken(TokenKind.AMP) || - this.peek(TokenKind.NAME) - ); - return types; - } - - return this.delimitedMany(TokenKind.AMP, this.parseNamedType); + return this.expectOptionalKeyword('implements') + ? this.delimitedMany(TokenKind.AMP, this.parseNamedType) + : []; } /** * FieldsDefinition : { FieldDefinition+ } */ parseFieldsDefinition(): Array { - // Legacy support for the SDL? - if ( - this._options?.allowLegacySDLEmptyFields === true && - this.peek(TokenKind.BRACE_L) && - this._lexer.lookahead().kind === TokenKind.BRACE_R - ) { - this._lexer.advance(); - this._lexer.advance(); - return []; - } return this.optionalMany( TokenKind.BRACE_L, this.parseFieldDefinition, diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index d0c78340e8..7f72cb6114 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -98,9 +98,6 @@ export function buildSchema( ): GraphQLSchema { const document = parse(source, { noLocation: options?.noLocation, - allowLegacySDLEmptyFields: options?.allowLegacySDLEmptyFields, - allowLegacySDLImplementsInterfaces: - options?.allowLegacySDLImplementsInterfaces, experimentalFragmentVariables: options?.experimentalFragmentVariables, });