You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The context Apollo Server exposes through resolvers is very convenient when using it within the same function, however, when more layers are added, passing ctx all around becomes messy.
Let's say we have a tenantId and tenantName that we extract from headers on every request. We need to pass them on to internal APIs down the line, but we have the following structure:
Can we pass ctx down to the function that consumes it? - absolutely, is it clean? - no.
I tried writing an express middleware that would wrap next() in Node's AsyncLocalStorage, but it doesn't work. This was brought up previously regarding a library that was trying to achieve the same goal.
Then I wrote a wrapper withCtx that wraps around resolvers and the context becomes available in all downstream functions, but I have to wrap every resolver manually.
Is there a way to make express middleware work? Alternatively, is there some kind of apollo middleware that would allow wrapping the rest of the request in an ALS?
The text was updated successfully, but these errors were encountered:
The context Apollo Server exposes through resolvers is very convenient when using it within the same function, however, when more layers are added, passing
ctx
all around becomes messy.Let's say we have a
tenantId
andtenantName
that we extract from headers on every request. We need to pass them on to internal APIs down the line, but we have the following structure:Can we pass
ctx
down to the function that consumes it? - absolutely, is it clean? - no.I tried writing an express middleware that would wrap
next()
in Node'sAsyncLocalStorage
, but it doesn't work. This was brought up previously regarding a library that was trying to achieve the same goal.Then I wrote a wrapper
withCtx
that wraps around resolvers and the context becomes available in all downstream functions, but I have to wrap every resolver manually.Is there a way to make express middleware work? Alternatively, is there some kind of apollo middleware that would allow wrapping the rest of the request in an ALS?
The text was updated successfully, but these errors were encountered: