How to use apollo client without/outside component?
See original GitHub issueI have to use apollo client without react component , it means that I cannot use useApolloClient
hook and withApollo
HOC. I wanna use client.query
and client.mutate
methods, so I have to be able to access client
instance. In this situation, I extracted client
instance as separate module and import that instance. Is it right way to use apollo client outside component? If it isn’t, what is the best approach?
client.ts (NOT REACT COMPONET)
export const client = new ApolloClient(...)
outsideComponent.ts (NOT REACT COMPONET)
import { client } from './client';
const veryComplexQuery = client.query....
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
How to run Queries/mutation outside of react components - Help
Hi Everyone, I have js file with multiple helper function which i call and use from many different components. Currently i call an...
Read more >How to call GraphQL outside a component - Stack Overflow
From a React component you can use useLazyQuery from Apollo Client which will only fire when you call it.
Read more >How to use apollo client without hooks (useQuery, and ...
In this article you will find out how to use apollo client without hooks such as useQuery or useMutation.
Read more >Components - Client (React) - Apollo GraphQL Docs
A guide to using the Apollo GraphQL Client with React.
Read more >How to: Vue-apollo v4 useQuery, outside Vue-component ...
Vue- apollo version 4 brought us composition-api that we can use with VueJS 3. It is a great library. But how do you...
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 Free
Top 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
This is what I have done. I am using a singleton pattern.
Now, wherever I need client, I call
getApolloClient()
.Hey @baeharam , do you mind providing an example of how you solved this with dependency injection? Are you referring to your initial explanation of creating the client instance in a separate module and then just importing it where you need it? Have you ran into any issues with that config? Thx for your time!