@graphql-tools/wrap 9.2.0 → 9.2.1-alpha-20220914014300-5f0405ae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -59,26 +59,16 @@ class MapLeafValues {
|
|
|
59
59
|
}
|
|
60
60
|
transformOperations(operations, variableValues) {
|
|
61
61
|
return operations.map((operation) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
...prev,
|
|
65
|
-
[def.variable.name.value]: def,
|
|
66
|
-
}), {});
|
|
67
|
-
const newOperation = (0, graphql_1.visit)(operation, (0, graphql_1.visitWithTypeInfo)(this._getTypeInfo(), {
|
|
68
|
-
[graphql_1.Kind.FIELD]: node => this.transformFieldNode(node, variableDefinitionMap, variableValues),
|
|
62
|
+
return (0, graphql_1.visit)(operation, (0, graphql_1.visitWithTypeInfo)(this._getTypeInfo(), {
|
|
63
|
+
[graphql_1.Kind.FIELD]: node => this.transformFieldNode(node, variableValues),
|
|
69
64
|
}));
|
|
70
|
-
return {
|
|
71
|
-
...newOperation,
|
|
72
|
-
variableDefinitions: Object.values(variableDefinitionMap),
|
|
73
|
-
};
|
|
74
65
|
});
|
|
75
66
|
}
|
|
76
|
-
transformFieldNode(field,
|
|
67
|
+
transformFieldNode(field, variableValues) {
|
|
77
68
|
const targetField = this._getTypeInfo().getFieldDef();
|
|
78
69
|
if (!targetField) {
|
|
79
70
|
return;
|
|
80
71
|
}
|
|
81
|
-
const generateVariableName = (0, utils_1.createVariableNameGenerator)(variableDefinitionMap);
|
|
82
72
|
if (!targetField.name.startsWith('__')) {
|
|
83
73
|
const argumentNodes = field.arguments;
|
|
84
74
|
if (argumentNodes != null) {
|
|
@@ -94,11 +84,24 @@ class MapLeafValues {
|
|
|
94
84
|
let value;
|
|
95
85
|
if (argValue != null) {
|
|
96
86
|
value = (0, graphql_1.valueFromAST)(argValue, argType, variableValues);
|
|
87
|
+
if (value == null) {
|
|
88
|
+
value = (0, graphql_1.valueFromASTUntyped)(argValue, variableValues);
|
|
89
|
+
}
|
|
97
90
|
}
|
|
98
|
-
|
|
91
|
+
const transformedValue = (0, utils_1.transformInputValue)(argType, value, (t, v) => {
|
|
99
92
|
const newValue = this.inputValueTransformer(t.name, v);
|
|
100
93
|
return newValue === undefined ? v : newValue;
|
|
101
|
-
})
|
|
94
|
+
});
|
|
95
|
+
if (argValue.kind === graphql_1.Kind.VARIABLE) {
|
|
96
|
+
variableValues[argValue.name.value] = transformedValue;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const newValueNode = (0, graphql_1.astFromValue)(transformedValue, argType);
|
|
100
|
+
argumentNodeMap[argName] = {
|
|
101
|
+
...argumentNode,
|
|
102
|
+
value: newValueNode,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
102
105
|
}
|
|
103
106
|
return {
|
|
104
107
|
...field,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { visit, Kind, TypeInfo, visitWithTypeInfo, valueFromAST, isLeafType, } from 'graphql';
|
|
2
|
-
import { visitResult,
|
|
1
|
+
import { visit, Kind, TypeInfo, visitWithTypeInfo, valueFromAST, isLeafType, astFromValue, valueFromASTUntyped, } from 'graphql';
|
|
2
|
+
import { visitResult, transformInputValue, } from '@graphql-tools/utils';
|
|
3
3
|
export default class MapLeafValues {
|
|
4
4
|
constructor(inputValueTransformer, outputValueTransformer) {
|
|
5
5
|
this.inputValueTransformer = inputValueTransformer;
|
|
@@ -57,26 +57,16 @@ export default class MapLeafValues {
|
|
|
57
57
|
}
|
|
58
58
|
transformOperations(operations, variableValues) {
|
|
59
59
|
return operations.map((operation) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...prev,
|
|
63
|
-
[def.variable.name.value]: def,
|
|
64
|
-
}), {});
|
|
65
|
-
const newOperation = visit(operation, visitWithTypeInfo(this._getTypeInfo(), {
|
|
66
|
-
[Kind.FIELD]: node => this.transformFieldNode(node, variableDefinitionMap, variableValues),
|
|
60
|
+
return visit(operation, visitWithTypeInfo(this._getTypeInfo(), {
|
|
61
|
+
[Kind.FIELD]: node => this.transformFieldNode(node, variableValues),
|
|
67
62
|
}));
|
|
68
|
-
return {
|
|
69
|
-
...newOperation,
|
|
70
|
-
variableDefinitions: Object.values(variableDefinitionMap),
|
|
71
|
-
};
|
|
72
63
|
});
|
|
73
64
|
}
|
|
74
|
-
transformFieldNode(field,
|
|
65
|
+
transformFieldNode(field, variableValues) {
|
|
75
66
|
const targetField = this._getTypeInfo().getFieldDef();
|
|
76
67
|
if (!targetField) {
|
|
77
68
|
return;
|
|
78
69
|
}
|
|
79
|
-
const generateVariableName = createVariableNameGenerator(variableDefinitionMap);
|
|
80
70
|
if (!targetField.name.startsWith('__')) {
|
|
81
71
|
const argumentNodes = field.arguments;
|
|
82
72
|
if (argumentNodes != null) {
|
|
@@ -92,11 +82,24 @@ export default class MapLeafValues {
|
|
|
92
82
|
let value;
|
|
93
83
|
if (argValue != null) {
|
|
94
84
|
value = valueFromAST(argValue, argType, variableValues);
|
|
85
|
+
if (value == null) {
|
|
86
|
+
value = valueFromASTUntyped(argValue, variableValues);
|
|
87
|
+
}
|
|
95
88
|
}
|
|
96
|
-
|
|
89
|
+
const transformedValue = transformInputValue(argType, value, (t, v) => {
|
|
97
90
|
const newValue = this.inputValueTransformer(t.name, v);
|
|
98
91
|
return newValue === undefined ? v : newValue;
|
|
99
|
-
})
|
|
92
|
+
});
|
|
93
|
+
if (argValue.kind === Kind.VARIABLE) {
|
|
94
|
+
variableValues[argValue.name.value] = transformedValue;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const newValueNode = astFromValue(transformedValue, argType);
|
|
98
|
+
argumentNodeMap[argName] = {
|
|
99
|
+
...argumentNode,
|
|
100
|
+
value: newValueNode,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
100
103
|
}
|
|
101
104
|
return {
|
|
102
105
|
...field,
|