-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable local state only when client resolvers provided. #4499
Merged
benjamn
merged 3 commits into
release-2.5.0
from
enable-local-state-only-if-client-resolvers-specified
Feb 26, 2019
Merged
Enable local state only when client resolvers provided. #4499
benjamn
merged 3 commits into
release-2.5.0
from
enable-local-state-only-if-client-resolvers-specified
Feb 26, 2019
Conversation
This file contains 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
If an application was previously using apollo-link-state, updating to apollo-client@2.5.0 could cause problems because @client fields are now stripped by the integrated LocalState API, and thus will not be passed into the link chain. This commit should ease the transition by enabling the LocalState functionality only if client resolvers were passed to the ApolloClient constructor, or the LocalState#setResolvers method has been called. If no client resolvers have been specified, @client fields will remain in the query passed to the link chain, so apollo-link-state can still process them, though a warning will be logged in development. If you want to use @client directives to read from or write to the cache without running resolver functions, you can pass an empty resolvers:{} map to enable the LocalState functionality (including the stripping of @client fields from queries).
The setResolvers method normalizes Resolvers[] arrays into a combined (non-array) Resolvers object.
hwillson
approved these changes
Feb 26, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it @benjamn - thanks for working on this!
Co-Authored-By: benjamn <ben@benjamn.com>
hwillson
added a commit
that referenced
this pull request
Feb 26, 2019
hwillson
added a commit
to apollographql/react-apollo
that referenced
this pull request
Feb 27, 2019
After the changes in apollographql/apollo-client#4499, when `MockedProvider` is currently used it doesn't have any `resolvers` set. This means `@client` directives are passed into the link chain. Since we don't currently allow people to modify the link chain that `MockedProvider` uses, it's safe to assume people won't want this behaviour, as they can't test things like `apollo-link-state` this way. This commit sets a default `resolvers` value of `{}` to enable AC 2.5's new local state handling, and opens the door for passing custom resolvers into the `MockedProvider` via props. Helps fix apollographql/fullstack-tutorial#73.
@benjamn not sure if I'm missing something, but don't these two contradict each other?
and
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
If an application was previously using
apollo-link-state
, updating toapollo-client@2.5.0
could cause problems because@client
fields are now stripped by the integratedLocalState
API, and thus will not be passed into the link chain.This commit should ease the transition by enabling the
LocalState
functionality only if clientresolvers
were passed to theApolloClient
constructor, or theLocalState#setResolvers
method has been called.If no client resolvers have been specified,
@client
fields will remain in the query passed to the link chain, soapollo-link-state
can still process them, though a warning will be logged in development.If you want to use
@client
directives to read from or write to the cache without running resolver functions, you can pass an emptyresolvers: {}
map to enable theLocalState
functionality (including the stripping of@client
fields from queries). This behavior may become the default, making theresolvers: {}
trick unnecessary, onceapollo-link-state
is fully deprecated.