Questions tagged [apollo-client]

Apollo Client is a JavaScript library for building client UIs that fetch data using GraphQL.

Apollo Client is the best way to use GraphQL to build client applications. The client is designed to help you quickly build a UI that fetches data with GraphQL, and can be used with any JavaScript front-end.

Apollo Client

Repository

3353 questions
29
votes
5 answers

Main module field cannot be resolved after installing @apollo/client

I'm running into an error after installing Apollo when trying to run my React Native Expo app. I've tried deleting node-modules and re-installing, resetting cache, restarting computer, and still no luck. Android Bundling failed 456ms While trying…
May
  • 321
  • 1
  • 3
  • 4
29
votes
1 answer

When to use watchQuery or query in Apollo-Angular?

I am using a watchQuery or query in Apollo-Angular (graphql) How is the logic and difference of the watchQuery and query
yussenn
  • 577
  • 1
  • 7
  • 11
27
votes
3 answers

Deleting Apollo Client cache for a given query and every set of variables

I have a filtered list of items based on a getAllItems query, which takes a filter and an order by option as arguments. After creating a new item, I want to delete the cache for this query, no matter what variables were passed. I don't know how to…
26
votes
6 answers

How to update the Redux store after Apollo GraphQL query returns

I'm fetching a list of data with the graphql HOC provided by react apollo. E.g.: const fetchList = graphql( dataListQuery, { options: ({ listId }) => ({ variables: { listId, }, }), props: ({ data: { loading,…
TheWebweiser
  • 621
  • 6
  • 10
25
votes
3 answers

Apollo Client delete Item from cache

Hy I'm using the Apollo Client with React. I query the posts with many different variables. So I have one post in different "caches". Now I want to delete a post. So I need to delete this specific post from all "caches". const client = new…
Tölz
  • 766
  • 2
  • 8
  • 18
25
votes
3 answers

CORS issue with using localhost:3000 to access graphql API at a different URL

I have searched all over StackOverflow and saw similar questions but have not found a working solution. Wondering if anyone has a working solution? I am developing a create react app on localhost:3000 and trying to access through my Apollo Client a…
Elaine
  • 383
  • 1
  • 5
  • 10
24
votes
4 answers

Is it possible to prevent `useLazyQuery` queries from being re-fetched on component state change / re-render?

Currently I have a useLazyQuery hook which is fired on a button press (part of a search form). The hook behaves normally, and is only fired when the button is pressed. However, once I've fired it once, it's then fired every time the component…
user11754604
  • 273
  • 1
  • 2
  • 6
22
votes
2 answers

How to execute query on every click using useLazyQuery()

Using useLazyQuery() hooks from @apollo/react-hooks I was able to execute a query on click of a button. But I cannot use it execute same query on consecutive clicks. export default ({ queryVariables }) => { const [sendQuery, { data, loading }] =…
arjun
  • 3,514
  • 4
  • 27
  • 48
22
votes
2 answers

How to do Batch Mutations with Apollo Client

I try to use ApolloClient 2.1 with the new Mutation Component. Simple use cases are working but now I have something more complex. What I want to achieve is to query data and put them in a list, then sort this list (here via react-sortable-hoc)…
schingeldi
  • 870
  • 2
  • 14
  • 26
21
votes
5 answers

How to force Apollo Query component to re-run query when parent component re-renders

I'm using Apollo Client's within a component that is re-rendered when state is changed within a lifecycle method. I wish to have my component re-run the query because I know that data has changed. It appears that Query component is…
Andrei R
  • 4,904
  • 5
  • 25
  • 26
21
votes
1 answer

How to set fetchPolicy globally on apollo-client queries?

I have a few mutations that should trigger some refetchQueries, but I need those queries to have a fetchPolicy other than the default. Is there a way to set fetchPolicy globally instead of per query? So to avoid setting fetchPolicy on each query.
Eduardo Polmann
  • 357
  • 3
  • 8
19
votes
1 answer

React apollo client: Warning: Can't perform a React state update on an unmounted component

I'm using react router and apollo client (v 3.0) in my react project. I have a nested route, let's say A -> B, where I use useQuery hooks to fetch different sets of data via graphql queries, let's say QA and QB respectively. In B I receive a new…
chingis
  • 1,514
  • 2
  • 19
  • 38
19
votes
7 answers

How to add header in Apollo GraphQL : iOS

Hy I am working in a project with Apollo GraphQL method and its working fine. But now the client required for adding additional header with Apollo API's. But after adding the header the API's response return as unAuthorized. I am adding the header…
Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43
19
votes
4 answers

Reset store after logout with Apollo client

I'm trying to reset the store after logout in my react-apollo application. So I've created a method called "logout" which is called when I click on a button (and passed by the 'onDisconnect' props). To do that I've tried to follow this example…
Putxe
  • 1,054
  • 1
  • 16
  • 23
18
votes
2 answers

"Found @client directives in query but no client resolvers were specified" Warning when using client cache

I've been following the Apollo Client docs on local state. I've implemented a very simple query of the client cache: export const GET_USER_ACCOUNTS = gql` query GetUserAccounts { userAccounts @client name @client …
Gilly Ames
  • 361
  • 4
  • 12