apollo-client: refetchQueries not working when using string array after mutation

Intended outcome: A query specified using a string identifier should be refetched when using refetchQueries.

Actual outcome: The query is not refetched and old versions of the query data are used from the cache.

How to reproduce the issue: One way to reproduce:

  • Using Hasura, create a table posts
  • Query 1: posts (fetches all posts)
  • Query 2: posts_by_pk (fetching a single post)
  • Mutation 1: update_posts_by_pk

Then, if mutation 1 has refetchQueries set to ['posts'] (or whatever the query is called), it won’t actually refetch and returns the error:

Unknown query named "posts" requested in refetchQueries options.include array

Versions System: OS: Linux 5.4 Linux Mint 20 (Ulyana) Binaries: Node: 16.7.0 - ~/.nvm/versions/node/v16.7.0/bin/node Yarn: 1.22.11 - ~/.nvm/versions/node/v16.7.0/bin/yarn npm: 7.20.3 - ~/.nvm/versions/node/v16.7.0/bin/npm Browsers: Chrome: 100.0.4896.75 Firefox: 99.0 npmPackages: @apollo/client: ^3.5.10 => 3.5.10 npmGlobalPackages: apollo: 2.33.6

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 4
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Plus it only seems to happen in dev mode.

We’re finding this to happen when using <React.StrictMode>. Removing <React.StrictMode> makes my development environment behave the same way as production in respect to refetchQueries no longer working.

I am suddenly running into a similar or same issue:

Unknown query named "BeobAssignLinesQuery" requested in refetchQueries options.include array

There are several additional mentions as a few queries are usually requeried together. But focusing on this one.

Query is here: https://github.com/barbalex/apf2/blob/8b5bce3a1585478e6b5a5b7c83b1a66ba328580d/src/components/Projekte/Karte/layers/BeobZugeordnetAssignPolylines/index.jsx

Refetches are here:

Thing is: This does not happen on the live version (yet). So it may be due to a recent change in @apollo/client. We updated yesterday to 3.7.11.

Edit: I tried using v3.7.10 but same error. These files have not been changed in at least two months. While everything worked fine. Until today.

Edit 2: Could it be that apollo does not know the query if one of it’s parents is lazy loaded and the refetch comes from a different component that is not in the same lazy loaded component tree?

Edit 3: It seems this happens in dev but not in production.

We’re experiencing the same issue. If we pass the query with all variables it works. If we pass a string name for the query with no variables, it does not work and we’re met with “Unknown query named …”

This works

const [handlePublish] = useMutation(UPDATE_POST, {
    refetchQueries: [
      {
        query: GET_POSTS,
        variables: {
          orderBy: {},
          first: 50,
          last: null,
          after: null,
          filters: {
            published: true,
          },
        },
      }, 
    ],
  });

This does not work

const [handlePublish] = useMutation(UPDATE_POST, {
    refetchQueries: ["posts"],
});