grafast 0.1.1-beta.2 → 0.1.1-beta.21
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.
- package/README.md +2 -3
- package/dist/args.d.ts +4 -7
- package/dist/args.js +53 -38
- package/dist/assert.js +2 -3
- package/dist/bucket.d.ts +1 -89
- package/dist/config.d.ts +0 -17
- package/dist/config.js +1 -95
- package/dist/constraints.d.ts +15 -1
- package/dist/constraints.js +41 -3
- package/dist/deferred.js +1 -2
- package/dist/dev.d.ts +1 -4
- package/dist/dev.js +18 -3
- package/dist/engine/LayerPlan.d.ts +21 -111
- package/dist/engine/LayerPlan.js +196 -78
- package/dist/engine/OperationPlan.d.ts +30 -104
- package/dist/engine/OperationPlan.js +763 -471
- package/dist/engine/OutputPlan.d.ts +9 -20
- package/dist/engine/OutputPlan.js +432 -444
- package/dist/engine/StepTracker.d.ts +1 -95
- package/dist/engine/StepTracker.js +94 -20
- package/dist/engine/executeBucket.d.ts +5 -7
- package/dist/engine/executeBucket.js +646 -244
- package/dist/engine/executeOutputPlan.d.ts +0 -53
- package/dist/engine/executeOutputPlan.js +7 -2
- package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
- package/dist/engine/lib/defaultPlanResolver.js +11 -0
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
- package/dist/engine/lock.d.ts +4 -0
- package/dist/engine/lock.js +82 -0
- package/dist/envelop.js +5 -4
- package/dist/error.d.ts +18 -49
- package/dist/error.js +50 -39
- package/dist/establishOperationPlan.js +57 -42
- package/dist/execute.d.ts +5 -4
- package/dist/execute.js +31 -15
- package/dist/exportAs.d.ts +1 -18
- package/dist/exportAs.js +2 -3
- package/dist/global.js +2 -3
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +35 -16
- package/dist/grafastPrint.d.ts +3 -0
- package/dist/grafastPrint.js +67 -6
- package/dist/graphqlCollectFields.d.ts +7 -34
- package/dist/graphqlCollectFields.js +24 -13
- package/dist/graphqlMergeSelectionSets.js +1 -2
- package/dist/index.d.ts +44 -29
- package/dist/index.js +91 -18
- package/dist/input.d.ts +1 -9
- package/dist/input.js +75 -28
- package/dist/inspect.d.ts +9 -3
- package/dist/inspect.js +3 -3
- package/dist/interfaces.d.ts +238 -93
- package/dist/interfaces.js +20 -3
- package/dist/makeGrafastSchema.d.ts +21 -9
- package/dist/makeGrafastSchema.js +353 -133
- package/dist/mermaid.d.ts +0 -17
- package/dist/mermaid.js +131 -19
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +24 -0
- package/dist/multistep.d.ts +19 -0
- package/dist/multistep.js +54 -0
- package/dist/operationPlan-input.d.ts +5 -4
- package/dist/operationPlan-input.js +140 -368
- package/dist/planJSONInterfaces.d.ts +12 -2
- package/dist/polymorphic.js +4 -5
- package/dist/prepare.d.ts +1 -7
- package/dist/prepare.js +100 -74
- package/dist/step.d.ts +118 -172
- package/dist/step.js +262 -183
- package/dist/steps/__flag.d.ts +65 -0
- package/dist/steps/__flag.js +261 -0
- package/dist/steps/__inputDefault.d.ts +14 -0
- package/dist/steps/__inputDefault.js +48 -0
- package/dist/steps/__inputDynamicScalar.d.ts +4 -6
- package/dist/steps/__inputDynamicScalar.js +4 -2
- package/dist/steps/__inputList.d.ts +5 -9
- package/dist/steps/__inputList.js +4 -1
- package/dist/steps/__inputObject.d.ts +7 -11
- package/dist/steps/__inputObject.js +49 -3
- package/dist/steps/__inputStaticLeaf.d.ts +2 -4
- package/dist/steps/__inputStaticLeaf.js +3 -1
- package/dist/steps/__item.d.ts +10 -12
- package/dist/steps/__item.js +8 -2
- package/dist/steps/__trackedValue.d.ts +7 -55
- package/dist/steps/__trackedValue.js +69 -8
- package/dist/steps/__value.d.ts +5 -4
- package/dist/steps/__value.js +5 -4
- package/dist/steps/access.d.ts +10 -10
- package/dist/steps/access.js +50 -17
- package/dist/steps/applyInput.d.ts +44 -0
- package/dist/steps/applyInput.js +206 -0
- package/dist/steps/applyTransforms.d.ts +2 -25
- package/dist/steps/applyTransforms.js +53 -31
- package/dist/steps/bakedInput.d.ts +23 -0
- package/dist/steps/bakedInput.js +90 -0
- package/dist/steps/condition.d.ts +31 -0
- package/dist/steps/condition.js +94 -0
- package/dist/steps/connection.d.ts +56 -42
- package/dist/steps/connection.js +97 -44
- package/dist/steps/constant.d.ts +7 -7
- package/dist/steps/constant.js +86 -7
- package/dist/steps/each.d.ts +3 -3
- package/dist/steps/each.js +2 -3
- package/dist/steps/error.d.ts +4 -4
- package/dist/steps/error.js +7 -6
- package/dist/steps/filter.d.ts +3 -2
- package/dist/steps/filter.js +1 -2
- package/dist/steps/first.d.ts +10 -9
- package/dist/steps/first.js +9 -13
- package/dist/steps/graphqlResolver.d.ts +3 -76
- package/dist/steps/graphqlResolver.js +89 -72
- package/dist/steps/groupBy.d.ts +3 -2
- package/dist/steps/groupBy.js +1 -2
- package/dist/steps/index.d.ts +12 -3
- package/dist/steps/index.js +48 -6
- package/dist/steps/lambda.d.ts +9 -9
- package/dist/steps/lambda.js +18 -9
- package/dist/steps/last.d.ts +9 -8
- package/dist/steps/last.js +7 -6
- package/dist/steps/list.d.ts +20 -9
- package/dist/steps/list.js +56 -13
- package/dist/steps/listTransform.d.ts +18 -22
- package/dist/steps/listTransform.js +58 -27
- package/dist/steps/listen.d.ts +6 -11
- package/dist/steps/listen.js +14 -16
- package/dist/steps/load.d.ts +42 -33
- package/dist/steps/load.js +60 -27
- package/dist/steps/node.d.ts +17 -10
- package/dist/steps/node.js +18 -6
- package/dist/steps/object.d.ts +33 -27
- package/dist/steps/object.js +53 -32
- package/dist/steps/partitionByIndex.d.ts +3 -2
- package/dist/steps/partitionByIndex.js +1 -2
- package/dist/steps/polymorphicBranch.d.ts +27 -0
- package/dist/steps/polymorphicBranch.js +62 -0
- package/dist/steps/proxy.d.ts +11 -12
- package/dist/steps/proxy.js +8 -5
- package/dist/steps/remapKeys.d.ts +10 -10
- package/dist/steps/remapKeys.js +14 -7
- package/dist/steps/reverse.d.ts +8 -8
- package/dist/steps/reverse.js +10 -7
- package/dist/steps/setter.d.ts +9 -18
- package/dist/steps/setter.js +24 -14
- package/dist/steps/sideEffect.d.ts +28 -0
- package/dist/steps/sideEffect.js +44 -0
- package/dist/stringifyPayload.js +1 -2
- package/dist/stripAnsi.js +2 -2
- package/dist/subscribe.d.ts +7 -1
- package/dist/subscribe.js +24 -9
- package/dist/thereCanBeOnlyOne.js +1 -1
- package/dist/timeSource.d.ts +0 -1
- package/dist/utils.d.ts +56 -55
- package/dist/utils.js +179 -59
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -8
package/dist/input.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.assertInputStep = assertInputStep;
|
|
4
|
+
exports.graphqlGetTypeForNode = graphqlGetTypeForNode;
|
|
5
|
+
exports.inputStep = inputStep;
|
|
4
6
|
const tslib_1 = require("tslib");
|
|
5
7
|
const graphql = tslib_1.__importStar(require("graphql"));
|
|
6
8
|
const inspect_js_1 = require("./inspect.js");
|
|
9
|
+
const __inputDefault_js_1 = require("./steps/__inputDefault.js");
|
|
7
10
|
const __inputDynamicScalar_js_1 = require("./steps/__inputDynamicScalar.js");
|
|
8
11
|
const __inputObject_js_1 = require("./steps/__inputObject.js");
|
|
9
12
|
const index_js_1 = require("./steps/index.js");
|
|
13
|
+
const utils_js_1 = require("./utils.js");
|
|
10
14
|
const { assertScalarType, GraphQLError, GraphQLList, GraphQLNonNull, isInputType, isLeafType, isInputObjectType, Kind, } = graphql;
|
|
11
15
|
function assertInputStep(itemPlan) {
|
|
12
16
|
if (itemPlan instanceof index_js_1.__TrackedValueStep)
|
|
@@ -19,7 +23,6 @@ function assertInputStep(itemPlan) {
|
|
|
19
23
|
return;
|
|
20
24
|
throw new Error(`Expected an InputStep, but found ${itemPlan}`);
|
|
21
25
|
}
|
|
22
|
-
exports.assertInputStep = assertInputStep;
|
|
23
26
|
function graphqlGetTypeForNode(operationPlan, node) {
|
|
24
27
|
switch (node.kind) {
|
|
25
28
|
case Kind.NAMED_TYPE: {
|
|
@@ -41,7 +44,6 @@ function graphqlGetTypeForNode(operationPlan, node) {
|
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
exports.graphqlGetTypeForNode = graphqlGetTypeForNode;
|
|
45
47
|
/**
|
|
46
48
|
* Returns a plan for the given `rawInputValue` AST node which could be a
|
|
47
49
|
* variable or a literal, and could be nested so that a variable (or more than
|
|
@@ -49,14 +51,21 @@ exports.graphqlGetTypeForNode = graphqlGetTypeForNode;
|
|
|
49
51
|
*
|
|
50
52
|
* @internal
|
|
51
53
|
*/
|
|
52
|
-
function inputStep(operationPlan, inputType,
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
54
|
+
function inputStep(operationPlan, inputType, inputValue, defaultValue = undefined) {
|
|
55
|
+
const { valueNodeToStaticValueCache } = operationPlan;
|
|
56
|
+
if (inputValue === undefined) {
|
|
57
|
+
// Definitely can't be or contain a variable!
|
|
58
|
+
if (defaultValue === undefined) {
|
|
59
|
+
return (0, index_js_1.constant)(undefined);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return valueNodeToCachedStaticValueConstantStep(valueNodeToStaticValueCache, defaultValue, inputType);
|
|
63
|
+
}
|
|
56
64
|
}
|
|
57
65
|
const isObj = isInputObjectType(inputType);
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
if (inputValue.kind === "Variable") {
|
|
67
|
+
// Note: this is the only other place where `defaultValue` might be used
|
|
68
|
+
// we know `inputValue` is not a variable.
|
|
60
69
|
const variableName = inputValue.name.value;
|
|
61
70
|
const variableDefinition = operationPlan.operation.variableDefinitions?.find((def) => def.variable.name.value === variableName);
|
|
62
71
|
if (!variableDefinition) {
|
|
@@ -68,17 +77,27 @@ function inputStep(operationPlan, inputType, rawInputValue, defaultValue = undef
|
|
|
68
77
|
if (!isInputType(variableType)) {
|
|
69
78
|
throw new Error(`Expected varible type to be an input type`);
|
|
70
79
|
}
|
|
71
|
-
|
|
80
|
+
const variableWillDefinitelyBeSet = variableType instanceof GraphQLNonNull ||
|
|
81
|
+
variableDefinition.defaultValue != null;
|
|
82
|
+
return inputVariablePlan(operationPlan, variableName, variableType, inputType, defaultValue, variableWillDefinitelyBeSet);
|
|
72
83
|
}
|
|
73
|
-
|
|
74
|
-
// we know `inputValue` is not a variable.
|
|
75
|
-
inputValue = inputValue ?? defaultValue;
|
|
76
|
-
if (inputType instanceof GraphQLNonNull) {
|
|
84
|
+
else if (inputType instanceof GraphQLNonNull) {
|
|
77
85
|
const innerType = inputType.ofType;
|
|
86
|
+
if (inputValue.kind === Kind.NULL) {
|
|
87
|
+
throw new Error(`Null found in non-null position; this should have been prevented by validation.`);
|
|
88
|
+
}
|
|
78
89
|
const valuePlan = inputStep(operationPlan, innerType, inputValue, undefined);
|
|
79
90
|
return inputNonNullPlan(operationPlan, valuePlan);
|
|
80
91
|
}
|
|
92
|
+
else if (inputValue.kind === Kind.NULL) {
|
|
93
|
+
return (0, index_js_1.constant)(null);
|
|
94
|
+
}
|
|
81
95
|
else if (inputType instanceof GraphQLList) {
|
|
96
|
+
const variableNames = new Set();
|
|
97
|
+
(0, utils_js_1.findVariableNamesUsedInValueNode)(inputValue, variableNames);
|
|
98
|
+
if (variableNames.size === 0) {
|
|
99
|
+
return valueNodeToCachedStaticValueConstantStep(valueNodeToStaticValueCache, inputValue, inputType);
|
|
100
|
+
}
|
|
82
101
|
return new index_js_1.__InputListStep(inputType, inputValue);
|
|
83
102
|
}
|
|
84
103
|
else if (isLeafType(inputType)) {
|
|
@@ -100,7 +119,6 @@ function inputStep(operationPlan, inputType, rawInputValue, defaultValue = undef
|
|
|
100
119
|
throw new Error(`Unsupported type in inputPlan: '${(0, inspect_js_1.inspect)(never)}'`);
|
|
101
120
|
}
|
|
102
121
|
}
|
|
103
|
-
exports.inputStep = inputStep;
|
|
104
122
|
function doTypesMatch(variableType, expectedType) {
|
|
105
123
|
if (variableType instanceof GraphQLNonNull &&
|
|
106
124
|
expectedType instanceof GraphQLNonNull) {
|
|
@@ -118,36 +136,57 @@ function doTypesMatch(variableType, expectedType) {
|
|
|
118
136
|
return variableType === expectedType;
|
|
119
137
|
}
|
|
120
138
|
}
|
|
121
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Returns a step representing a variable's value.
|
|
141
|
+
*
|
|
142
|
+
* @param operationPlan -
|
|
143
|
+
* @param variableName -
|
|
144
|
+
* @param variableType -
|
|
145
|
+
* @param inputType -
|
|
146
|
+
* @param defaultValue -
|
|
147
|
+
* @param variableWillDefinitelyBeSet - If `true` the variable is either
|
|
148
|
+
* non-null _or_ it has a default value (including null). In this case, the
|
|
149
|
+
* variable will never be `undefined` and thus an input position's defaultValue
|
|
150
|
+
* will never be invoked where it is used.
|
|
151
|
+
*/
|
|
152
|
+
function inputVariablePlan(operationPlan, variableName, variableType, inputType, defaultValue, variableWillDefinitelyBeSet) {
|
|
122
153
|
if (variableType instanceof GraphQLNonNull &&
|
|
123
154
|
!(inputType instanceof GraphQLNonNull)) {
|
|
124
155
|
const unwrappedVariableType = variableType.ofType;
|
|
125
|
-
return inputVariablePlan(operationPlan, variableName, unwrappedVariableType, inputType, defaultValue);
|
|
156
|
+
return inputVariablePlan(operationPlan, variableName, unwrappedVariableType, inputType, defaultValue, variableWillDefinitelyBeSet);
|
|
126
157
|
}
|
|
127
158
|
const typesMatch = doTypesMatch(variableType, inputType);
|
|
128
159
|
if (!typesMatch) {
|
|
129
160
|
// REF: https://spec.graphql.org/draft/#IsVariableUsageAllowed()
|
|
130
161
|
if (inputType instanceof GraphQLNonNull &&
|
|
131
162
|
!(variableType instanceof GraphQLNonNull)) {
|
|
132
|
-
const variablePlan = inputVariablePlan(operationPlan, variableName, variableType, inputType.ofType, defaultValue);
|
|
133
|
-
|
|
163
|
+
const variablePlan = inputVariablePlan(operationPlan, variableName, variableType, inputType.ofType, defaultValue, variableWillDefinitelyBeSet);
|
|
164
|
+
// TODO: find a way to do this without doing eval. For example: track list of variables that may not be nullish.
|
|
165
|
+
if (variablePlan.evalIs(null) ||
|
|
166
|
+
(!variableWillDefinitelyBeSet && variablePlan.evalIs(undefined))) {
|
|
134
167
|
throw new GraphQLError(`Expected non-null value of type ${inputType.ofType.toString()}`);
|
|
135
168
|
}
|
|
136
169
|
return variablePlan;
|
|
137
170
|
}
|
|
138
171
|
throw new Error("Expected variable and input types to match");
|
|
139
172
|
}
|
|
140
|
-
const
|
|
141
|
-
if (defaultValue === undefined
|
|
142
|
-
// There's no default value
|
|
143
|
-
|
|
144
|
-
|
|
173
|
+
const $variableValue = operationPlan.trackedVariableValuesStep.get(variableName);
|
|
174
|
+
if (defaultValue === undefined) {
|
|
175
|
+
// There's no default value and thus the default will not be used; use the variable.
|
|
176
|
+
return $variableValue;
|
|
177
|
+
}
|
|
178
|
+
else if (variableWillDefinitelyBeSet) {
|
|
179
|
+
// The variable will DEFINITELY be set (even if it is set to null, possibly
|
|
180
|
+
// by a default), so the input position's default value will never apply.
|
|
181
|
+
return $variableValue;
|
|
145
182
|
}
|
|
146
183
|
else {
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
|
|
184
|
+
// Here:
|
|
185
|
+
// - the variable is nullable, optional, and has no default value
|
|
186
|
+
// - the input position has a default value
|
|
187
|
+
// We thus need a step that results in `variableValue === undefined ? defaultValue : variableValue`
|
|
188
|
+
const runtimeDefaultValue = (0, utils_js_1.valueNodeToStaticValue)(defaultValue, inputType);
|
|
189
|
+
return new __inputDefault_js_1.__InputDefaultStep($variableValue, runtimeDefaultValue);
|
|
151
190
|
}
|
|
152
191
|
}
|
|
153
192
|
/**
|
|
@@ -156,4 +195,12 @@ function inputVariablePlan(operationPlan, variableName, variableType, inputType,
|
|
|
156
195
|
function inputNonNullPlan(_operationPlan, innerPlan) {
|
|
157
196
|
return innerPlan;
|
|
158
197
|
}
|
|
198
|
+
function valueNodeToCachedStaticValueConstantStep(cache, valueNode, inputType) {
|
|
199
|
+
let step = cache.get(valueNode);
|
|
200
|
+
if (!step) {
|
|
201
|
+
step = (0, index_js_1.constant)((0, utils_js_1.valueNodeToStaticValue)(valueNode, inputType), false);
|
|
202
|
+
cache.set(valueNode, step);
|
|
203
|
+
}
|
|
204
|
+
return step;
|
|
205
|
+
}
|
|
159
206
|
//# sourceMappingURL=input.js.map
|
package/dist/inspect.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export declare let inspect:
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare let inspect: {
|
|
2
|
+
(obj: any, options?: {
|
|
3
|
+
colors?: boolean;
|
|
4
|
+
depth?: number;
|
|
5
|
+
compact?: boolean | number;
|
|
6
|
+
breakLength?: number;
|
|
7
|
+
}): string;
|
|
8
|
+
custom: symbol;
|
|
9
|
+
};
|
|
4
10
|
//# sourceMappingURL=inspect.d.ts.map
|
package/dist/inspect.js
CHANGED
|
@@ -8,13 +8,13 @@ try {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
catch {
|
|
11
|
-
exports.inspect = (obj) => {
|
|
11
|
+
exports.inspect = Object.assign((obj) => {
|
|
12
12
|
return Array.isArray(obj) ||
|
|
13
13
|
!obj ||
|
|
14
14
|
Object.getPrototypeOf(obj) === null ||
|
|
15
15
|
Object.getPrototypeOf(obj) === Object.prototype
|
|
16
|
-
? JSON.stringify(obj)
|
|
16
|
+
? String(JSON.stringify(obj))
|
|
17
17
|
: String(obj);
|
|
18
|
-
};
|
|
18
|
+
}, { custom: Symbol.for("nodejs.util.inspect.custom") });
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=inspect.js.map
|