Consider id field addition dangerous#42
Draft
sambostock wants to merge 2 commits into
Draft
Conversation
sambostock
commented
Dec 1, 2021
|
|
||
| def initialize(object_type, field) | ||
| @criticality = Changes::Criticality.non_breaking | ||
| @criticality = if field.graphql_name == 'id' |
Contributor
Author
There was a problem hiding this comment.
Perhaps it should be possible to customize this?
For instance,
- Apollo's
InMemoryCachelooks foridor_idby default - ESLint-Plugin-GraphQL's
required-fieldsrule is customizable and usesuuidin its example
Collaborator
There was a problem hiding this comment.
🤔 I think customizing this might go into "linter" territory? Especially beyond the initial id only proposal.
Anyone consuming this library is free to do whatever they want with the output of course.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
idfield.This is because many caching implementations will use the
idfield as part of a cache key, if present. For example, Apollo'sInMemoryCacheuses__typenameandid(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
idfield 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 ↩