Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Sep 15, 2024
1 parent 95d1d93 commit 15aa1e5
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/utilities/replaceVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,47 @@ export function replaceVariables(
return visit(valueNode, {
Variable(node) {
const varName = node.name.value;
const scopedVariableValues = fragmentVariableValues?.signatures[varName]
const scopedVariableValues = fragmentVariableValues?.sources[varName]
? fragmentVariableValues
: variableValues;

if (scopedVariableValues == null) {
return { kind: Kind.NULL };
}

if (scopedVariableValues.sources[varName] === undefined) {
const defaultValue =
scopedVariableValues.signatures[varName]?.defaultValue;
const scopedVariableSource = scopedVariableValues.sources[varName];
if (scopedVariableSource.value === undefined) {
const defaultValue = scopedVariableSource.signature.defaultValue;
if (defaultValue !== undefined) {
return defaultValue.literal;
}
}

return valueToLiteral(
scopedVariableValues.sources[varName],
scopedVariableValues?.signature.type,
scopedVariableSource.value,
scopedVariableSource.signature.type,
);
},
ObjectValue(node) {
return {
...node,
// Filter out any fields with a missing variable.
fields: node.fields.filter(
(field) =>
(field.value.kind !== Kind.VARIABLE ||
fragmentVariableValues?.sources[field.value.name.value]) ??
variableValues?.sources[field.value.name.value],
),
fields: node.fields.filter((field) => {
if (field.value.kind !== Kind.VARIABLE) {
return true;
}
const scopedVariableSource =
fragmentVariableValues?.sources[field.value.name.value] ??
variableValues?.sources[field.value.name.value];

if (
scopedVariableSource?.value === undefined &&
scopedVariableSource?.signature.defaultValue === undefined
) {
return false;
}
return true;
}),
};
},
}) as ConstValueNode;
Expand Down

0 comments on commit 15aa1e5

Please sign in to comment.