urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.57k stars 445 forks source link

Graphcache cache invalidation no longer working within optimistic update #3396

Closed dizlexik closed 6 months ago

dizlexik commented 10 months ago

Describe the bug

I just upgraded @urql/exchange-graphcache in my project from v6.0.4 to v6.3.3 and it broke some cache invalidation I was doing within an optimistic handler. The code is very simple and is along the lines of this example in the documentation: cache.invalidate({ __typename: 'Todo', id: 1 }). The line has no effect now within the optimistic handler, but moving it into updates.Mutation works. This is an okay workaround for now but not ideal. I'd rather this cache invalidation happen immediately when the mutation is executed, like it was before, instead of having to wait for the response. I don't see any changes in the documentation in this area so this feels like a bug to me. Any help would be greatly appreciated, thanks!

Reproduction

No time, sorry

Urql version

@urql/exchange-graphcache v6.3.3

Validations

JoviDeCroock commented 10 months ago

updates.Mutation is called for optimistic updates as well, so as long as you return an optimistic result it will get invoked even for your optimistic updates 😅 I would love to know what version exactly broke it as we normally ask for a reproduction, saying "no time" is a bit.. disrespectful given that we give our time to you for free as well

dizlexik commented 10 months ago

I thought it would be helpful to document this issue here so that other users who may be experiencing the same problem can have a place to discuss it, and it seemed reasonable to me to write this up so that any contributors familiar with this area of the code would be aware that there is a defect. I very much appreciate all of the hard work that you and others have put into this great library, but the truth is that I really don't have the time right now to create a reproduction of this, so if it's disrespectful to point out this bug without doing that then I apologize, and please feel free to delete the issue. I'll take a look at it myself when I have more time, and I'll be careful about posting issues here in the future. Thanks for your time, xoxo.

JoviDeCroock commented 6 months ago

Closing due to inactivity, always open to re-opening this when we have a minimal reproduction that illustrates the problem