graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Interface fields syntactically incorrect for empty interfaces

Open timbonicus opened this issue 4 years ago • 1 comments

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": [],
        }
      ]
    }
  }
}

timbonicus avatar Jul 22 '20 22:07 timbonicus

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:

  1. The reason why interface Animal {} is invalid is because there cannot be an interface without fields.
  2. However interface Animal is allowed as it can be followed by something like extend Animal { field: Boolean! }.

Contributions are welcome. If you see a quick way to fix this, feel free to open a PR.

vojtapol avatar Jul 23 '20 00:07 vojtapol