Consider id
field addition dangerous
#42
Draft
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.
While most of the time adding a field is a safe non-breaking change, there are certain fields that can be dangerous to add, namely the
id
field.This is because many caching implementations will use the
id
field as part of a cache key, if present. For example, Apollo'sInMemoryCache
uses__typename
andid
(or_id
) to generate a cache key.1In fact, an ESLint-Plugin-GraphQL rule exists to enforce the querying of so called "required fields"2 (such as
id
), to ensure caching is done properly.As such, adding an
id
field to an existing type can change the client side caching behaviour if the client hasn't defined a custom caching strategy (e.g. start caching resources that were previously not cached).Footnotes
https://www.apollographql.com/docs/react/v2/caching/cache-configuration/#default-identifiers ↩
https://github.com/apollographql/eslint-plugin-graphql#required-fields-validation-rule ↩