-
-
Notifications
You must be signed in to change notification settings - Fork 453
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
Multiple clients / instances? #429
Comments
You can solve that very easily e.g. in case you are using hooks by rolling your own useQuery. It pulls in the client from context here: https://github.com/FormidableLabs/urql/blob/master/src/hooks/useQuery.ts#L36 So if you just put the client in your own (multiple) contexts and then pull in whatever instance you need for a given query, you got your solution. |
Thanks for the answer, I'll try it ASAP 😃 |
@bouiboui did you get this going? I'll have the need for this soon and would love to see an example. If not, i'll goof around and report back when I have it working. |
Actually I did not, I solved it before getting an answer by adding another GraphQL client in the mix, and since then I've been submerged by other things to work on! |
Hiya 👋 Sorry for not responding to this thread and not picking it up. For now I've gone ahead and closed the related PR. Mainly we're concerned that this will A) make not a lot of sense as a natural evolution of the hook, and B) be an irreversible API change that is not inline with React. What I mean by this is that it's something that hasn't really come up in our tested cases. GraphQL usually ties multiple APIs together and hence this doesn't really come up as we've seen. (Your mileage may vary of course) This bring me to the other point. We currently don't think this is in line with how GraphQL is often used or what corresponds to its best practices. GraphQL APIs aren't just data sources, but they're data gateways that tie data sources together. This will obviously cause conflicts if you're trying to build something from multiple GraphQL APIs and are trying to bundle them together. But in such a case it may be beneficial to either build your own GraphQL API to stitch or wrap the multiple APIs you have, or to stitch them automatically. Either can also be done on the client-side, either by writing your own exchange or using something like this Happy to reopen this if anything new comes up in this discussion! ❤️ |
I'm not sure if this is what kitten was getting at or not, but I've posted the way I solved this with an exchange here: #1523 |
In my application I have to talk to several (two) GraphQL endpoints, but I think URQL's Context is a singleton, so I can't create two Providers.
I need to use both endpoints in the same component (one to fetch external data, the other to apply mutations to another data source), so I can't isolate Providers.
How can I solve this?
Thank you!
The text was updated successfully, but these errors were encountered: