mutation not invalidating cache and fetch order seems mixed up #1049
-
|
We are using urql in a react project to manage our fetching and mutations for a rails graphql backend. We are noobs with Graphql and learning urql as we go but have hit a stumbling block on mutations. We are requesting a list of objects which works fine but when destroying one of the objects, the cache appears to optimistically update (good - it removes the object from the list) but before the mutation returns data, the fetch/query begins for the list of objects which goes straight to cache and returns the original list of objects. The mutation returns the original object but the cache is not invalidated and no fetch for the list occurs again. Is this normal behaviour or is our setup incorrect? We are using graphcache to normalise the cache too We are using a query with a variable to fetch a list of 'books' by the author id (not sure if interpolating a variable is best practice but it works) - we also return some nest associations
we then have a method to destroy a book
Both the query and the mutation work, in that the first fetches all the books and the second destroys a book. The issue is that the returned book from the mutation is not causing a refetch even though the __typename's are the same. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Hey, could you show us what's being returned from this query and mutation since this should automatically happen if you are using our default cache. For an empty list you might have to use additionalTypenames. So |
Beta Was this translation helpful? Give feedback.
-
|
from our fetch all books from our create mutation - not listed above from our delete |
Beta Was this translation helpful? Give feedback.
Hey, could you show us what's being returned from this query and mutation since this should automatically happen if you are using our default cache.
For an empty list you might have to use additionalTypenames.
So
deleteBook.__typename === 'Book'andbooks[0].__typename === 'Book'?