React-apollo: How can we use apollo-link-state with multiple clients?

Created on 17 Jan 2019  路  3Comments  路  Source: apollographql/react-apollo

Intended outcome:

Multiple clients, for each API in use. All the clients should be able to store data in the Apollo Client cache.

const client1 = new ApolloClient({
 ...client1Props
});
const client2 = new ApolloClient({
 ...client2Props
});
const client3 = new ApolloClient({
 ...client3Props
});

Actual outcome:

I looked at the documentation of apollo-link-state, but there aren't any guidelines on how to handle multiple clients. Do i create a cache for each of the clients, or do they share one? Do i create a stateLink with withClientState for each client or do they share one?
The documentation isn't clear on this.
Any advice would be helpful.

All 3 comments

You can pass the client prop to any component. Please ask questions on StackOverflow or slack.

@rosskevin I'm trying to point out there is an issue with your docs, i.e. missing information about using apollo-link-state and the apollo cache across multiple clients.

I'm aware you can pass a client prop to components, because that's included in the docs and there are even articles about it, but that wasn't what i meant.

Feel free to not answer my questions, i can ask them elsewhere, but please update the docs to include this information. If you can provide a resource where i can learn this, i'll be happy to do a PR adding the extra info.

For the future, your issue was unclear and appears an explicit ask for advice, which should happen on stack overflow or slack. The intended outcome in your issue doesn't mention docs and the actual outcome in your question explicitly asks for advice.

Each client is separately constructed. Pass the options you like to each client, and the client you like to each component.

If you are concerned about the docs concerning the construction of apollo-client or the usage of apollo-link-state then please file the issue in the relevant repository.

Was this page helpful?
0 / 5 - 0 ratings