graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

Cache transform should wait until active requests for the same cache key are completed

Open ntziolis opened this issue 2 years ago • 0 comments

If 2 requests have the same cache key. At any given point there should only be one active call to originalResolver. Right now the second request will also be executed when the first request hasn't returned yet. Instead the Cache transform should wait until active requests for the same cache key are completed.

In our case:

  • We leverage openapi handler on top of badly designed rest apis (out of our control)
  • We then use delegateToSchema (within additionalResolvers) to create relationships between the rest endpoints
  • And then we leverage the cache transform to cache all lookup data which is 100% stable

We were able to reduce number of calls from 75 to 16. By ensuring the cache only makes a request when no other request is active (via patch-package)

Describe the solution you'd like Cache transform should wait until active requests for the same cache key are completed.

Describe alternatives you've considered Implement batch loader in openapi-to-graphql package. We decided against it because we feel this issue is universal and the cache should never make a second request for the same cacheKey if one request for the same cacheKey is already active.

ntziolis avatar Oct 18 '21 14:10 ntziolis