Skip to content

Commit 3322438

Browse files
committed
feat(execution): store document on validated args
1 parent f9f737b commit 3322438

10 files changed

Lines changed: 28 additions & 3 deletions

File tree

integrationTests/diagnostics-bun/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function runExecuteRootSelectionSetCase() {
153153
events.push({
154154
kind: 'start',
155155
schema: msg.schema,
156+
document: msg.document,
156157
operation: msg.operation,
157158
variableValues: msg.variableValues,
158159
operationName: msg.operationName,
@@ -180,6 +181,7 @@ function runExecuteRootSelectionSetCase() {
180181
);
181182
assert.equal(events[0].operationType, 'query');
182183
assert.equal(events[0].operationName, 'Greeting');
184+
assert.equal(events[0].document, document);
183185
assert.equal(events[0].operation, operation);
184186
assert.equal(events[0].schema, schema);
185187
assert.equal(events[1].result, result);

integrationTests/diagnostics-deno-with-deno-build/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function runExecuteRootSelectionSetCase() {
153153
events.push({
154154
kind: 'start',
155155
schema: msg.schema,
156+
document: msg.document,
156157
operation: msg.operation,
157158
variableValues: msg.variableValues,
158159
operationName: msg.operationName,
@@ -180,6 +181,7 @@ function runExecuteRootSelectionSetCase() {
180181
);
181182
assert.equal(events[0].operationType, 'query');
182183
assert.equal(events[0].operationName, 'Greeting');
184+
assert.equal(events[0].document, document);
183185
assert.equal(events[0].operation, operation);
184186
assert.equal(events[0].schema, schema);
185187
assert.equal(events[1].result, result);

integrationTests/diagnostics-deno-with-node-build/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function runExecuteRootSelectionSetCase() {
153153
events.push({
154154
kind: 'start',
155155
schema: msg.schema,
156+
document: msg.document,
156157
operation: msg.operation,
157158
variableValues: msg.variableValues,
158159
operationName: msg.operationName,
@@ -180,6 +181,7 @@ function runExecuteRootSelectionSetCase() {
180181
);
181182
assert.equal(events[0].operationType, 'query');
182183
assert.equal(events[0].operationName, 'Greeting');
184+
assert.equal(events[0].document, document);
183185
assert.equal(events[0].operation, operation);
184186
assert.equal(events[0].schema, schema);
185187
assert.equal(events[1].result, result);

integrationTests/diagnostics-node20/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function runExecuteRootSelectionSetCase() {
153153
events.push({
154154
kind: 'start',
155155
schema: msg.schema,
156+
document: msg.document,
156157
operation: msg.operation,
157158
variableValues: msg.variableValues,
158159
operationName: msg.operationName,
@@ -180,6 +181,7 @@ function runExecuteRootSelectionSetCase() {
180181
);
181182
assert.equal(events[0].operationType, 'query');
182183
assert.equal(events[0].operationName, 'Greeting');
184+
assert.equal(events[0].document, document);
183185
assert.equal(events[0].operation, operation);
184186
assert.equal(events[0].schema, schema);
185187
assert.equal(events[1].result, result);

src/diagnostics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export interface GraphQLExecuteContext {
115115
*/
116116
export interface GraphQLExecuteRootSelectionSetContext {
117117
schema: GraphQLSchema;
118+
document: DocumentNode;
118119
operation: OperationDefinitionNode;
119120
variableValues: Maybe<{ readonly [variable: string]: unknown }>;
120121
operationName: string | undefined;

src/execution/ExecutionArgs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export interface ExecutionArgs {
6767
export interface ValidatedExecutionArgs {
6868
/** Schema used for execution. */
6969
schema: GraphQLSchema;
70+
/** Parsed GraphQL document being executed. */
71+
document: DocumentNode;
7072
// TODO: consider deprecating/removing fragmentDefinitions if/when fragment
7173
// arguments are officially supported and/or the full fragment details are
7274
// exposed within GraphQLResolveInfo.

src/execution/Executor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,14 @@ export class Executor<
266266
/**
267267
* Build an operation-scoped diagnostics context from ValidatedExecutionArgs.
268268
* Used after the operation has already been resolved during argument
269-
* validation. The original document is not available at this point, only the
270-
* resolved operation; subscribers that need the document should read it from
271-
* the graphql:execute or graphql:subscribe contexts.
269+
* validation.
272270
*/
273271
buildExecuteContextFromValidatedArgs(
274272
args: ValidatedExecutionArgs,
275273
): GraphQLExecuteRootSelectionSetContext {
276274
return {
277275
schema: args.schema,
276+
document: args.document,
278277
operation: args.operation,
279278
variableValues: args.rawVariableValues,
280279
operationName: args.operation.name?.value,

src/execution/__tests__/diagnostics-execute-test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ describe('execute root selection set diagnostics channel', () => {
389389
channel: 'start',
390390
context: {
391391
schema,
392+
document,
392393
operation,
393394
variableValues,
394395
operationName: 'Q',
@@ -399,6 +400,7 @@ describe('execute root selection set diagnostics channel', () => {
399400
channel: 'end',
400401
context: {
401402
schema,
403+
document,
402404
operation,
403405
variableValues,
404406
operationName: 'Q',
@@ -427,6 +429,7 @@ describe('execute root selection set diagnostics channel', () => {
427429
channel: 'start',
428430
context: {
429431
schema,
432+
document,
430433
operation,
431434
variableValues: undefined,
432435
operationName: undefined,
@@ -437,6 +440,7 @@ describe('execute root selection set diagnostics channel', () => {
437440
channel: 'end',
438441
context: {
439442
schema,
443+
document,
440444
operation,
441445
variableValues: undefined,
442446
operationName: undefined,
@@ -447,6 +451,7 @@ describe('execute root selection set diagnostics channel', () => {
447451
channel: 'asyncStart',
448452
context: {
449453
schema,
454+
document,
450455
operation,
451456
variableValues: undefined,
452457
operationName: undefined,
@@ -457,6 +462,7 @@ describe('execute root selection set diagnostics channel', () => {
457462
channel: 'asyncEnd',
458463
context: {
459464
schema,
465+
document,
460466
operation,
461467
variableValues: undefined,
462468
operationName: undefined,

src/execution/__tests__/diagnostics-subscribe-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ describe('subscribe diagnostics channel', () => {
202202
channel: 'start',
203203
context: {
204204
schema,
205+
document,
205206
operation,
206207
variableValues,
207208
operationName: 'S',
@@ -212,6 +213,7 @@ describe('subscribe diagnostics channel', () => {
212213
channel: 'end',
213214
context: {
214215
schema,
216+
document,
215217
operation,
216218
variableValues,
217219
operationName: 'S',
@@ -223,6 +225,7 @@ describe('subscribe diagnostics channel', () => {
223225
channel: 'start',
224226
context: {
225227
schema,
228+
document,
226229
operation,
227230
variableValues,
228231
operationName: 'S',
@@ -233,6 +236,7 @@ describe('subscribe diagnostics channel', () => {
233236
channel: 'end',
234237
context: {
235238
schema,
239+
document,
236240
operation,
237241
variableValues,
238242
operationName: 'S',
@@ -298,6 +302,7 @@ describe('subscribe diagnostics channel', () => {
298302
channel: 'start',
299303
context: {
300304
schema,
305+
document,
301306
operation,
302307
variableValues,
303308
operationName: 'S',
@@ -308,6 +313,7 @@ describe('subscribe diagnostics channel', () => {
308313
channel: 'end',
309314
context: {
310315
schema,
316+
document,
311317
operation,
312318
variableValues,
313319
operationName: 'S',
@@ -319,6 +325,7 @@ describe('subscribe diagnostics channel', () => {
319325
channel: 'start',
320326
context: {
321327
schema,
328+
document,
322329
operation,
323330
variableValues,
324331
operationName: 'S',
@@ -329,6 +336,7 @@ describe('subscribe diagnostics channel', () => {
329336
channel: 'end',
330337
context: {
331338
schema,
339+
document,
332340
operation,
333341
variableValues,
334342
operationName: 'S',

src/execution/execute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ export function validateExecutionArgs(
822822

823823
return {
824824
schema,
825+
document,
825826
fragmentDefinitions,
826827
fragments,
827828
rootValue,

0 commit comments

Comments
 (0)