Skip to content

Commit 9311842

Browse files
authored
fix(server): Add request to the operation instrumentation's payload (#3874)
* fix(server): Add `request` to the `operation` instrumentation's payload * changeset
1 parent 2082071 commit 9311842

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

.changeset/young-emus-drop.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'graphql-yoga': patch
3+
---
4+
5+
Gives access to the request in the `operation` instrument payload, since the request is not in the
6+
context yet.

packages/graphql-yoga/src/plugins/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export type Instrumentation<TContext extends Record<string, any>> =
9696
EnvelopInstrumentation<TContext> &
9797
ServerAdapterInstrumentation & {
9898
operation?: (
99-
payload: { context: TContext },
99+
payload: { context: TContext; request: Request },
100100
wrapped: () => PromiseOrValue<void>,
101101
) => PromiseOrValue<void>;
102102
requestParse?: (

packages/graphql-yoga/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ export class YogaServer<
690690
}
691691
const getResultForParams = this.instrumentation?.operation
692692
? (payload: { request: Request; params: GraphQLParams }, context: any) => {
693-
const instrumented = getInstrumented({ context });
693+
const instrumented = getInstrumented({ context, request: payload.request });
694694
const tracedHandler = instrumented.asyncFn(
695695
this.instrumentation?.operation,
696696
this.getResultForParams,

0 commit comments

Comments
 (0)