Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refetch returns undefined data and errors #2914

Closed
psamim opened this issue Jan 26, 2018 · 6 comments
Closed

Refetch returns undefined data and errors #2914

psamim opened this issue Jan 26, 2018 · 6 comments

Comments

@psamim
Copy link
Contributor

psamim commented Jan 26, 2018

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

@psamim psamim changed the title Refetch returns undefined data and erros Refetch returns undefined data and errors Jan 26, 2018
@Poincare
Copy link
Contributor

The network status seems to indicate that there were to obvious errors with the query execution.

Could you implement a test case that elicits this behavior? That'll allow us to identify what is wrong and whether or not it constitutes intended behavior.

@hwillson
Copy link
Member

We haven't heard back regarding the reproduction requested in #2914 (comment), so closing for now. If this issue is still happening, and you're able to supply a reproduction, we'll be happy to re-visit it. Thanks!

quazzie added a commit to quazzie/apollo-client that referenced this issue Oct 24, 2018
Is there a reason why returnPartialData is true?
This was hiding an error and returning { data: undefined, networkState: 7, stale: true } for me.
I had forgotten to query for the id of an object and watchQuery could not find it in store.
With returnPartialData false i was able to get an error about missing property and finally find the problem.
With this true all i was getting from watchQuery was { data: undefined, networkState: 7, stale: true }.

Maybe related issues: apollographql#3030 , apollographql#2914
@vinit-m
Copy link

vinit-m commented Jun 4, 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 } })

@vinit-m
Copy link

vinit-m commented 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', }

@kenjinp
Copy link

kenjinp commented May 19, 2021

I create the apollo client instance with the default settings set to no-cache, but I still had to explicitly set the fetchPolicy to no-cache in my queries to avoid this issue!

@brainkim
Copy link
Contributor

brainkim commented May 19, 2021

@kenjinp This is probably related to #8063 and potentially fixed by #8262. Whenever you see this the problem is usually that you’re missing a field in the JSON response.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants