-
Notifications
You must be signed in to change notification settings - Fork 787
How to use the "client" option on the server. #1232
Comments
Just got back to this issue. What I'm finding a pain is that the graphql hoc re-uses client form the ApolloProvider context. So on server render, it's easy to pass the client + cache down to my wrapped component. The way to get around it is to create my own wrapped component and pass my second client in the context and use recompose or so to add it to the props then use that prop in the client options configuration.. This just seems way harder and more painful to do than just having it be like: // Store.js
export default graphql(gql(`...`))(Products); // uses default client
// Repositories.js
export default graphql(gql(`...`), {
options: {
client: 'github'
}
})(Repos);
// App.js
<ApolloProvider clients={{ shopify, github }} defaultClient={shopify}>
<App>
<Store />
<Repositories />
</App>
</ApolloProvider> In comments, I see this example: import MyOtherClient from "../other-client"
export default graphql(MyQuery, {
client: MyOtherClient,
})(MyComponent); which is great and clean... until you want to do this on the server side. Thoughts? /cc @jbaxleyiii @flexzuu |
I created this PR to see if this method fixes my SSR issues and it does: #1292 |
Hey I just saw your mention so sry for the late reply. At my company we don't use SSR so i have Thoughts to give. But i think the most versatile would be to set the client via props. Then you can add it via a contex hoc or whatever you desire. |
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo! |
Since there hasn't been any recent activity here, and this issue was opened for React Apollo 1.x, we'll close this for now. Please try using a 2.x version of React Apollo and post back if this is still an issue. Thanks! |
See this comment: #1232 (comment)
I noticed when using multiple clients, it's a pain on the server side to pass around client instances per request. This is managed with a single client b/c it's in the context.
A comment suggests to use it like so:
However, on the server, this is a lot harder. You'd have to have a container hoc that stores the extra clients and passes them down as a prop to the graphql wrapped component which seems kind of ugly.
What's a clean way to do this?
The text was updated successfully, but these errors were encountered: