question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to deal with multiple environments ?

See original GitHub issue

Hello,

We currently encounter a specific case where we have to deal with multiple graphql apis. We have a graphql api developed by another team and we develop our own graphql api which returns mock data. This second api allows us to do a lot of tests and to develop new features even if the real graphql api is not ready yet.

We would like to use different environments in function of the query. Some queries can already be done on the real api, but some other exist only on the mock api.

The issue is that all the methods (useQuery, useRefetch, etc.) take the environment from the context provider, and we have no solution to override that for one useQuery for example.

Is there a solution to deal with multiple environments ? The only solution I see for now is an evolution in the methods useQuery etc. to add an extra optional parameter customEnvironment and in the method : const environment = customEnvironment || useRelayEnvironment();.

What do you think ?

Thank you !

Edit : Issue solved with the use of networkCacheConfig.metadata object to change dynamically the url in the fetchQuery method (https://github.com/relay-tools/relay-hooks/issues/59#issuecomment-595809130)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
morryscommented, Mar 6, 2020

Hi @davidgarry, for your use case it seems sufficient to use a single environment and correctly use useQuery and the networkCacheConfig (specifically the metadata field) and manage your case at the network level.

However your request seems very similar to the solutions adopted in Apollo: https://medium.com/open-graphql/apollo-multiple-clients-with-react-b34b571210a5

3reactions
davidgarrycommented, Mar 6, 2020

@morrys , thank you a lot for your help. It works perfectly with the cacheConfig.metadata object ! I’m able to change the url to use dynamically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Manage Multiple Environments with DevOps
Handle data across environments. Keeping parity across all of the environments is important for them to remain useful. The main area that you ......
Read more >
How to Manage Multiple Environments with DevOps - Medium
Handle data across environments ... Keeping parity across all of the environments is important for them to remain useful. The main area that...
Read more >
Using Multiple Environments to Improve Your Development ...
Maintaining multiple environments provides better security: To protect the integrity of your production data, you should limit access to it.
Read more >
How do companies manage multiple environments (dev, test ...
Try and create a test or development environment. · Create small proof of Concepts in those environments and test the feasibility of hosting...
Read more >
How to manage multiple environments with Terraform using ...
Setting up environments using workspaces; Switching between environments; Using different configurations in each environment; Using different ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found