Skip to content

Commit f8e2f96

Browse files
authored
fix: FragmentVariableValueSource.value can be non-constant (#4773)
i.e. it can be another variable or have an embedded variable, I.e of type ValueNode not ConstValueNode.
1 parent 64e7c68 commit f8e2f96

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

src/execution/collectFields.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { AccumulatorMap } from '../jsutils/AccumulatorMap.ts';
22
import type { ObjMap, ReadOnlyObjMap } from '../jsutils/ObjMap.ts';
33

44
import type {
5-
ConstValueNode,
65
DirectiveNode,
76
FieldNode,
87
FragmentDefinitionNode,
98
FragmentSpreadNode,
109
InlineFragmentNode,
1110
SelectionSetNode,
11+
ValueNode,
1212
} from '../language/ast.ts';
1313
import { Kind } from '../language/kinds.ts';
1414

@@ -43,9 +43,10 @@ export interface FragmentVariableValues {
4343
readonly coerced: ReadOnlyObjMap<unknown>;
4444
}
4545

46-
interface FragmentVariableValueSource {
46+
/** @internal */
47+
export interface FragmentVariableValueSource {
4748
readonly signature: GraphQLVariableSignature;
48-
readonly value?: ConstValueNode;
49+
readonly value?: ValueNode;
4950
readonly fragmentVariableValues?: FragmentVariableValues;
5051
}
5152

src/execution/values.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ import {
3838
validateInputValue,
3939
} from '../utilities/validateInputValue.ts';
4040

41-
import type { FragmentVariableValues } from './collectFields.ts';
41+
import type {
42+
FragmentVariableValues,
43+
FragmentVariableValueSource,
44+
} from './collectFields.ts';
4245
import type { GraphQLVariableSignature } from './getVariableSignature.ts';
4346
import { getVariableSignature } from './getVariableSignature.ts';
4447

@@ -306,17 +309,23 @@ export function getFragmentVariableValues(
306309
): FragmentVariableValues {
307310
const argumentNodes = fragmentSpreadNode.arguments ?? [];
308311
const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));
309-
const sources = Object.create(null);
310-
const coerced = Object.create(null);
312+
const sources: ObjMap<FragmentVariableValueSource> = Object.create(null);
313+
const coerced: ObjMap<unknown> = Object.create(null);
311314
for (const [varName, varSignature] of Object.entries(fragmentSignatures)) {
312-
sources[varName] = {
313-
signature: varSignature,
314-
};
315315
const argumentNode = argNodeMap.get(varName);
316316
if (argumentNode !== undefined) {
317-
const source = sources[varName];
318-
source.value = argumentNode.value;
319-
source.fragmentVariableValues = fragmentVariableValues;
317+
sources[varName] =
318+
fragmentVariableValues == null
319+
? { signature: varSignature, value: argumentNode.value }
320+
: {
321+
signature: varSignature,
322+
value: argumentNode.value,
323+
fragmentVariableValues,
324+
};
325+
} else {
326+
sources[varName] = {
327+
signature: varSignature,
328+
};
320329
}
321330

322331
coerceArgument(

0 commit comments

Comments
 (0)