4

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(),
          },
        },
      },
    })
Mohammad K.
  • 238
  • 3
  • 12

1 Answers1

2

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

Mohammad K.
  • 238
  • 3
  • 12
  • I have the same issue! Can you please provide an example or explanation of where you called refetch? – Sean W Nov 24 '22 at 04:12
  • 1
    @SeanW You can do it like this: refetch({ details: { sort: { sortBy: sortBy, }, filters: handleFilters, searchTerm: searchTerm, }, after: 0, }); Of course these parameters are based on your query types. Also one thing that I experienced is that you need to call the refetch in an useEffect It doesn't work if you call it in your callback props and I still don't know why. – Mohammad K. Nov 26 '22 at 15:18