Refetch returns undefined data and errors
See original GitHub issueIntended 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:
- Created 6 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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', }
@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.