docs(express): document resolver response manipulation - #157
docs(express): document resolver response manipulation#157ayushvyas-dev wants to merge 2 commits into
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR addresses #141 by documenting how to access the Express Response via the request context and demonstrating how to expose it through the GraphQL context so resolvers can manipulate HTTP headers.
Changes:
- Expanded Express adapter documentation to describe
req.context.resand provide a resolver example for setting response headers/cookies. - Added a regression test verifying a resolver can set an HTTP response header through the Express response object.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/use.test.ts | Adds an Express regression test proving a resolver can set an HTTP header via the Express Response. |
| src/use/express.ts | Updates Express adapter docs to explain response exposure through request/GraphQL context and provide example usage. |
Suppressed comments (1)
src/use/express.ts:91
- These lines state that GraphQL resolvers can access the response via
req.context.res, but resolvers don’t receivereq; they receive the GraphQL context value. Reword to indicatereq.context.resis on the handler request, and that you can pass it into resolvers by returning it from thecontextoption.
* The Express response is available to GraphQL resolvers through
* `req.context.res`. This can be used to manipulate the HTTP response,
* for example to set response headers or cookies.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * The `res` property is the Express response object for the current request. | ||
| * It can be used to manipulate the HTTP response from the `context` option | ||
| * or from GraphQL resolvers, for example to set response headers or cookies. |
There was a problem hiding this comment.
I'd also move the documentation for the res property to the res property itself, rather than the interface as a whole
There was a problem hiding this comment.
Thanks for the feedback, @benjie . I've moved the res documentation to the res property itself and clarified that req.context.res needs to be returned from the context option to make it available to GraphQL resolvers. I've pushed the updates to the PR.
Description
This PR addresses #141 by documenting how GraphQL resolvers can access and manipulate the Express response through the request context.
Changes
RequestContextdocumentation to explain thatreq.context.resprovides access to the current ExpressResponse.Testing
yarn testyarn check:typeyarn check:lintyarn check:formatgit diff --checkCloses #141