Skip to content

Commit 15aa1e5

Browse files
committed
f
1 parent 95d1d93 commit 15aa1e5

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/utilities/replaceVariables.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,47 @@ export function replaceVariables(
2424
return visit(valueNode, {
2525
Variable(node) {
2626
const varName = node.name.value;
27-
const scopedVariableValues = fragmentVariableValues?.signatures[varName]
27+
const scopedVariableValues = fragmentVariableValues?.sources[varName]
2828
? fragmentVariableValues
2929
: variableValues;
3030

3131
if (scopedVariableValues == null) {
3232
return { kind: Kind.NULL };
3333
}
3434

35-
if (scopedVariableValues.sources[varName] === undefined) {
36-
const defaultValue =
37-
scopedVariableValues.signatures[varName]?.defaultValue;
35+
const scopedVariableSource = scopedVariableValues.sources[varName];
36+
if (scopedVariableSource.value === undefined) {
37+
const defaultValue = scopedVariableSource.signature.defaultValue;
3838
if (defaultValue !== undefined) {
3939
return defaultValue.literal;
4040
}
4141
}
4242

4343
return valueToLiteral(
44-
scopedVariableValues.sources[varName],
45-
scopedVariableValues?.signature.type,
44+
scopedVariableSource.value,
45+
scopedVariableSource.signature.type,
4646
);
4747
},
4848
ObjectValue(node) {
4949
return {
5050
...node,
5151
// Filter out any fields with a missing variable.
52-
fields: node.fields.filter(
53-
(field) =>
54-
(field.value.kind !== Kind.VARIABLE ||
55-
fragmentVariableValues?.sources[field.value.name.value]) ??
56-
variableValues?.sources[field.value.name.value],
57-
),
52+
fields: node.fields.filter((field) => {
53+
if (field.value.kind !== Kind.VARIABLE) {
54+
return true;
55+
}
56+
const scopedVariableSource =
57+
fragmentVariableValues?.sources[field.value.name.value] ??
58+
variableValues?.sources[field.value.name.value];
59+
60+
if (
61+
scopedVariableSource?.value === undefined &&
62+
scopedVariableSource?.signature.defaultValue === undefined
63+
) {
64+
return false;
65+
}
66+
return true;
67+
}),
5868
};
5969
},
6070
}) as ConstValueNode;

0 commit comments

Comments
 (0)