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 444 forks source link

RFC: Operation context cache miss information #3382

Closed Banou26 closed 8 months ago

Banou26 commented 10 months ago

Summary

Having an additional response operation.context.meta.cacheOutcome field to know what field(s) caused the cache miss.

I've spent so many hours trying to debug a local cache resolver to find why a field would return null(with partial miss), or a request not return anything at all(without partial miss).

There's no error or warning messages if a cache field doesn't return a value or a correct value beside the "should have returned a scalar type" warning.

On simple applications this doesn't really happen, but if your application complexity increase a bit and your resolvers query other resolvers, this start to happen pretty easily.

Having a better workflow to work with the cache in general would be great.

Proposed Solution

Add a new field in the context meta cacheOutcome object with the fields paths/refs that caused the cache miss. Additionally it could also be useful to get the returned value of those fields.

JoviDeCroock commented 8 months ago

Hey,

Sorry about the delay here, I was thinking about the complexities involved here as there might be multiple things attributing a cache-miss and a missing field doesn't necessarily equate a cache-miss, think about fragments that don't match the underlying shape for instance.

With the arrival of our custom logger in https://github.com/urql-graphql/urql/pull/3444 it might be appealing to re-purpose that to issue a debug log when we are missing a field, miss match a fragment, ....