Mohammad K.
Mohammad K.

Reputation: 268

Apollo Graphql relayStylePagination prevents query to refetch on variables change

When I use relayStylePagination helper funtion in Apollo Client cache type policies, changing the variables passed to the query doesn't call the query again even if I call the refetch function manually. It perfectly does the fetchMore behavior and merges the new data.

My cache field looks like this:

cache: new InMemoryCache({
      typePolicies: {
        Query: {
          fields: {
            inventories: relayStylePagination(),
          },
        },
      },
    })

Upvotes: 5

Views: 967

Answers (2)

hwwi
hwwi

Reputation: 11

Maybe you need config like this..

cache: new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
        inventories: relayStylePagination(["variableName#1", ...etc]),
      },
    },
  },
})

Key arguments in Apollo Client

Upvotes: 0

Mohammad K.
Mohammad K.

Reputation: 268

I needed to manually call refetch while passing the new variables. Still have no clue why adding relay type policy prevents triggering refetch automatically.

Upvotes: 2

Related Questions