Skip to content

Commit 0d3654a

Browse files
yaacovCRlogaretm
authored andcommitted
make sure variableValues in context for execution and subscription are the original passed values, not the internal type
1 parent 3e0c960 commit 0d3654a

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

src/execution/__tests__/diagnostics-test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ describe('execute diagnostics channel', () => {
5454
const executeChannel = getTracingChannel('graphql:execute');
5555

5656
it('emits start and end around a synchronous execute', async () => {
57-
const document = parse('query Q { sync }');
57+
const document = parse('query Q($sync: String) { sync }');
58+
const variableValues = { sync: 'ignored by the field' };
5859

5960
await expectEvents(
6061
executeChannel,
@@ -63,14 +64,15 @@ describe('execute diagnostics channel', () => {
6364
schema,
6465
document,
6566
rootValue: { sync: () => 'hello' },
67+
variableValues,
6668
}),
6769
(result) => [
6870
{
6971
channel: 'start',
7072
context: {
7173
document,
7274
schema,
73-
variableValues: undefined,
75+
variableValues,
7476
operationName: 'Q',
7577
operationType: 'query',
7678
},
@@ -80,7 +82,7 @@ describe('execute diagnostics channel', () => {
8082
context: {
8183
document,
8284
schema,
83-
variableValues: undefined,
85+
variableValues,
8486
operationName: 'Q',
8587
operationType: 'query',
8688
result,
@@ -370,9 +372,9 @@ describe('execute diagnostics channel', () => {
370372
yield { tick: 'two' };
371373
}
372374

373-
const document = parse('subscription S { tick }');
375+
const document = parse('subscription S($tick: String) { tick }');
374376
const operation = document.definitions[0];
375-
const variableValues = { coerced: {}, sources: {} };
377+
const variableValues = { tick: 'ignored by the field' };
376378

377379
await expectEvents(
378380
executeChannel,
@@ -381,6 +383,7 @@ describe('execute diagnostics channel', () => {
381383
schema,
382384
document,
383385
rootValue: { tick: tickGenerator },
386+
variableValues,
384387
});
385388
assert(isAsyncIterable(subscription));
386389

@@ -470,7 +473,8 @@ describe('subscribe diagnostics channel', () => {
470473
}
471474

472475
it('emits start and end for a synchronous subscription setup', async () => {
473-
const document = parse('subscription S { tick }');
476+
const document = parse('subscription S($tick: String) { tick }');
477+
const variableValues = { tick: 'ignored by the field' };
474478

475479
await expectEvents(
476480
subscribeChannel,
@@ -479,6 +483,7 @@ describe('subscribe diagnostics channel', () => {
479483
schema,
480484
document,
481485
rootValue: { tick: twoTicks },
486+
variableValues,
482487
});
483488
assert(isAsyncIterable(subscription));
484489

@@ -494,7 +499,7 @@ describe('subscribe diagnostics channel', () => {
494499
context: {
495500
document,
496501
schema,
497-
variableValues: undefined,
502+
variableValues,
498503
operationName: 'S',
499504
operationType: 'subscription',
500505
},
@@ -504,7 +509,7 @@ describe('subscribe diagnostics channel', () => {
504509
context: {
505510
document,
506511
schema,
507-
variableValues: undefined,
512+
variableValues,
508513
operationName: 'S',
509514
operationType: 'subscription',
510515
result,

src/execution/execute.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,27 @@ function buildExecuteCtxFromValidatedArgs(
772772
return {
773773
operation: args.operation,
774774
schema: args.schema,
775-
variableValues: args.variableValues,
775+
variableValues: getOriginalVariableValues(args),
776776
operationName: args.operation.name?.value,
777777
operationType: args.operation.operation,
778778
};
779779
}
780780

781+
function getOriginalVariableValues(
782+
args: ValidatedExecutionArgs,
783+
): Maybe<{ readonly [variable: string]: unknown }> {
784+
const originalVariableValues: { [variable: string]: unknown } = {};
785+
for (const [variableName, source] of Object.entries(
786+
args.variableValues.sources,
787+
)) {
788+
if (Object.hasOwn(source, 'value')) {
789+
originalVariableValues[variableName] = source.value;
790+
}
791+
}
792+
793+
return originalVariableValues;
794+
}
795+
781796
/**
782797
* TODO: consider no longer exporting this function
783798
* @internal

0 commit comments

Comments
 (0)