How to use ApolloClient in Selector
See original GitHub issueThanks for providing the great library.
I try to load asynchronos data as described in the example with an Apollo GraphQl client. This works:
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: 'http://localhost:1337/graphql',
})
});
const currentPatientsQuery = selector({
key: 'Patients',
get: async ({get}) => {
const response = await client.query ({
query: PATIENTS,
fetchPolicy: "network-only",
});
return response.data.patients;
},
});
Now I want to use the client I had created in my App.tsx.
Normaly I would use:
const client = useApolloClient();
But this is not working.
Is it possible to use other react hooks together with recoil ?
Thanks for your help.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Redux to Apollo: Data Access Patterns - Apollo GraphQL Blog
Selectors are just utility functions that read, aka select, data from that global state object. For example, your Redux state might look like ......
Read more >Set Context with Apollo Client - YouTube
... your Apollo Client based on the behaviour of users in your app, ... our request headers using the value from a custom...
Read more >Integrating with Redux | Apollo React Docs - Amazon S3
By default, Apollo Client creates its own internal Redux store to manage queries and their results. If you are already using Redux for...
Read more >Data retrieval in GraphQL with react-apollo - LogRocket Blog
By the end of your reading, you will learn how to use and install GraphQL and Apollo client, and two different approaches for...
Read more >React Native. Upload file apollo client - Stack Overflow
enter image description here Trying to send the file this way with a single button click using react-native-image-crop-picker I already sent ...
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
The
recoil-relay
library is also now available for working with GraphQL and Recoil. This uses Relay instead of Apollo, but does allow for easy syncing of GraphQL queries with Recoil.@dcantu96 Like you and @zbyte64 said, we should always use hooks inside a component. It might work when you use them otherwise, but can break in some edge cases or future releases, depending on how exactly it’s implemented.
We don’t have an easy way to make it work appropriately at the moment. But we’ve been working on a sister library called “recoil-sync” to address this issue, with which you can sync a piece of external data to an atom. Our current plan is to release it in March, but you can preview the doc here. We appreciate feedbacks on the design, docs and source code. I’ll also ping the thread once it’s released. Thanks for the support!