Skip to content
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

Conversation

@benjamn
Copy link
Member

@benjamn benjamn commented Feb 26, 2019

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). This behavior may become the default, making the resolvers: {} trick unnecessary, once apollo-link-state is fully deprecated.

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).
@benjamn benjamn added this to the Release 2.5.0 milestone Feb 26, 2019
@benjamn benjamn self-assigned this Feb 26, 2019
@benjamn benjamn requested a review from hwillson Feb 26, 2019
The setResolvers method normalizes Resolvers[] arrays into a combined
(non-array) Resolvers object.
Copy link
Member

@hwillson hwillson left a comment

Love it @benjamn - thanks for working on this!

@benjamn benjamn merged commit 96fa3da into release-2.5.0 Feb 26, 2019
1 of 4 checks passed
1 of 4 checks passed
ci/circleci: Apollo Client Monorepo CircleCI is running your tests
Details
ci/circleci: Danger CircleCI is running your tests
Details
ci/circleci: Filesize CircleCI is running your tests
Details
@apollo-cla
CLA Author has signed the Meteor CLA.
Details
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.
@aryzing
Copy link

@aryzing aryzing commented Sep 19, 2019

@benjamn not sure if I'm missing something, but don't these two contradict each other?

enabling the LocalState functionality only if client resolvers were passed

and

an empty resolvers: {} map to enable the LocalState functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants