Update / set dynamic uri
See original GitHub issueI’ve got things working with a hardcoded url endpoint, but I can’t figure out how to set the uri after bootstrapping. I tried
const networkInterface = createNetworkInterface({
// TODO - add method to set url / setup network interface (or just take url paramter in this function)
uri: '{unknown at this point}',
});
networkInterface.use([{
applyMiddleware(req: any, next: any) {
req.uri = '{myUrlHere}';
next();
}
}]);
but that does not seem to work.
How do I set / change the uri?
My use case: I have a helper repository that wraps apollo for graphql, and the main repo has the url. The main repo sets the urls, and at that point, I need to set the graphql url (I don’t know it ahead of time, as it is set by a function call with which url to use).
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:15 (3 by maintainers)
Top Results From Across the Web
How to Update URL for Dynamic URLs - Stack Overflow
If you want to try this using AddThis, you can change the title and url by updating the page's title and history like...
Read more >Update** Update dynamic page URL field in a collection?
I have a dynamic form that collates information from two collections for a specific user. The dynamic form URL is set to my...
Read more >Updating WebSEAL for dynamic URLs - IBM
Use the dynurl update command to update the WebSEAL protected object space with entries made in the dynurl.conf configuration file. Create, edit, or...
Read more >Is it possible to dynamically update the source URL ... - TechNet
Hi Imke,. I've created a first table as you explained. Now, i have trouble to understand how to create a new query and...
Read more >Set dynamic url in field via a business rule - ServiceNow
I have a business rule that calls a REST Service to create an Incident in another ServiceNow instance. Upon return I will have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@carlospalacin this looks like it creates a new instance of the client on every request.
I think I found a more efficient way of doing this when I was looking at this ticket: https://github.com/apollographql/apollo-client/issues/1267
NetworkInterface is referenced so you can just extend it and update it in your application.
Basically you create a new class that extends HTTPFetchNetworkInterface:
Then create your client as instructed, but using the new network interface. Make sure you export the networkInterface when creating it:
Lastly, provide the networkInterface instance you created above in your module
Then basically you can inject GraphQLNetworkInterface anywhere in your application and call the setUri to update the URI. It will be the same instance of the network interface you used to instantiate the client.
Hi! I leave my solution, I have created apollo-client-manager.ts:
and apollo-service.ts:
and graphql.module.ts:
you can create your apollo instance with service:
don’t forget import graphql.module.ts in your module This works fine for me