Remove non-nullable in many types in graph-ql/coverage/company.md #372
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We're using a lot of non-null types in the Company GraphQL Schema. I don't think this is an ideal starting place.
From the GraphQL specification:
http://spec.graphql.org/June2018/#sec-Errors-and-Non-Nullability
In other words, a non-null type infects things up the tree until it finds a non-null field.
Take the following simplified example from our company schema:
Schema
Client Query
When executing this query, imagine that the
Company.CompanyLegalAddress
resolver calls an external AddressService, and that service has a failure. This is the response the client will get:Uh oh.
Company.CompanyLegalAddress.city
was marked as non-nullable, but it couldn't fetch its data. That means that the GraphQL executor is going to walk up to the next parent. ButCompany.legal_address
is also a non-null. For this query, the closest non-null isQuery.company
, so the client will not get any data it requested.If
Company.legal_address
was a nullable type, the response would have looked more like this:As we move towards a distributed architecture, and use GraphQL to stitch all those sources of data together, it's important that our schema design enables clients to gracefully handle outages of some services.
Backwards Compatibility
It's a backwards-compatible change to the schema if we want to make some fields non-nullable in the future. That does not break any guarantees to the client.
However, switching from nullable to non-null is a breaking change. Given our goals are BIC changes in GraphQL, it's safer to use nullables when in doubt.
Solution
Remove non-nullable types from the majority of
GraphQLObjectType
s in the company schema.Leave non-null fields only where they would be critical for any nested operations to succeed. Example: If we can't lookup an
ID
for a resource, we know the queries below are going to fail, so we can fail early.Further Reading
Requested Reviewers