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
merged 3 commits into from Feb 26, 2019

Conversation

Projects
None yet
2 participants
@benjamn
Copy link
Contributor

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.

Enable local state only when client resolvers provided.
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

Refine private LocalState resolvers field type.
The setResolvers method normalizes Resolvers[] arrays into a combined
(non-array) Resolvers object.
@hwillson
Copy link
Member

hwillson left a comment

Love it @benjamn - thanks for working on this!

Update packages/apollo-client/src/__tests__/local-state/general.ts
Co-Authored-By: benjamn <ben@benjamn.com>

@benjamn benjamn merged commit 96fa3da into release-2.5.0 Feb 26, 2019

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
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

Allow resolvers to be passed into `MockedProvider` and set a default
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.