Apollo-client: Query @client directive is reaching server

Created on 22 May 2019  ·  3Comments  ·  Source: apollographql/apollo-client


Queries with "@client" are resolved with local state only for scalar types
Intended outcome:

Resolve query with local state
Actual outcome:

Query with "@client" directive is reaching the backend and it is not possible to resolve it using the local state.
How to reproduce the issue:

https://stackblitz.com/edit/react-h5tues

Query1 is resolved locally
Query2 connects to backend and fails
Versions

apollo-cache-inmemory1.6.0
apollo-client2.6.0
apollo-link-http1.5.14
graphql14.3.0
graphql-tag2.10.1
react16.8.6
react-apollo2.5.5
react-dom16.8.6

Most helpful comment

You have to pass { resolvers: {...} } as an option to ApolloClient to enable local state, even if it's just an empty object. This was necessary for backwards compatibility with apps that were using apollo-link-state previously. I can elaborate if need be, but I'm pretty sure this is the key bit you need to make this work. Please feel free to reopen the issue if I'm wrong!

All 3 comments

You have to pass { resolvers: {...} } as an option to ApolloClient to enable local state, even if it's just an empty object. This was necessary for backwards compatibility with apps that were using apollo-link-state previously. I can elaborate if need be, but I'm pretty sure this is the key bit you need to make this work. Please feel free to reopen the issue if I'm wrong!

@benjamn is it get covered in docs anywhere?

I just stumbled over this as well. In the Angular documentation for the local state management it explicitly says that the resolver is optional, but without it it will not work as expected.

Was this page helpful?
0 / 5 - 0 ratings