@@ -24,37 +24,47 @@ export function replaceVariables(
24
24
return visit ( valueNode , {
25
25
Variable ( node ) {
26
26
const varName = node . name . value ;
27
- const scopedVariableValues = fragmentVariableValues ?. signatures [ varName ]
27
+ const scopedVariableValues = fragmentVariableValues ?. sources [ varName ]
28
28
? fragmentVariableValues
29
29
: variableValues ;
30
30
31
31
if ( scopedVariableValues == null ) {
32
32
return { kind : Kind . NULL } ;
33
33
}
34
34
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 ;
38
38
if ( defaultValue !== undefined ) {
39
39
return defaultValue . literal ;
40
40
}
41
41
}
42
42
43
43
return valueToLiteral (
44
- scopedVariableValues . sources [ varName ] ,
45
- scopedVariableValues ? .signature . type ,
44
+ scopedVariableSource . value ,
45
+ scopedVariableSource . signature . type ,
46
46
) ;
47
47
} ,
48
48
ObjectValue ( node ) {
49
49
return {
50
50
...node ,
51
51
// 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
+ } ) ,
58
68
} ;
59
69
} ,
60
70
} ) as ConstValueNode ;
0 commit comments