Skip to content

Commit

Permalink
Removed parser support for legacy syntax (#2903)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jan 31, 2021
1 parent 3e2e2cc commit 0d2bd54
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 96 deletions.
25 changes: 0 additions & 25 deletions src/language/__tests__/schema-parser-test.js
Expand Up @@ -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 }),
]);
});
});
20 changes: 0 additions & 20 deletions src/language/parser.d.ts
Expand Up @@ -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:
*
Expand Down
51 changes: 3 additions & 48 deletions src/language/parser.js
Expand Up @@ -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:
*
Expand Down Expand Up @@ -855,40 +835,15 @@ export class Parser {
* - ImplementsInterfaces & NamedType
*/
parseImplementsInterfaces(): Array<NamedTypeNode> {
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<FieldDefinitionNode> {
// 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,
Expand Down
3 changes: 0 additions & 3 deletions src/utilities/buildASTSchema.js
Expand Up @@ -98,9 +98,6 @@ export function buildSchema(
): GraphQLSchema {
const document = parse(source, {
noLocation: options?.noLocation,
allowLegacySDLEmptyFields: options?.allowLegacySDLEmptyFields,
allowLegacySDLImplementsInterfaces:
options?.allowLegacySDLImplementsInterfaces,
experimentalFragmentVariables: options?.experimentalFragmentVariables,
});

Expand Down

0 comments on commit 0d2bd54

Please sign in to comment.