Apollo-client: refetchQueries with string arguments not updating component

Created on 7 Apr 2017  ·  11Comments  ·  Source: apollographql/apollo-client

Intended outcome:
Given a query:

const AllUsersQuery = gql`
  query AllUsers {
    users {
      id
      login
    }
  }
`;

Using refetchQueries: ["AllUsers"] in a mutation should re-execute the query and update any components depending on that query.

Actual outcome:
While the query is re-executed, the component never updates. Using the apollo dev tools in Chrome, I can see the new User item listed in the store, but it never makes it to my component.

If I instead import the original query variable and use refetchQueries: [{query: AllUsersQuery}], everything works as expected.

How to reproduce the issue:
Use string arguments in refetchQueries

needs-reproduction

Most helpful comment

I'm seeing the same behaviour @jpikora, passing the query document works but passing the operation name as a Array doesn't update the cache.

All 11 comments

refetchQueries takes a query object, I don't think u can actually pass a string to it.

@saudpunjwani101 The documentation on refetchQueries says it can take an array of either strings or objects (and the first example uses the string option).

Yeah ur right, although the query does re execute it's not resolving the updates. I'll try it

@dmarkow could you provide a reproduction for this?

@dmarkow If your get back a union, then this could be the same problem as in #1611, which is 'fixed' (you'll get warnings what to do) by #1638 :-)

I just tried to reproduce this on the current version and can't, so maybe it was resolved with some of the recent updates... Thanks!

Might be related to the race-condition described in #1821.

I've just come across the same issue as @dmarkow.

Object format [{ query: ... }, ...] for refetchQueries is working correctly, but when using Strings ['queryName', ...] the store is not updated, even though the refetch requests are correctly executed.

[email protected]

@jpikora I still believe that this is the race condition outlined in #1821

I'm seeing the same behaviour @jpikora, passing the query document works but passing the operation name as a Array doesn't update the cache.

Any update on this? I still can't pass string arguments to refetchQueries, as they don't seem to update the cache. Apollo client v2.6.8

Was this page helpful?
0 / 5 - 0 ratings