-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Avoid parse ambiguity on types & extensions #598
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leebyron I think it's the best solution that possible without breaking changes.
P.S. In retrospective, legacy SDL syntax that always requires curly braces (even if empty) offered a better solution to this problem:
https://github.com/graphql/graphql-js/blob/670bbaca5ed897d0ee2caadbc8ac3a0bbf281b87/src/language/parser.js#L73-L81
acf624b
to
3bc2b08
Compare
Yeah, I agree. I believe I made a mistake with that change for type definitions. |
Updated this change to use a single token lookahead since that's more accurate to how we expect parser implementations to implement this restriction, and it reinforces the idea that parsing should be linear time. Also includes both type extensions and type definitions, and updates the grammar appendix |
3bc2b08
to
c9c5973
Compare
Partial fix to #564, adds lookahead constraints to type system extensions to remove ambiguity or inefficiency from the grammar. The GraphQL grammar should be parsed in linear type with at most one lookahead. Since extensions have an optional `{ }` body, finding the token `{` should always attempt to parse the relevant portion of the type extension rather than completing the type extension and attempting to parse the query shorthand SelectionSet.
c9c5973
to
a91fdd5
Compare
Here's a parser test case: interface Foo
{ alpha: beta } Before this change, this could be interpreted either as:
After this change, option 2. is the only legal result. 1. is not possible since the incompletely defined interface must not be followed by |
Partial fix to #564, adds lookahead constraints to type system extensions to remove ambiguity or inefficiency from the grammar.
The GraphQL grammar should be parsed in linear type with at most one lookahead. Since extensions have an optional
{ }
body, finding the token{
should always attempt to parse the relevant portion of the type extension rather than completing the type extension and attempting to parse the query shorthand SelectionSet.