Allow graphql resolvers to return data even when fields are missing from schema
- Dominant language
- Go
- Stars
- 10.8k
- Forks
- 1.3k
- Avg merge
- 2d 36m
- Merged PRs (30d)
- 26
Description
## Issue
Hello,
We have a use case where the client may be ahead of the server version. This often happens when the server is located in an offline or disconnected environment. As the graphql schema gets modified forward in a non-breaking way, the client starts using the new schema capabilities. When it runs into a server that has not yet been updated, it results in a `null` gqlgen response and a validation error corresponding to the `FieldsOnCorrectType` rule.
The graphql specification and related best practices are clear on non-breaking changes where the server is ahead of the client. However the spec appears silent on expected behavior in the other direction, which is our use case.
## Proposal
We propose a gqlgen configuration option `allowUnknownFields` that is disabled by default. This option would permit unknown fields to pass validation but be returned as `null` in the response object. An error could also be added to the graphql response indicating this is an unknown field, however all of the resolvers are permitted to run and return data as per usual.
## Implementation
This requires changes to `executor.go` to check which rules failed validation and to the `object.gotpl` template to return a `nil` graphql value.
We would be happy to provide a PR with these changes.
Would you be willing to accept such a contribution?
Contributor guide
Assessment
This issue has not been assessed yet.