goget

A fetch client built to interact with GraphQL-based APIs with built in rate-limiting retry functionality and a Strategy concept to requests and run consistent post-response logic.
Motivation
The original motivation for this fetch wrapper was to deal with the cache changes that were made to Next.js. I needed a consistent way to apply caching to all requests. A CMS I like to use (DatoCMS) also released a feature called Cache Tags to further help to control & bust this same Cache. I wanted to set up this client to implement this feature in the future, which is where the Strategy Concept comes in.
Strategy Concept
This was added to allow a developer to run specific code;
- Before the request to change the
RequestInitobject - After the request to do something with the
Responseobject
But why? In short, because Next.js cache. Whenever I make a request I can add a strategy to the request to add the required revalidate and/or tags to the request, or, force the request to never cache etc etc. Setting these up as classes that implement the QueryStrategy interface means I can set up specific caching strategies once and use them across any request. This also makes it more explicit to a developer what is happening to the request. Seeing a request with a NoCacheStrategy is makes it pretty obvious what it’ll do.
To see how it works, check out Using a Strategy in the usage guide.