Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed parser support for legacy syntax #2903

Merged
merged 1 commit into from Jan 31, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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