hasura / hasura/graphql-engine
Coerce absent values to null in responses to Hasura actions
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
Some REST endpoints have optional values in their response types. Unfortunately GraphQL has no concept of optional values, so my client library (Apollo) prints error messages saying that the field is missing.
Concrete example: a third-party endpoint returns the type `{ username: string, email?: string }`. I have an Action defined with the schema `type User { username: String!, email: String }`. The endpoint returns `{ "username": "carlpaten" }`, with no email. Apollo throws an error because it expects an email field, even if the value of the field is `null`.
### Describe the solution you'd like
Whenever a value is missing in an HTTP response, if the value is nullable in the GraphQL schema then it should be replaced by a `null` instead of left absent.
### Describe alternatives you've considered
The alternatives are to a) bear with it, or b) modify the endpoint, which is not always possible.
### If the feature is approved, would you be willing to submit a PR?
I'm open to the idea. I've already submitted a simple Hasura PR before, it wasn't too bad.
Contributor guide
Research direction
Start by tracing Hasura Actions and how HTTP response values are mapped against nullable GraphQL schema fields. Compare the absent email example with the desired null response, then verify that missing nullable fields are coerced while non-nullable fields retain existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100