graphql-java-tools
graphql-java-tools copied to clipboard
Interface fields syntactically incorrect for empty interfaces
I'm on a bit of a wild goose chase. I filed a bug with codegen-graphql about a crash which instead seems to be the fault of graphql-java-tools.
The problem comes from declaring an interface with no fields:
interface Product {}
interface Product
The first declaration is invalid according to graphql-spec, which shows FieldsDefinition
as optional but requires at least one field with a name
if a list is declared. The second is syntactically valid, since the optional FieldsDefinition
is not provided (see codegen-graphql ticket for an in-depth examination of the spec).
Both formats are accepted by SchemaParser
, but both create a schema introspection of the interface with fields: []
instead of fields: null
, which causes the original codegen-graphql crash as invalid syntax.
{
__schema {
types {
name
kind
fields {
name
}
}
}
}
{
"data": {
"__schema": {
"types": [
{
"name": "Product",
"kind": "INTERFACE",
"fields": [],
}
]
}
}
}
What a coincidence! I ran into this myself just a few days ago. Thank you for the report and the explanation provided.
Just to save others some clicks:
- The reason why
interface Animal {}
is invalid is because there cannot be an interface without fields. - However
interface Animal
is allowed as it can be followed by something likeextend Animal { field: Boolean! }
.
Contributions are welcome. If you see a quick way to fix this, feel free to open a PR.