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.

After refetch fails, successful fetchMore sends updateQuery undefined previousResults

See original GitHub issue

Intended outcome: After server downtime, during which a call to refetch fails, I would expect future successful queries using fetchMore to call the updateQuery function with previousResults from before the downtime.

Actual outcome: After failed calls to refetch, successful calls to fetchMore call the updateQuery function with a first argument (previousResults) value of undefined. At that point, there is no way to use the existing results.

A log looks something like this:

Server online, screen loading
Component rendering with data: {loading: true, networkStatus: 1, error: undefined}
Component rendering with data: {names: ["a", "b", "c", "d", "e"], loading: false, networkStatus: 7, error: undefined}
Server going offline
Attempting to sort (using `refetch` with variables as a promise)
Component rendering with data: {names: ["a", "b", "c", "d", "e"], loading: true, networkStatus: 2, error: undefined}
Component rendering with data: {names: ["a", "b", "c", "d", "e"], loading: false, networkStatus: 7, error: "Error: GraphQL error: ..."}
Sort failed
Server going online
Attempting to paginate
fetchMore's updateQuery method called with previousResults: undefined

How to reproduce the issue: Set up a repo that uses both refetch for sorting and fetchMore for pagination.

  1. Load the initial results successfully
  2. Go offline
  3. Try sorting the results (which should fail)
  4. Go online
  5. Try paginating The updateQuery method is called with a first argument, previousResults, of undefined.

I’ve created a branch to demonstrate the behavior: https://github.com/treyp/react-apollo-error-template/tree/previousresults-undefined

This can also be found on CodeSandbox: https://codesandbox.io/s/github/treyp/react-apollo-error-template/tree/previousresults-undefined

Follow the steps above, just like the screen recording here, to reproduce.

apollo-updatequery

Versions

  System:
    OS: macOS 10.14.6
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    npm: 6.10.3 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Browsers:
    Chrome: 76.0.3809.100
    Safari: 12.1.2
  npmPackages:
    apollo-cache-inmemory: ^1.6.3 => 1.6.3 
    apollo-client: ^2.6.4 => 2.6.4 
    apollo-link-batch-http: ^1.2.12 => 1.2.12 
    react-apollo: ^3.0.0 => 3.0.0 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ManAnRuckcommented, Feb 15, 2020

i have the same issue, that fetchMore is for some queries very buggy.

when I fetch more directly it’s undefined. after ignoring this and run refetch the and then fetchMore/updateQuery it works fine. 🧐

1reaction
hwillsoncommented, Apr 27, 2021

Can someone confirm if this is still an issue with @apollo/client@latest? I’ll close this for now, but happy to re-open if this is still happening. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also...
Read more >
Apollo Graphql fetchMore, updateQuery does not update state
I'm not sure why, but setting a fetchPolicy for Apollo will do the job const client = new ApolloClient({ link: authLink.concat(httpLink), ...
Read more >
Components - Client (React) - Apollo GraphQL Docs
The Query component accepts the following props. query is required. Option, Type, Description. query, DocumentNode, A GraphQL query document parsed ...
Read more >
React with Apollo and GraphQL Tutorial - Robin Wieruch
In the following, it needs two steps to connect the Apollo Client with ... Every other request to fetch more items from the...
Read more >
type error: 'component' cannot be used as a jsx component. nextjs ...
Same error! A bit stuck with where to start looking as this error seems to be happen to loads of things after yarn...
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