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 use ApolloClient in Selector

See original GitHub issue

Thanks 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
drarmstrcommented, Jun 2, 2022

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.

0reactions
mondaychencommented, Feb 23, 2022

@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!

Read more comments on GitHub >

github_iconTop 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 >

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