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
18
votes
2 answers

Apollo Link response headers

I am using the latest version of Apollo Client in a simple React app and I am trying to pull out a header value from the response that is being used to show the size of the record set being returned. I appreciate that this is not the most elegant…
smitp33
  • 411
  • 1
  • 3
  • 9
17
votes
4 answers

Property 'setLink' is missing in type 'ApolloClient' but required in type 'ApolloClient

I am setting up a new typescript project with react and apollo client. I am attempting to wire in the client like so: const client = new ApolloClient({ cache: new InMemoryCache(), link: new HttpLink({ uri: 'http://localhost:3000/graphql', …
Eric H
  • 1,323
  • 3
  • 14
  • 29
17
votes
1 answer

Is there a way to detect when data used by a query is evicted from the Apollo Client cache?

Apologies for the long question, but I'd be really grateful for some thoughts/help on the best strategy for cache invalidation & refetching queries in Apollo Client 3. Background First, some information about the scenario I'm imagining: There is…
Matt Wilson
  • 8,159
  • 8
  • 33
  • 55
17
votes
2 answers

How to run a mutation on mount with React Apollo 2.1's Mutation component?

We are currently moving from Relay to React Apollo 2.1 and something I'm doing seems fishy. Context: Some components must only be rendered if the user is authenticated (via an API key), so there is an Authenticator component guarding the rest of the…
astorije
  • 2,666
  • 2
  • 27
  • 39
17
votes
3 answers

optimisticResponse vs update in Apollo Client?

I want to use optimistic UI updates after a mutation: https://www.apollographql.com/docs/react/basics/mutations.html Im confused about the relationship between 'optimisticResponse' and 'update'. Here optimisticResponse is used: const…
Evanss
  • 23,390
  • 94
  • 282
  • 505
17
votes
1 answer

Apollo-client (react) - Update on create mutation - "Can't find field Fund({}) on object (ROOT_QUERY)"

Using: "react-apollo": "^1.4.3" In the parent component I query using GraphQL a parent node 'Fund' with children 'fundQuarterlyMetric'. This returns data in the following format: { id name ... fundQuarterlyMetrics (orderBy:…
Blackstone4
  • 681
  • 1
  • 9
  • 21
17
votes
2 answers

Apollo Client (React): Handling unexpected errors

I have been reviewing the Apollo documentation but I do not see information of how to go about handling server errors in the Apollo client. For example, suppose that the server either: Times out Becomes unreachable Unexpectedly fails How…
dipole_moment
  • 5,266
  • 4
  • 39
  • 55
16
votes
1 answer

Unsubscribe subscription in Apollo Client

In my component, I have this code: componentDidMount () { // Setup subscription listener const { client, match: { params: { groupId } } } = this.props client.subscribe({ query: HOMEWORK_IN_GROUP_SUBSCRIPTION, variables: { groupId }, …
V0iDiFiER
  • 165
  • 1
  • 1
  • 4
16
votes
1 answer

Difference between AWS Amplify & Apollo Client for GraphQL?

I agree Apollo Client is a pain to set up because of lots of boilerplate (although it becomes simple after reading the docs) & things like AWS Amplify, URQL, Apollo Boost & Micro GraphQL React makes it easy to work with GraphQL on the client. I am…
deadcoder0904
  • 7,232
  • 12
  • 66
  • 163
15
votes
3 answers

Using multiple endpoints in Apollo Client

this is my first discussion post here. I have learned Apollo + GraphQL through Odyssey. Currently, I am building my own project using Next.js which required fetching data from 2 GraphQL endpoints. My problem: How can I fetch data from multiple…
Eugene
  • 163
  • 1
  • 1
  • 6
15
votes
2 answers

Apollo Client what are active queries?

My Setup Typescript React App Backend GraphQL API Apollo Client Inspecting with Apollo Client Devtools Extension My question What are active queries? The Apollo Docs talks about active queries a lot but I am struggling to get an actual…
Simon Verhoeven
  • 347
  • 4
  • 16
15
votes
2 answers

Best practice for Next.js data fetching inside a component

I have a menu component that appears globally. What is the best practice for getting data into that component? I'm trying to take advantage of static generation that Next.js offers but all data fetching guidance from the Next.js team relates to…
serraosays
  • 7,163
  • 3
  • 35
  • 60
15
votes
0 answers

What is the difference between client.query and useQuery in Apollo?

In my query, I use a blend of remote and local properties. The local properties have different values depending on: The remote properties The current unix timestamp The local resolvers computes the local state according to these rules. Now, I face…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
15
votes
3 answers

How to use the loading property in a watchQuery when using the Apollo client for GraphQl

So when i get the response from my query, i can see there is a loading property. But i don't really get why they would pass it along. Because when you get the response it means that the loading is finished, hence the loading will always be false. Is…
Martijn van den Bergh
  • 1,434
  • 1
  • 20
  • 40
15
votes
2 answers

Apollo client link state "Missing field in {}" when writing to cache?

Im using Apollo Client, Graphcool and React. I have a working login form but I need the UI to update when the user is logged in, and I need this to happen in different components. It seems apollo-link-state is the solution for this. My code below…
Evanss
  • 23,390
  • 94
  • 282
  • 505