Skip to content

Issues with introspection query when no Query type is in schema #952

Open
@mattjohnsonpint

Description

@mattjohnsonpint

Consider a schema that contains only mutations:

type Mutation {
  doSomething: Boolean
}

In such cases, it appears that an empty root Query object is being added to the results of the introspection queries:

{
  "data": {
    "__schema": {
      "queryType": { "name": "Query" },
      "mutationType": { "name": "Mutation" },
      "subscriptionType": null,
      "types": [
        {
          "kind": "OBJECT",
          "name": "Query",
          "description": "",
          "fields": null,
          "inputFields": [],
          "interfaces": [],
          "enumValues": null,
          "possibleTypes": []
        },
...

This is good, because (as I learned), the GraphQL spec requires a Query type but you can't define an empty type Query or type Query {} because all object types must have at least one field. Short of adding a fake field that would clutter the schema, having the introspection query tack on a Query object is a good idea!

HOWEVER, I'm getting an error in Postman:
image

This seems to be caused by "fields": null. As a workaround, I modified our code to patch that to be "fields": [] and the error goes away. (see hypermodeinc/modus#558)

I dug through the GraphQL Go Tools sources, but I really can't seem to find where the Query type is being added. Any ideas? Happy to send a PR if you can point me in the right direction. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions