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

Fix __type queries sometimes not returning data #540

Merged
merged 3 commits into from
Dec 16, 2022

Conversation

simhnna
Copy link
Contributor

@simhnna simhnna commented Dec 12, 2022

If the queried type was not defined it would return an empty data section instead of __type: null

Fixes #539

If the queried type was not defined it would return an empty data
section instead of `__type: null`

Fixes graph-gophers#539
@pavelnikolov
Copy link
Member

@simhnna thank you for opening the issue and contributing with a PR. Does the response in the current version of the library actually violate the GraphQL Spec?

@simhnna
Copy link
Contributor Author

simhnna commented Dec 13, 2022

https://spec.graphql.org/October2021/#sec-Schema-Introspection
Defines __type(name: String!): __Type
So the return type is nullable.

And https://spec.graphql.org/October2021/#sec-Executing-Fields
states that

Each field requested in the grouped field set that is defined on the selected objectType will result in an entry in the response map.

So yes I would say the current implementation violates the spec. I know that Apollo server returns a field with null value for such queries. If you want I can double check the JavaScript reference implementation tomorrow on my work PC, but I'm pretty certain it also returns a field with a null if asked for an unknown type.

@pavelnikolov pavelnikolov merged commit e892575 into graph-gophers:master Dec 16, 2022
@simhnna simhnna deleted the fix-type-query branch January 18, 2023 07:47
KNiepok pushed a commit to spacelift-io/graphql-go that referenced this pull request Feb 28, 2023
* Fix __type queries sometimes not returning data

If the queried type was not defined it would return an empty data
section instead of `__type: null`

Fixes graph-gophers#539
KNiepok pushed a commit to spacelift-io/graphql-go that referenced this pull request Feb 28, 2023
* Fix __type queries sometimes not returning data

If the queried type was not defined it would return an empty data
section instead of `__type: null`

Fixes graph-gophers#539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

__type(name:"") queries don't return data if the named type is unknown
2 participants