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
|
@@ -1,26 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withFieldArgsForArguments =
|
|
3
|
+
exports.withFieldArgsForArguments = withFieldArgsForArguments;
|
|
4
|
+
exports.getNullableInputTypeAtPath = getNullableInputTypeAtPath;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const graphql = tslib_1.__importStar(require("graphql"));
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const { getNullableType,
|
|
10
|
-
function
|
|
7
|
+
const index_js_1 = require("./index.js");
|
|
8
|
+
const inspect_js_1 = require("./inspect.js");
|
|
9
|
+
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const { getNullableType, isInputObjectType, isListType } = graphql;
|
|
11
|
+
function assertNotRuntime(operationPlan, description) {
|
|
12
|
+
if (operationPlan.phase === "ready") {
|
|
13
|
+
throw new Error(`${description} may only be called at planning time; however you have code that has attempted to call it during execution time. Please revisit your plan resolvers to locate the issue.`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function withFieldArgsForArguments(operationPlan, $all, field, $parent, applyAfterMode, coordinate, callback) {
|
|
11
17
|
if (operationPlan.loc !== null)
|
|
12
18
|
operationPlan.loc.push(`withFieldArgsForArguments(${field.name})`);
|
|
13
|
-
const schema = operationPlan.schema;
|
|
14
19
|
const args = Object.create(null);
|
|
15
20
|
for (const arg of field.args) {
|
|
16
21
|
args[arg.name] = arg;
|
|
17
22
|
}
|
|
18
|
-
const got = new Map();
|
|
19
23
|
const applied = new Map();
|
|
20
24
|
let explicitlyApplied = false;
|
|
21
25
|
const fieldArgs = {
|
|
22
|
-
|
|
26
|
+
typeAt(path) {
|
|
23
27
|
if (typeof path === "string") {
|
|
28
|
+
return args[path].type;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (path.length === 0) {
|
|
32
|
+
throw new Error(`typeAt can only be used with a non-empty path since arguments themselves don't belong to a type but a field.`);
|
|
33
|
+
}
|
|
34
|
+
const argName = path[0];
|
|
35
|
+
let type = args[argName]?.type;
|
|
36
|
+
if (!type) {
|
|
37
|
+
throw new Error(`Argument ${argName} does not exist`);
|
|
38
|
+
}
|
|
39
|
+
for (let i = 1, l = path.length; i < l; i++) {
|
|
40
|
+
const segment = path[i];
|
|
41
|
+
type = graphql.isNonNullType(type) ? type.ofType : type;
|
|
42
|
+
if (typeof segment === "number") {
|
|
43
|
+
if (!isListType(type)) {
|
|
44
|
+
throw new Error(`Invalid path ${path.slice(1)} within argument ${argName}; expected a list at path index ${i - 1}`);
|
|
45
|
+
}
|
|
46
|
+
type = type.ofType;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (!isInputObjectType(type)) {
|
|
50
|
+
throw new Error(`Invalid path ${path.slice(1)} within argument ${argName}; expected an object at path index ${i - 1}`);
|
|
51
|
+
}
|
|
52
|
+
const arg = type.getFields()[segment];
|
|
53
|
+
if (!arg) {
|
|
54
|
+
throw new Error(`Invalid path ${path.slice(1)} within argument ${argName}; ${type} does not have a field '${segment}'`);
|
|
55
|
+
}
|
|
56
|
+
type = arg.type;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return type;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
getRaw(path) {
|
|
63
|
+
assertNotRuntime(operationPlan, `fieldArgs.getRaw()`);
|
|
64
|
+
if (path === undefined) {
|
|
65
|
+
return (0, index_js_1.object)(Object.fromEntries(Object.keys(args).map((argName) => [argName, $all.get(argName)])));
|
|
66
|
+
}
|
|
67
|
+
else if (typeof path === "string") {
|
|
24
68
|
return $all.get(path);
|
|
25
69
|
}
|
|
26
70
|
else if (Array.isArray(path)) {
|
|
@@ -43,187 +87,47 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
|
|
|
43
87
|
return $entry;
|
|
44
88
|
}
|
|
45
89
|
else {
|
|
46
|
-
throw new Error(`Invalid path`);
|
|
90
|
+
throw new Error(`Invalid path passed to FieldArgs.getRaw(); please check your code. Path: ${(0, inspect_js_1.inspect)(path)}`);
|
|
47
91
|
}
|
|
48
92
|
},
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
?
|
|
52
|
-
:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if ($existing) {
|
|
58
|
-
return $existing;
|
|
59
|
-
}
|
|
60
|
-
if (path.length === 0) {
|
|
61
|
-
const values = Object.create(null);
|
|
62
|
-
for (const argName of Object.keys(args)) {
|
|
63
|
-
values[argName] = fieldArgs.get([argName]);
|
|
64
|
-
}
|
|
65
|
-
return (0, object_js_1.object)(values);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const [argName, ...rest] = path;
|
|
69
|
-
if (typeof argName !== "string") {
|
|
70
|
-
throw new Error(`Invalid path; argument '${argName}' is an invalid argument name`);
|
|
71
|
-
}
|
|
72
|
-
let entity = args[argName];
|
|
73
|
-
if (!entity) {
|
|
74
|
-
throw new Error(`Invalid path; argument '${argName}' does not exist`);
|
|
75
|
-
}
|
|
76
|
-
let entityType = entity.type;
|
|
77
|
-
let $val = $all.get(argName);
|
|
78
|
-
for (const pathSegment of rest) {
|
|
79
|
-
const nullableType = getNullableType(entityType);
|
|
80
|
-
if (typeof pathSegment === "string" &&
|
|
81
|
-
isInputObjectType(nullableType)) {
|
|
82
|
-
entity = nullableType.getFields()[pathSegment];
|
|
83
|
-
entityType = entity.type;
|
|
84
|
-
if ("get" in $val) {
|
|
85
|
-
$val = $val.get(pathSegment);
|
|
86
|
-
}
|
|
87
|
-
else if ($val instanceof constant_js_1.ConstantStep && $val.isUndefined()) {
|
|
88
|
-
$val = (0, constant_js_1.constant)(undefined);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
throw new Error(`GrafastInternalError<b9e9a57a-bbdd-486c-bdcf-25cf99bf0243>: Processing input object type, but '${$val}' has no .get() method.`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (typeof pathSegment === "number" &&
|
|
95
|
-
isListType(nullableType)) {
|
|
96
|
-
entity = null;
|
|
97
|
-
entityType = nullableType.ofType;
|
|
98
|
-
if ("at" in $val) {
|
|
99
|
-
$val = $val.at(pathSegment);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
throw new Error(`GrafastInternalError<0abe76fa-c87a-4477-aebd-feffef848c2b>: Processing input object type, but '${$val}' has no .get() method.`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
throw new Error(`Asked to navigate ('get' mode) to position '${pathSegment}' (${typeof pathSegment}) (in path '${path.join(".")}') for incompatible type '${nullableType}' (${nullableType.constructor.name})`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
let result;
|
|
110
|
-
const childFieldArgs = getFieldArgsForPath(path, entityType, $val, "input");
|
|
111
|
-
if (rest.length === 0) {
|
|
112
|
-
// Argument
|
|
113
|
-
const arg = entity;
|
|
114
|
-
result = arg.extensions.grafast?.inputPlan
|
|
115
|
-
? arg.extensions.grafast.inputPlan($parent, childFieldArgs, {
|
|
116
|
-
schema,
|
|
117
|
-
entity: arg,
|
|
118
|
-
})
|
|
119
|
-
: childFieldArgs.get();
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
// Input field
|
|
123
|
-
const inputField = entity;
|
|
124
|
-
result = inputField?.extensions.grafast?.inputPlan
|
|
125
|
-
? inputField.extensions.grafast.inputPlan(childFieldArgs, {
|
|
126
|
-
schema,
|
|
127
|
-
entity: inputField,
|
|
128
|
-
})
|
|
129
|
-
: childFieldArgs.get();
|
|
130
|
-
}
|
|
131
|
-
const nullableType = getNullableType(entityType);
|
|
132
|
-
if (isInputObjectType(nullableType)) {
|
|
133
|
-
processAfter(fieldArgs, path, result, nullableType.getFields(), "autoApplyAfterParentInputPlan");
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
apply(targetStepOrCallback, inPath) {
|
|
93
|
+
apply($target, inPathOrGetTargetFromParent, maybeGetTargetFromParent) {
|
|
94
|
+
const inPath = typeof inPathOrGetTargetFromParent === "function"
|
|
95
|
+
? undefined
|
|
96
|
+
: inPathOrGetTargetFromParent;
|
|
97
|
+
const getTargetFromParent = typeof inPathOrGetTargetFromParent === "function"
|
|
98
|
+
? inPathOrGetTargetFromParent
|
|
99
|
+
: maybeGetTargetFromParent;
|
|
100
|
+
assertNotRuntime(operationPlan, `fieldArgs.apply()`);
|
|
139
101
|
const path = Array.isArray(inPath) ? inPath : inPath ? [inPath] : [];
|
|
140
102
|
const pathString = path.join(".");
|
|
141
103
|
const $existing = applied.get(pathString);
|
|
142
104
|
if ($existing) {
|
|
143
|
-
throw new Error(`Attempted to apply 'applyPlan' at input path ${pathString} more than once - first time to ${$existing}, second time to ${
|
|
105
|
+
throw new Error(`Attempted to apply 'applyPlan' at input path ${pathString} more than once - first time to ${$existing}, second time to ${$target}. Multiple applications are not currently supported.`);
|
|
144
106
|
}
|
|
145
107
|
if (path.length === 0) {
|
|
146
108
|
explicitlyApplied = true;
|
|
147
109
|
// Auto-apply all the arguments
|
|
148
110
|
for (const argName of Object.keys(args)) {
|
|
149
|
-
const $target = typeof targetStepOrCallback === "function"
|
|
150
|
-
? targetStepOrCallback()
|
|
151
|
-
: targetStepOrCallback;
|
|
152
111
|
fieldArgs.apply($target, [argName]);
|
|
153
112
|
}
|
|
154
113
|
}
|
|
155
114
|
else {
|
|
156
115
|
const [argName, ...rest] = path;
|
|
157
|
-
|
|
158
|
-
|
|
116
|
+
if (typeof argName !== "string") {
|
|
117
|
+
throw new Error(`Invalid path; argument '${argName}' is an invalid argument name`);
|
|
118
|
+
}
|
|
119
|
+
const arg = args[argName];
|
|
120
|
+
if (!arg) {
|
|
159
121
|
throw new Error(`Invalid path; argument '${argName}' does not exist`);
|
|
160
122
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
entity = nullableType.getFields()[pathSegment];
|
|
167
|
-
entityType = entity.type;
|
|
168
|
-
if ("get" in $val) {
|
|
169
|
-
$val = $val.get(pathSegment);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new Error(`GrafastInternalError<b9e9a57a-bbdd-486c-bdcf-25cf99bf0243>: Processing input object type, but '${$val}' has no .get() method.`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
else if (typeof pathSegment === "number" &&
|
|
176
|
-
isListType(nullableType)) {
|
|
177
|
-
entity = null;
|
|
178
|
-
entityType = nullableType.ofType;
|
|
179
|
-
if ("at" in $val) {
|
|
180
|
-
$val = $val.at(pathSegment);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
throw new Error(`GrafastInternalError<a097a130-f68f-4a5c-bd0c-24fcd26127a9>: Processing list type, but '${$val}' has no .at() method.`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
throw new Error(`Asked to navigate ('apply' mode) to position '${pathSegment}' (${typeof pathSegment}) (in path '${path.join(".")}') for incompatible type '${nullableType}' (${nullableType.constructor.name})`);
|
|
188
|
-
}
|
|
123
|
+
const typeAtPath = getNullableInputTypeAtPath(arg.type, rest);
|
|
124
|
+
const $valueAtPath = fieldArgs.getRaw(inPath);
|
|
125
|
+
if ($valueAtPath instanceof index_js_1.ConstantStep &&
|
|
126
|
+
$valueAtPath.data === undefined) {
|
|
127
|
+
// Skip applying!
|
|
189
128
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
operationPlan.withModifiers(() => {
|
|
193
|
-
let result;
|
|
194
|
-
const $target = typeof targetStepOrCallback === "function"
|
|
195
|
-
? targetStepOrCallback()
|
|
196
|
-
: targetStepOrCallback;
|
|
197
|
-
if (rest.length === 0) {
|
|
198
|
-
// Argument
|
|
199
|
-
const arg = entity;
|
|
200
|
-
result = arg.extensions.grafast?.applyPlan
|
|
201
|
-
? arg.extensions.grafast.applyPlan($parent, $target, childFieldArgs, {
|
|
202
|
-
schema,
|
|
203
|
-
entity: arg,
|
|
204
|
-
})
|
|
205
|
-
: undefined;
|
|
206
|
-
}
|
|
207
|
-
else if (entity) {
|
|
208
|
-
// input field
|
|
209
|
-
const inputField = entity;
|
|
210
|
-
result = inputField.extensions.grafast?.applyPlan
|
|
211
|
-
? inputField.extensions.grafast.applyPlan($target, childFieldArgs, {
|
|
212
|
-
schema,
|
|
213
|
-
entity: inputField,
|
|
214
|
-
})
|
|
215
|
-
: undefined;
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
childFieldArgs.apply($target);
|
|
219
|
-
// Shortcut 'processAfter'
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const nullableType = getNullableType(entityType);
|
|
223
|
-
if (isInputObjectType(nullableType)) {
|
|
224
|
-
processAfter(fieldArgs, path, result, nullableType.getFields(), "autoApplyAfterParentApplyPlan");
|
|
225
|
-
}
|
|
226
|
-
});
|
|
129
|
+
else {
|
|
130
|
+
$target.apply((0, index_js_1.applyInput)(typeAtPath, $valueAtPath, getTargetFromParent));
|
|
227
131
|
}
|
|
228
132
|
}
|
|
229
133
|
},
|
|
@@ -232,218 +136,86 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
|
|
|
232
136
|
let val;
|
|
233
137
|
Object.defineProperty(fieldArgs, `$${argName}`, {
|
|
234
138
|
get() {
|
|
235
|
-
|
|
236
|
-
val = fieldArgs.getRaw(argName);
|
|
237
|
-
}
|
|
238
|
-
return val;
|
|
139
|
+
return (val ??= fieldArgs.getRaw(argName));
|
|
239
140
|
},
|
|
240
141
|
});
|
|
241
142
|
}
|
|
242
|
-
function getFieldArgsForPath(path, entityType, $input, mode) {
|
|
243
|
-
const nullableEntityType = getNullableType(entityType);
|
|
244
|
-
const localFieldArgs = {
|
|
245
|
-
getRaw(subpath) {
|
|
246
|
-
return fieldArgs.getRaw(concatPath(path, subpath));
|
|
247
|
-
},
|
|
248
|
-
get(subpath) {
|
|
249
|
-
if (!subpath || (Array.isArray(subpath) && subpath.length === 0)) {
|
|
250
|
-
if (isListType(nullableEntityType)) {
|
|
251
|
-
if (!("evalLength" in $input)) {
|
|
252
|
-
throw new Error(`GrafastInternalError<6ef74af7-7be0-4117-870f-2ebabcf5161c>: Expected ${$input} to be a __InputListStep or __TrackedValueStep (i.e. to have 'evalLength')`);
|
|
253
|
-
}
|
|
254
|
-
const l = $input.evalLength();
|
|
255
|
-
if (l == null) {
|
|
256
|
-
return (0, constant_js_1.constant)(null);
|
|
257
|
-
}
|
|
258
|
-
const entries = [];
|
|
259
|
-
for (let i = 0; i < l; i++) {
|
|
260
|
-
const entry = fieldArgs.get([...path, i]);
|
|
261
|
-
entries.push(entry);
|
|
262
|
-
}
|
|
263
|
-
return (0, list_js_1.list)(entries);
|
|
264
|
-
}
|
|
265
|
-
else if (isInputObjectType(nullableEntityType)) {
|
|
266
|
-
const typeResolver = nullableEntityType.extensions.grafast?.inputPlan ||
|
|
267
|
-
defaultInputObjectTypeInputPlanResolver;
|
|
268
|
-
const resolvedResult = typeResolver(getFieldArgsForPath(path, nullableEntityType, $input, "input"), {
|
|
269
|
-
schema,
|
|
270
|
-
type: nullableEntityType,
|
|
271
|
-
});
|
|
272
|
-
if (mode === "apply") {
|
|
273
|
-
// NOTE: if mode === 'input' then `.get()` won't need a
|
|
274
|
-
// `processAfter` since that will already have been handled in
|
|
275
|
-
// the parent fieldArgs.
|
|
276
|
-
processAfter(fieldArgs, path, resolvedResult, nullableEntityType.getFields(), "autoApplyAfterParentInputPlan");
|
|
277
|
-
}
|
|
278
|
-
return resolvedResult;
|
|
279
|
-
}
|
|
280
|
-
else if (isScalarType(nullableEntityType)) {
|
|
281
|
-
const scalarResolver = nullableEntityType.extensions.grafast?.inputPlan;
|
|
282
|
-
if (scalarResolver !== undefined) {
|
|
283
|
-
return scalarResolver($input, {
|
|
284
|
-
schema,
|
|
285
|
-
type: nullableEntityType,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
return $input;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
else if (isEnumType(nullableEntityType)) {
|
|
293
|
-
/*
|
|
294
|
-
const enumResolver = nullableEntityType.extensions.grafast?.inputPlan;
|
|
295
|
-
if (enumResolver) {
|
|
296
|
-
return enumResolver($input, { schema, type: nullableEntityType });
|
|
297
|
-
} else {
|
|
298
|
-
return $input;
|
|
299
|
-
}
|
|
300
|
-
*/
|
|
301
|
-
return $input;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
throw new Error(`Call to fieldArgs.get() at input path '${path.join(".")}' must pass a non-empty subpath`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return fieldArgs.get(concatPath(path, subpath));
|
|
308
|
-
},
|
|
309
|
-
apply(targetStepOrCallback, subpath) {
|
|
310
|
-
if (mode === "apply" &&
|
|
311
|
-
(!subpath || (Array.isArray(subpath) && subpath.length === 0))) {
|
|
312
|
-
if (isInputObjectType(nullableEntityType)) {
|
|
313
|
-
for (const fieldName of Object.keys(nullableEntityType.getFields())) {
|
|
314
|
-
const $target = typeof targetStepOrCallback === "function"
|
|
315
|
-
? targetStepOrCallback()
|
|
316
|
-
: targetStepOrCallback;
|
|
317
|
-
fieldArgs.apply($target, [...path, fieldName]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else if (isListType(nullableEntityType)) {
|
|
321
|
-
if (!("evalLength" in $input)) {
|
|
322
|
-
throw new Error(`GrafastInternalError<6ef74af7-7be0-4117-870f-2ebabcf5161c>: Expected ${$input} to be a __InputListStep or __TrackedValueStep (i.e. to have 'evalLength')`);
|
|
323
|
-
}
|
|
324
|
-
const l = $input.evalLength();
|
|
325
|
-
if (l == null) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
// const innerType = nullableEntityType.ofType;
|
|
329
|
-
for (let i = 0; i < l; i++) {
|
|
330
|
-
const $target = typeof targetStepOrCallback === "function"
|
|
331
|
-
? targetStepOrCallback()
|
|
332
|
-
: targetStepOrCallback;
|
|
333
|
-
fieldArgs.apply($target, [...path, i]);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
else if (isScalarType(nullableEntityType)) {
|
|
337
|
-
// noop
|
|
338
|
-
}
|
|
339
|
-
else if (isEnumType(nullableEntityType)) {
|
|
340
|
-
// PERF: only do this if this enum type has values that have side effects
|
|
341
|
-
const value = $input.eval();
|
|
342
|
-
const enumValue = nullableEntityType
|
|
343
|
-
.getValues()
|
|
344
|
-
.find((v) => v.value === value);
|
|
345
|
-
const enumResolver = enumValue?.extensions.grafast?.applyPlan;
|
|
346
|
-
if (enumResolver !== undefined) {
|
|
347
|
-
const $target = typeof targetStepOrCallback === "function"
|
|
348
|
-
? targetStepOrCallback()
|
|
349
|
-
: targetStepOrCallback;
|
|
350
|
-
enumResolver($target);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
const never = nullableEntityType;
|
|
355
|
-
throw new Error(`Unhandled input type ${never}`);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
const $target = typeof targetStepOrCallback === "function"
|
|
360
|
-
? targetStepOrCallback()
|
|
361
|
-
: targetStepOrCallback;
|
|
362
|
-
fieldArgs.apply($target, concatPath(path, subpath));
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
if (isInputObjectType(nullableEntityType)) {
|
|
367
|
-
const inputFields = nullableEntityType.getFields();
|
|
368
|
-
for (const fieldName of Object.keys(inputFields)) {
|
|
369
|
-
let val;
|
|
370
|
-
Object.defineProperty(localFieldArgs, `$${fieldName}`, {
|
|
371
|
-
enumerable: true,
|
|
372
|
-
get() {
|
|
373
|
-
if (!val) {
|
|
374
|
-
if ("get" in $input) {
|
|
375
|
-
val = $input.get(fieldName);
|
|
376
|
-
}
|
|
377
|
-
else if ($input instanceof constant_js_1.ConstantStep &&
|
|
378
|
-
$input.isUndefined()) {
|
|
379
|
-
val = (0, constant_js_1.constant)(undefined);
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
throw new Error(`GrafastInternalError<9b70d5c0-c45f-4acd-8b94-eaa02f87ad41>: expected '${$input}' to have a .get() method`);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return val;
|
|
386
|
-
},
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return localFieldArgs;
|
|
391
|
-
}
|
|
392
143
|
const result = callback(fieldArgs);
|
|
393
|
-
|
|
394
|
-
|
|
144
|
+
(0, utils_js_1.assertNotPromise)(result, callback, operationPlan.loc?.join(">") ?? "???");
|
|
145
|
+
if (!explicitlyApplied && result != null) {
|
|
146
|
+
processAfter($parent, fieldArgs, result, args, applyAfterMode, coordinate);
|
|
395
147
|
}
|
|
396
148
|
if (operationPlan.loc !== null)
|
|
397
149
|
operationPlan.loc.pop();
|
|
398
150
|
return (result ?? null);
|
|
399
151
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
152
|
+
function processAfter($parent, rootFieldArgs, $result, args, applyAfterMode, coordinate) {
|
|
153
|
+
const schema = $parent.operationPlan.schema;
|
|
154
|
+
for (const [argName, arg] of Object.entries(args)) {
|
|
155
|
+
const autoApply = applyAfterMode === "plan"
|
|
156
|
+
? arg.extensions.grafast?.applyPlan
|
|
157
|
+
: applyAfterMode === "subscribePlan"
|
|
158
|
+
? arg.extensions.grafast?.applySubscribePlan
|
|
159
|
+
: null;
|
|
160
|
+
if (autoApply) {
|
|
161
|
+
// TODO: should this have dollars on it for accessing subkeys?
|
|
162
|
+
const input = {
|
|
163
|
+
typeAt(path) {
|
|
164
|
+
return rootFieldArgs.typeAt(concatPath(argName, path));
|
|
165
|
+
},
|
|
166
|
+
getRaw(path) {
|
|
167
|
+
return rootFieldArgs.getRaw(concatPath(argName, path));
|
|
168
|
+
},
|
|
169
|
+
apply($target, pathOrTargetGetter, maybeTargetGetter) {
|
|
170
|
+
if (typeof pathOrTargetGetter === "function") {
|
|
171
|
+
return rootFieldArgs.apply($target, [argName], pathOrTargetGetter);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
return rootFieldArgs.apply($target, concatPath(argName, pathOrTargetGetter), maybeTargetGetter);
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const result = autoApply($parent, $result, input, {
|
|
179
|
+
schema,
|
|
180
|
+
arg,
|
|
181
|
+
argName,
|
|
182
|
+
});
|
|
183
|
+
if (result !== undefined) {
|
|
184
|
+
const fullCoordinate = `${coordinate}(${argName}:)`;
|
|
185
|
+
throw new Error(`Argument ${fullCoordinate}'s applyPlan returned a value. This may indicate a bug in that method, please see https://err.red/gaap#coord=${encodeURIComponent(fullCoordinate)}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function getNullableInputTypeAtPath(startType, path) {
|
|
191
|
+
let type = getNullableType(startType);
|
|
192
|
+
for (let i = 0, l = path.length; i < l; i++) {
|
|
193
|
+
const segment = path[i];
|
|
194
|
+
if (typeof segment === "number") {
|
|
195
|
+
// Expect list
|
|
196
|
+
if (!isListType(type)) {
|
|
197
|
+
throw new Error(`Invalid path passed to fieldArgs.get(); expected list type, but found ${type}`);
|
|
407
198
|
}
|
|
199
|
+
type = getNullableType(type.ofType);
|
|
408
200
|
}
|
|
409
201
|
else {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
?.autoApplyAfterParentPlan
|
|
414
|
-
: applyAfterMode === "autoApplyAfterParentSubscribePlan"
|
|
415
|
-
? spec.extensions.grafast
|
|
416
|
-
?.autoApplyAfterParentSubscribePlan
|
|
417
|
-
: applyAfterMode === "autoApplyAfterParentInputPlan"
|
|
418
|
-
? spec.extensions.grafast
|
|
419
|
-
?.autoApplyAfterParentInputPlan
|
|
420
|
-
: applyAfterMode === "autoApplyAfterParentApplyPlan"
|
|
421
|
-
? spec.extensions.grafast
|
|
422
|
-
?.autoApplyAfterParentApplyPlan
|
|
423
|
-
: null;
|
|
424
|
-
if (autoApply) {
|
|
425
|
-
rootFieldArgs.apply(result, [...path, name]);
|
|
426
|
-
}
|
|
202
|
+
// Must be a string
|
|
203
|
+
if (!isInputObjectType(type)) {
|
|
204
|
+
throw new Error(`Invalid path passed to fieldArgs.get(); expected object type, but found ${type}`);
|
|
427
205
|
}
|
|
206
|
+
const field = type.getFields()[segment];
|
|
207
|
+
if (!field) {
|
|
208
|
+
throw new Error(`Invalid path passed to fieldArgs.get(); ${type} has no field named ${segment}`);
|
|
209
|
+
}
|
|
210
|
+
type = getNullableType(field.type);
|
|
428
211
|
}
|
|
429
212
|
}
|
|
213
|
+
return type;
|
|
430
214
|
}
|
|
431
|
-
function concatPath(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
// OPTIMIZE: having a lot of 'is undefined' checks is expensive; instead we
|
|
437
|
-
// should optimize this so that it tracks the set of keys that are set and
|
|
438
|
-
// matches against those as a single operation.
|
|
439
|
-
return !("evalIs" in $value && $value.evalIs(undefined));
|
|
215
|
+
function concatPath(argName, subpath) {
|
|
216
|
+
if (subpath == null)
|
|
217
|
+
return [argName];
|
|
218
|
+
const localPath = Array.isArray(subpath) ? subpath : [subpath];
|
|
219
|
+
return [argName, ...localPath];
|
|
440
220
|
}
|
|
441
|
-
const defaultInputObjectTypeInputPlanResolver = (input, info) => {
|
|
442
|
-
const fields = info.type.getFields();
|
|
443
|
-
const obj = Object.create(null);
|
|
444
|
-
for (const fieldName in fields) {
|
|
445
|
-
obj[fieldName] = input.get(fieldName);
|
|
446
|
-
}
|
|
447
|
-
return (0, object_js_1.object)(obj);
|
|
448
|
-
};
|
|
449
221
|
//# sourceMappingURL=operationPlan-input.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExecutionEntryFlags } from "./interfaces";
|
|
1
2
|
export interface GrafastPlanJSON {
|
|
2
3
|
version: "v1" | "v2";
|
|
3
4
|
}
|
|
@@ -5,12 +6,19 @@ export interface GrafastPlanStepJSONv1 {
|
|
|
5
6
|
id: string | number;
|
|
6
7
|
stepClass: string;
|
|
7
8
|
metaString: string | null;
|
|
9
|
+
isUnary: boolean;
|
|
8
10
|
bucketId: string | number;
|
|
11
|
+
implicitSideEffectStepId: string | number | null;
|
|
9
12
|
dependencyIds: ReadonlyArray<string | number>;
|
|
13
|
+
dependencyForbiddenFlags: ReadonlyArray<ExecutionEntryFlags>;
|
|
14
|
+
dependencyOnReject: ReadonlyArray<string | null | undefined>;
|
|
10
15
|
polymorphicPaths: readonly string[] | undefined;
|
|
11
16
|
isSyncAndSafe: boolean | undefined;
|
|
12
17
|
supportsUnbatched: boolean | undefined;
|
|
13
18
|
hasSideEffects: boolean | undefined;
|
|
19
|
+
stream: {
|
|
20
|
+
initialCountStepId?: number;
|
|
21
|
+
} | undefined;
|
|
14
22
|
extra?: Record<string, JSONValue | undefined>;
|
|
15
23
|
}
|
|
16
24
|
export interface GrafastPlanBucketPhaseJSONv1 {
|
|
@@ -32,8 +40,9 @@ export interface GrafastPlanBucketReasonListItemJSONv1 {
|
|
|
32
40
|
parentStepId: string | number;
|
|
33
41
|
/** If this listItem is to be streamed, the configuration for that streaming */
|
|
34
42
|
stream?: {
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
initialCountStepId?: number;
|
|
44
|
+
ifStepId?: number;
|
|
45
|
+
labelStepId?: number;
|
|
37
46
|
};
|
|
38
47
|
}
|
|
39
48
|
/** Non-branching, deferred */
|
|
@@ -65,6 +74,7 @@ export interface GrafastPlanBucketReasonSubroutineJSONv1 {
|
|
|
65
74
|
export interface GrafastPlanBucketJSONv1 {
|
|
66
75
|
id: number;
|
|
67
76
|
reason: GrafastPlanBucketReasonJSONv1;
|
|
77
|
+
parentSideEffectStepId: string | number | null;
|
|
68
78
|
copyStepIds: ReadonlyArray<string | number>;
|
|
69
79
|
steps: ReadonlyArray<GrafastPlanStepJSONv1>;
|
|
70
80
|
rootStepId: string | number | null;
|
package/dist/polymorphic.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isPolymorphicData = isPolymorphicData;
|
|
4
|
+
exports.assertPolymorphicData = assertPolymorphicData;
|
|
5
|
+
exports.polymorphicWrap = polymorphicWrap;
|
|
6
|
+
exports.resolveType = resolveType;
|
|
4
7
|
const inspect_js_1 = require("./inspect.js");
|
|
5
8
|
const interfaces_js_1 = require("./interfaces.js");
|
|
6
9
|
function isPolymorphicData(data) {
|
|
@@ -12,13 +15,11 @@ function isPolymorphicData(data) {
|
|
|
12
15
|
}
|
|
13
16
|
return true;
|
|
14
17
|
}
|
|
15
|
-
exports.isPolymorphicData = isPolymorphicData;
|
|
16
18
|
function assertPolymorphicData(data) {
|
|
17
19
|
if (!isPolymorphicData(data)) {
|
|
18
20
|
throw new Error(`Expected a polymorphic object, received ${(0, inspect_js_1.inspect)(data)}`);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
exports.assertPolymorphicData = assertPolymorphicData;
|
|
22
23
|
// const EMPTY_OBJECT = Object.freeze(Object.create(null));
|
|
23
24
|
/**
|
|
24
25
|
* Returns an object with the given concrete type (and, optionally, associated
|
|
@@ -50,7 +51,6 @@ data = Object.create(null)) {
|
|
|
50
51
|
});
|
|
51
52
|
*/
|
|
52
53
|
}
|
|
53
|
-
exports.polymorphicWrap = polymorphicWrap;
|
|
54
54
|
/**
|
|
55
55
|
* All polymorphic objects in Grafast have a $$concreteType property which
|
|
56
56
|
* contains the GraphQL object's type name; we simply return that.
|
|
@@ -59,7 +59,6 @@ function resolveType(o) {
|
|
|
59
59
|
assertPolymorphicData(o);
|
|
60
60
|
return o[interfaces_js_1.$$concreteType];
|
|
61
61
|
}
|
|
62
|
-
exports.resolveType = resolveType;
|
|
63
62
|
/* TODO: we should be extracting data from a subproperty when we rewrite how polymorphism works.
|
|
64
63
|
/* *
|
|
65
64
|
* All polymorphic objects in Grafast have a $$concreteType property which
|