Apollo-client: Refetch returns undefined data and errors

Created on 26 Jan 2018  路  4Comments  路  Source: apollographql/apollo-client

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

needs-reproduction

Most helpful comment

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', }

All 4 comments

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.

We haven't heard back regarding the reproduction requested in https://github.com/apollographql/apollo-client/issues/2914#issuecomment-360741571, 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!

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'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', }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichaelDeBoey picture MichaelDeBoey  路  3Comments

helfer picture helfer  路  3Comments

rafgraph picture rafgraph  路  3Comments

stubailo picture stubailo  路  3Comments

timbotnik picture timbotnik  路  3Comments