Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mattjohnsonpint opened this issue Nov 6, 2024 · 1 comment
Open
Labels
internally-reviewed Internally reviewed

Comments

@mattjohnsonpint
Copy link
Contributor

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.

@devsergiy
Copy link
Member

Hi @mattjohnsonpint

Basically, in our case, we anyway will add a Query type with introspection service fields

But right now our introspection generator skips such fields

They could be added and the query would never be empty

@devsergiy devsergiy added the internally-reviewed Internally reviewed label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internally-reviewed Internally reviewed
Projects
None yet
Development

No branches or pull requests

2 participants