grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

GraphQL schema: fields named "type" are ignored

Open mockmotor opened this issue 3 years ago • 1 comments
trafficstars

The GraphQL schema doesn't support fields that are named "type".

A simple example is

{ type { id name }}

The parser with the default error handler reports

line 1:2 mismatched input 'type' expecting {'...', NAME}
line 1:7 extraneous input '{' expecting NAME

and the field is disappearing from the parsed tree.

It clearly happens due to the conflict with one of the type definition rules, but my knowledge of ANTLR is not enough to fix it.

mockmotor avatar Dec 09 '21 04:12 mockmotor

A band-aid fix that helped me to parse the requests coming from a vendor is below. It looks ad hoc tho :(

field: alias? (name|'type') arguments? directives? selectionSet?;

Even more blunt fix is:

name: NAME|'type';

mockmotor avatar Dec 09 '21 04:12 mockmotor