apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.

Home Page:https://www.apollographql.com/docs/apollo-server/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apis that have their requests cached dont need to make unnecessary auth token fetches

samstitt opened this issue · comments

Issue

You have API-A that as part of its request requires an auth token from API-B, Once you get a response for API-A you cache the payload for 24 hours in something like redis.

A new request comes in that requires API-A, However you don't want to request API-B again if its in the cache. It would be good if there was a restdatasource hook that would only be called if its not in the cache to allow you to fetch auth tokens before sending the request again.

the flow would be something like

apollo drawio

because the request API-A has a dependency on API-B you have to fetch it before making the request to API-A even if API-A is in the cache because the cache check is only done on fetch meaning you have to build the full request prior to sending.

you could in theory manually checking redis via the context is possible but I am sure there are a few usecases for a cache-miss hook that could be abstracted to a function