grammars-v4
grammars-v4 copied to clipboard
GraphQL schema: fields named "type" are ignored
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.
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';