React-apollo: partialRefetch behaving differently (incorrectly?) from v2.x

Created on 16 Oct 2019  ·  7Comments  ·  Source: apollographql/react-apollo

Intended outcome:
If I have a query rendered like this:

query MyQuery {
  user {
    id
    todos { # list of todos
      id
      title
      completed
    }
  }
}

And I've just executed a mutation like this:

mutation AddTodoToUser {
  addTodoToUser { # appends a new todo to the user
    user {
      id
      todos {
        id
      }
    }
  }
}

If I have partialRefetch on for the query, I would expect the query to be re-fetched to get the missing data for the new todo. This is what happened before I upgraded from 2.x.

Actual outcome:
The query is not re-fetched, and the query continues to render the stale data that does not include the new todo.

I dug through the source code, and I think this code from the QueryManager is part of the problem:
https://github.com/apollographql/apollo-client/blob/d61e90926cb5f5c559f3daa1c974fac225b1c5b2/packages/apollo-client/src/core/QueryManager.ts#L627-L637

Because returnPartialData is false, the query manager interprets the new partial data as stale. And this causes the query manager to not provide its subscribers with the new data. Therefore, this codeblock is never hit, so the refetch never happens.

I can't just start passing returnPartialData to my queries because I don't actually want to receive any partial data—I just want the Query component/hook to receive it so that it can trigger the partial refetch.

How to reproduce the issue:
Set up a query/mutation as described above!

Version

  System:
    OS: macOS 10.15
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
  Browsers:
    Chrome: 77.0.3865.120
    Firefox: 66.0.2
    Safari: 13.0.2

Most helpful comment

I can confirm half of this is fixed in v3 beta. Partial refetching works correctly now, but during the partial refetch the component has its data reset to undefined. I have an open PR to have partial refetches retain the last result so they behave the same as triggering another useQuery.

https://github.com/apollographql/apollo-client/pull/6012

All 7 comments

Update: I'm working on a failing test case for this. Hope to have it up soon!

Update: converted the failing testcase PR into one that also implements a solution: #3606

Could only downgrade to react-apollo@^2, and use https://github.com/trojanowski/react-apollo-hooks for now.

@hwillson any updates on this? I noticed there is a PR that fixes this that has been in review for a couple months now

Any updates?

@fran-costa Can confirm this is fixed in @apollo/client@3 (beta). react-apollo needs to be replaced with @apollo/[email protected] though. But upgrading does fix this for me!

I can confirm half of this is fixed in v3 beta. Partial refetching works correctly now, but during the partial refetch the component has its data reset to undefined. I have an open PR to have partial refetches retain the last result so they behave the same as triggering another useQuery.

https://github.com/apollographql/apollo-client/pull/6012

Was this page helpful?
0 / 5 - 0 ratings