How to update the store when query to be updated has filters

Hey,

I have been trying to update the store of my apollo+react app after a create mutation but am failing miserably. The issue is as follows: I have a component showing a list of items which are fetched using a query named ALL_ITEMS_QUERY. In another component, i have a mutation which creates an item. Both the mutation and the query to fetch seem to work fine in isolation. When i try to read the store in an update() function:

update:(store, {data:{createItem}}) => {
     
   const data=store.readQuery({query: ALL_ITEMS_QUERY})
     
}

I find that if the ALL_ITEMS_QUERY has no filters, I am able to read the store and things work just fine. However, if the ALL_ITEMS_QUERY has any filters applied to it, I get an error of the form :

Can’t find field allItems({“filter”:{“AND”:[{“type”:{“description”:“XYZ”}},{“thing”:{“ent”:{}}}]}}) on object (ROOT_QUERY)

I cannot seem to find anything in the docs to cover this use case. What am I missing? Can someone please point me in the right direction?

I was able to fix this. In case anybody stumbles upon this, the issue was that the ALL_ITEMS_QUERY with filters need the variables passed to the filters available to them and in this scenario they were not.

The relevant part of the docs:

“If all of the data needed to fulfill this read is in Apollo Client’s normalized data cache then a data object will be returned in the shape of the query you wanted to read. If not all of the data needed to fulfill this read is in Apollo Client’s cache then an error will be thrown instead, so make sure to only read data that you know you have!”

can be found here .