99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.97k stars 1.17k forks source link

Introspection "field" results don't follow GraphQL spec #1867

Open zoevkay opened 2 years ago

zoevkay commented 2 years ago

What happened?

When running an introspection query against a GraphQL schema implemented with gqlgen, I receive the following (snippet of the full response):

...
{
    "description": "An enum that represents the various recipe statuses.",
    "enumValues": [
      ...
    ],
    "fields": [],
    "inputFields": [],
    "interfaces": [],
    "kind": "ENUM",
    "name": "RecipeStatusType",
    "possibleTypes": []
  },
{
    "kind": "SCALAR",
    "name": "SemVer",
    "description": "A version designation conforming to the SemVer specification.",
    "fields": [],
    "inputFields": [],
    "interfaces": [],
    "enumValues": [],
    "possibleTypes": []
}

What did you expect?

Per the GraphQL spec, I expect "fields" to be null for all types except OBJECT and iNTERFACE, from this documentation:

# must be non-null for OBJECT and INTERFACE, otherwise null.
  fields(includeDeprecated: Boolean = false): [__Field!]

Ie, I'd expect any OBJECT or INTERFACE to have "fields": [] but other types to return "fields": null. The spec behavior is what I've seen with other GraphQL APIs.

Minimal graphql.schema and models to reproduce

schema {
  query: Query
}

type Query {
  cliVersion: SemVer
  status: RecipeStatusType
}

enum RecipeStatusType {
  AVAILABLE
  CANCELED
}

scalar SemVer

versions

Thanks for your time!

frederikhors commented 2 years ago

Can you try with the latest 0.16.0 version?

zoevkay commented 2 years ago

Hi @frederikhors , thanks for your patience. A colleague ran 0.16.0 and received the same results as 0.13.0. An example snippet:

        {
          "kind": "SCALAR",
          "name": "EpochMilliseconds",
          "description": "",
          "fields": [],
          "inputFields": [],
          "interfaces": [],
          "enumValues": [],
          "possibleTypes": []
        },