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.
Files changed (157) hide show
  1. package/README.md +2 -3
  2. package/dist/args.d.ts +4 -7
  3. package/dist/args.js +53 -38
  4. package/dist/assert.js +2 -3
  5. package/dist/bucket.d.ts +1 -89
  6. package/dist/config.d.ts +0 -17
  7. package/dist/config.js +1 -95
  8. package/dist/constraints.d.ts +15 -1
  9. package/dist/constraints.js +41 -3
  10. package/dist/deferred.js +1 -2
  11. package/dist/dev.d.ts +1 -4
  12. package/dist/dev.js +18 -3
  13. package/dist/engine/LayerPlan.d.ts +21 -111
  14. package/dist/engine/LayerPlan.js +196 -78
  15. package/dist/engine/OperationPlan.d.ts +30 -104
  16. package/dist/engine/OperationPlan.js +763 -471
  17. package/dist/engine/OutputPlan.d.ts +9 -20
  18. package/dist/engine/OutputPlan.js +432 -444
  19. package/dist/engine/StepTracker.d.ts +1 -95
  20. package/dist/engine/StepTracker.js +94 -20
  21. package/dist/engine/executeBucket.d.ts +5 -7
  22. package/dist/engine/executeBucket.js +646 -244
  23. package/dist/engine/executeOutputPlan.d.ts +0 -53
  24. package/dist/engine/executeOutputPlan.js +7 -2
  25. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  26. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  27. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
  28. package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
  29. package/dist/engine/lock.d.ts +4 -0
  30. package/dist/engine/lock.js +82 -0
  31. package/dist/envelop.js +5 -4
  32. package/dist/error.d.ts +18 -49
  33. package/dist/error.js +50 -39
  34. package/dist/establishOperationPlan.js +57 -42
  35. package/dist/execute.d.ts +5 -4
  36. package/dist/execute.js +31 -15
  37. package/dist/exportAs.d.ts +1 -18
  38. package/dist/exportAs.js +2 -3
  39. package/dist/global.js +2 -3
  40. package/dist/grafastGraphql.d.ts +6 -1
  41. package/dist/grafastGraphql.js +35 -16
  42. package/dist/grafastPrint.d.ts +3 -0
  43. package/dist/grafastPrint.js +67 -6
  44. package/dist/graphqlCollectFields.d.ts +7 -34
  45. package/dist/graphqlCollectFields.js +24 -13
  46. package/dist/graphqlMergeSelectionSets.js +1 -2
  47. package/dist/index.d.ts +44 -29
  48. package/dist/index.js +91 -18
  49. package/dist/input.d.ts +1 -9
  50. package/dist/input.js +75 -28
  51. package/dist/inspect.d.ts +9 -3
  52. package/dist/inspect.js +3 -3
  53. package/dist/interfaces.d.ts +238 -93
  54. package/dist/interfaces.js +20 -3
  55. package/dist/makeGrafastSchema.d.ts +21 -9
  56. package/dist/makeGrafastSchema.js +353 -133
  57. package/dist/mermaid.d.ts +0 -17
  58. package/dist/mermaid.js +131 -19
  59. package/dist/middleware.d.ts +7 -0
  60. package/dist/middleware.js +24 -0
  61. package/dist/multistep.d.ts +19 -0
  62. package/dist/multistep.js +54 -0
  63. package/dist/operationPlan-input.d.ts +5 -4
  64. package/dist/operationPlan-input.js +140 -368
  65. package/dist/planJSONInterfaces.d.ts +12 -2
  66. package/dist/polymorphic.js +4 -5
  67. package/dist/prepare.d.ts +1 -7
  68. package/dist/prepare.js +100 -74
  69. package/dist/step.d.ts +118 -172
  70. package/dist/step.js +262 -183
  71. package/dist/steps/__flag.d.ts +65 -0
  72. package/dist/steps/__flag.js +261 -0
  73. package/dist/steps/__inputDefault.d.ts +14 -0
  74. package/dist/steps/__inputDefault.js +48 -0
  75. package/dist/steps/__inputDynamicScalar.d.ts +4 -6
  76. package/dist/steps/__inputDynamicScalar.js +4 -2
  77. package/dist/steps/__inputList.d.ts +5 -9
  78. package/dist/steps/__inputList.js +4 -1
  79. package/dist/steps/__inputObject.d.ts +7 -11
  80. package/dist/steps/__inputObject.js +49 -3
  81. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  82. package/dist/steps/__inputStaticLeaf.js +3 -1
  83. package/dist/steps/__item.d.ts +10 -12
  84. package/dist/steps/__item.js +8 -2
  85. package/dist/steps/__trackedValue.d.ts +7 -55
  86. package/dist/steps/__trackedValue.js +69 -8
  87. package/dist/steps/__value.d.ts +5 -4
  88. package/dist/steps/__value.js +5 -4
  89. package/dist/steps/access.d.ts +10 -10
  90. package/dist/steps/access.js +50 -17
  91. package/dist/steps/applyInput.d.ts +44 -0
  92. package/dist/steps/applyInput.js +206 -0
  93. package/dist/steps/applyTransforms.d.ts +2 -25
  94. package/dist/steps/applyTransforms.js +53 -31
  95. package/dist/steps/bakedInput.d.ts +23 -0
  96. package/dist/steps/bakedInput.js +90 -0
  97. package/dist/steps/condition.d.ts +31 -0
  98. package/dist/steps/condition.js +94 -0
  99. package/dist/steps/connection.d.ts +56 -42
  100. package/dist/steps/connection.js +97 -44
  101. package/dist/steps/constant.d.ts +7 -7
  102. package/dist/steps/constant.js +86 -7
  103. package/dist/steps/each.d.ts +3 -3
  104. package/dist/steps/each.js +2 -3
  105. package/dist/steps/error.d.ts +4 -4
  106. package/dist/steps/error.js +7 -6
  107. package/dist/steps/filter.d.ts +3 -2
  108. package/dist/steps/filter.js +1 -2
  109. package/dist/steps/first.d.ts +10 -9
  110. package/dist/steps/first.js +9 -13
  111. package/dist/steps/graphqlResolver.d.ts +3 -76
  112. package/dist/steps/graphqlResolver.js +89 -72
  113. package/dist/steps/groupBy.d.ts +3 -2
  114. package/dist/steps/groupBy.js +1 -2
  115. package/dist/steps/index.d.ts +12 -3
  116. package/dist/steps/index.js +48 -6
  117. package/dist/steps/lambda.d.ts +9 -9
  118. package/dist/steps/lambda.js +18 -9
  119. package/dist/steps/last.d.ts +9 -8
  120. package/dist/steps/last.js +7 -6
  121. package/dist/steps/list.d.ts +20 -9
  122. package/dist/steps/list.js +56 -13
  123. package/dist/steps/listTransform.d.ts +18 -22
  124. package/dist/steps/listTransform.js +58 -27
  125. package/dist/steps/listen.d.ts +6 -11
  126. package/dist/steps/listen.js +14 -16
  127. package/dist/steps/load.d.ts +42 -33
  128. package/dist/steps/load.js +60 -27
  129. package/dist/steps/node.d.ts +17 -10
  130. package/dist/steps/node.js +18 -6
  131. package/dist/steps/object.d.ts +33 -27
  132. package/dist/steps/object.js +53 -32
  133. package/dist/steps/partitionByIndex.d.ts +3 -2
  134. package/dist/steps/partitionByIndex.js +1 -2
  135. package/dist/steps/polymorphicBranch.d.ts +27 -0
  136. package/dist/steps/polymorphicBranch.js +62 -0
  137. package/dist/steps/proxy.d.ts +11 -12
  138. package/dist/steps/proxy.js +8 -5
  139. package/dist/steps/remapKeys.d.ts +10 -10
  140. package/dist/steps/remapKeys.js +14 -7
  141. package/dist/steps/reverse.d.ts +8 -8
  142. package/dist/steps/reverse.js +10 -7
  143. package/dist/steps/setter.d.ts +9 -18
  144. package/dist/steps/setter.js +24 -14
  145. package/dist/steps/sideEffect.d.ts +28 -0
  146. package/dist/steps/sideEffect.js +44 -0
  147. package/dist/stringifyPayload.js +1 -2
  148. package/dist/stripAnsi.js +2 -2
  149. package/dist/subscribe.d.ts +7 -1
  150. package/dist/subscribe.js +24 -9
  151. package/dist/thereCanBeOnlyOne.js +1 -1
  152. package/dist/timeSource.d.ts +0 -1
  153. package/dist/utils.d.ts +56 -55
  154. package/dist/utils.js +179 -59
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +5 -8
@@ -1,26 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withFieldArgsForArguments = void 0;
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 constant_js_1 = require("./steps/constant.js");
7
- const list_js_1 = require("./steps/list.js");
8
- const object_js_1 = require("./steps/object.js");
9
- const { getNullableType, isEnumType, isInputObjectType, isListType, isScalarType, } = graphql;
10
- function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAfterMode, callback) {
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
- getRaw(path) {
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
- get(inPath) {
50
- const path = Array.isArray(inPath)
51
- ? inPath
52
- : inPath
53
- ? [inPath]
54
- : [];
55
- const pathString = path.join(".");
56
- const $existing = got.get(pathString);
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 ${targetStepOrCallback}. Multiple applications are not currently supported.`);
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
- let entity = args[argName];
158
- if (!entity) {
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
- let entityType = entity.type;
162
- let $val = $all.get(argName);
163
- for (const pathSegment of rest) {
164
- const nullableType = getNullableType(entityType);
165
- if (isInputObjectType(nullableType)) {
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
- if (notUndefined($val)) {
191
- const childFieldArgs = getFieldArgsForPath(path, entityType, $val, "apply");
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
- if (!val) {
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
- if (!explicitlyApplied) {
394
- processAfter(fieldArgs, [], result, args, applyAfterMode);
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
- exports.withFieldArgsForArguments = withFieldArgsForArguments;
401
- function processAfter(rootFieldArgs, path, result, fields, applyAfterMode) {
402
- if (result != null && !(result instanceof constant_js_1.ConstantStep && result.isNull())) {
403
- if (applyAfterMode === "autoApplyAfterParentApplyPlan" && result != null) {
404
- // `applyPlan` returned a step, so auto-apply every subfield to it
405
- for (const name of Object.keys(fields)) {
406
- rootFieldArgs.apply(result, [...path, name]);
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
- for (const [name, spec] of Object.entries(fields)) {
411
- const autoApply = applyAfterMode === "autoApplyAfterParentPlan"
412
- ? spec.extensions.grafast
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(path, subpath) {
432
- const localPath = Array.isArray(subpath) ? subpath : subpath ? [subpath] : [];
433
- return [...path, ...localPath];
434
- }
435
- function notUndefined($value) {
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
- initialCount: number;
36
- label?: string;
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;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveType = exports.polymorphicWrap = exports.assertPolymorphicData = exports.isPolymorphicData = void 0;
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