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.

Refetch returns undefined data and errors

See original GitHub issue

Intended outcome: I want to use refetch to re-send the same query with new variables. I expect the returned promise to deliver the results in data.

Actual outcome: When refetch is used with new variables, the following object is returned by the promise:

{
  data: undefined
  errors: undefined,
  loading: false,
  networkStatus: 7,
  stale: false,
}

Version

  • apollo-client@2.2
  • react-apollo@2.0.4

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
vinit-mcommented, Jun 5, 2020

I’m getting the exact same issue, the API hits successfully and returns data in network tab (chrom dev tools) but the promise returned by refetch has {data: undefined, errors: undefined, loading: false, networkStatus: 7, stale: false}. This happens when I pass variable (dynamic) in refetch as refetch({ first: 10, filter: { search } })

I found the issue, I had implemented cache in my apollo client, so whenever I was using refetch it used to get response from the cache. If variables were different it would return undefined. Setting up fetch policy to ‘no-cache’ in query options (I’m using hooks) resolved the issue { variables: { first: 10, filter: { search: '' } }, fetchPolicy: 'no-cache', }

1reaction
brainkimcommented, May 20, 2021

@kenjinp This is probably related to https://github.com/apollographql/apollo-client/issues/8063 and potentially fixed by https://github.com/apollographql/apollo-client/pull/8262. Whenever you see this the problem is usually that you’re missing a field in the JSON response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refetching queries in Apollo Client - Apollo GraphQL Docs
The client.refetchQueries method collects the TResult results returned by onQueryUpdated , defaulting to TResult = Promise<ApolloQueryResult<any>> if ...
Read more >
Apollo-client useLazyQuery returning undefined on refetch
I have a subcomponent Viewer that uses a refetch function passed down to its parent Homescreen. The lazyQuery in homescreen is structured as ......
Read more >
Handling `undefined` in React Query and Typescript - neldeles
Generally, on the first render cycle, data will be undefined because well, the data is async and does not exist yet on the...
Read more >
useQuery | TanStack Query Docs
Receives a QueryFunctionContext; Must return a promise that will either resolve data or throw an error. The data cannot be undefined . enabled:...
Read more >
useQuery returns undefined, But returns data on gql ...
I ran into similar problem when data is shown completely in playground, but empty in actual app. I checked dev tool and saw...
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