Replies: 2 comments 1 reply
-
Hi, I like the idea of having a common place to share data across all lifecycles 👍 Does it also mean that every hook can manipulate that context, or is it read-only? |
Beta Was this translation helpful? Give feedback.
1 reply
-
It's worth explicitly stating when |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Situation
Currently, we propagate a context object through the request chain of WunderGraph. This context object contains fields like the client request, user (extracted from cookie or JWT), internal client (to call into other Operations) and log (for standardized logging).
Problem
As a user, I'd like to be able to add custom fields to the request context, like a request ID (generated in a specific way), info about feature flags, a/b testing, etc... This context object should be populated by a middleware that is running before all other hooks. The custom ctx should be accessible to all subsequent requests generated by the initial client request, hence propagated through the whole request chain.
Current state
This context is defined in
packages/sdk/src/middleware/types.ts
:Proposed solution
With this change, the user defined Context extension is type-safe.
Next, we need to populate this custom context.
We do so by adding a new hook to
wundergraph.server.ts
.Beta Was this translation helpful? Give feedback.
All reactions