grafast 0.1.1-beta.20 → 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 (133) hide show
  1. package/dist/args.js +2 -3
  2. package/dist/assert.js +2 -3
  3. package/dist/constraints.js +1 -2
  4. package/dist/deferred.js +1 -2
  5. package/dist/dev.js +2 -2
  6. package/dist/engine/LayerPlan.d.ts +20 -16
  7. package/dist/engine/LayerPlan.js +5 -10
  8. package/dist/engine/OperationPlan.d.ts +12 -13
  9. package/dist/engine/OperationPlan.js +210 -146
  10. package/dist/engine/OutputPlan.d.ts +4 -4
  11. package/dist/engine/OutputPlan.js +13 -10
  12. package/dist/engine/StepTracker.js +11 -2
  13. package/dist/engine/executeBucket.js +135 -94
  14. package/dist/engine/executeOutputPlan.js +1 -2
  15. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  16. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  17. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -2
  18. package/dist/engine/lib/withGlobalLayerPlan.js +4 -5
  19. package/dist/engine/lock.d.ts +3 -3
  20. package/dist/engine/lock.js +3 -3
  21. package/dist/error.js +4 -4
  22. package/dist/establishOperationPlan.js +2 -3
  23. package/dist/execute.js +3 -4
  24. package/dist/exportAs.js +2 -3
  25. package/dist/global.js +2 -3
  26. package/dist/grafastGraphql.js +2 -3
  27. package/dist/grafastPrint.js +7 -8
  28. package/dist/graphqlCollectFields.js +6 -7
  29. package/dist/graphqlMergeSelectionSets.js +1 -2
  30. package/dist/index.d.ts +22 -18
  31. package/dist/index.js +41 -16
  32. package/dist/input.js +75 -28
  33. package/dist/inspect.d.ts +9 -4
  34. package/dist/inspect.js +2 -2
  35. package/dist/interfaces.d.ts +110 -89
  36. package/dist/makeGrafastSchema.d.ts +18 -9
  37. package/dist/makeGrafastSchema.js +64 -30
  38. package/dist/mermaid.js +53 -14
  39. package/dist/middleware.js +1 -2
  40. package/dist/multistep.d.ts +6 -6
  41. package/dist/multistep.js +6 -7
  42. package/dist/operationPlan-input.d.ts +5 -4
  43. package/dist/operationPlan-input.js +131 -399
  44. package/dist/planJSONInterfaces.d.ts +6 -2
  45. package/dist/polymorphic.js +4 -5
  46. package/dist/prepare.js +6 -6
  47. package/dist/step.d.ts +67 -99
  48. package/dist/step.js +99 -127
  49. package/dist/steps/__flag.d.ts +16 -16
  50. package/dist/steps/__flag.js +9 -6
  51. package/dist/steps/__inputDefault.d.ts +14 -0
  52. package/dist/steps/__inputDefault.js +48 -0
  53. package/dist/steps/__inputDynamicScalar.d.ts +2 -4
  54. package/dist/steps/__inputDynamicScalar.js +4 -2
  55. package/dist/steps/__inputList.d.ts +5 -9
  56. package/dist/steps/__inputList.js +4 -1
  57. package/dist/steps/__inputObject.d.ts +6 -11
  58. package/dist/steps/__inputObject.js +13 -3
  59. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  60. package/dist/steps/__inputStaticLeaf.js +3 -1
  61. package/dist/steps/__item.d.ts +6 -6
  62. package/dist/steps/__item.js +1 -1
  63. package/dist/steps/__trackedValue.d.ts +4 -49
  64. package/dist/steps/__trackedValue.js +24 -6
  65. package/dist/steps/__value.d.ts +3 -3
  66. package/dist/steps/__value.js +3 -2
  67. package/dist/steps/access.d.ts +7 -6
  68. package/dist/steps/access.js +14 -7
  69. package/dist/steps/applyInput.d.ts +44 -0
  70. package/dist/steps/applyInput.js +206 -0
  71. package/dist/steps/applyTransforms.d.ts +2 -2
  72. package/dist/steps/applyTransforms.js +7 -5
  73. package/dist/steps/bakedInput.d.ts +23 -0
  74. package/dist/steps/bakedInput.js +90 -0
  75. package/dist/steps/condition.d.ts +5 -5
  76. package/dist/steps/condition.js +3 -3
  77. package/dist/steps/connection.d.ts +42 -39
  78. package/dist/steps/connection.js +51 -35
  79. package/dist/steps/constant.d.ts +4 -8
  80. package/dist/steps/constant.js +54 -6
  81. package/dist/steps/each.d.ts +3 -3
  82. package/dist/steps/each.js +1 -2
  83. package/dist/steps/error.d.ts +2 -2
  84. package/dist/steps/error.js +3 -3
  85. package/dist/steps/filter.d.ts +3 -2
  86. package/dist/steps/filter.js +1 -2
  87. package/dist/steps/first.d.ts +6 -5
  88. package/dist/steps/first.js +5 -4
  89. package/dist/steps/graphqlResolver.d.ts +2 -2
  90. package/dist/steps/graphqlResolver.js +44 -56
  91. package/dist/steps/groupBy.d.ts +3 -2
  92. package/dist/steps/groupBy.js +1 -2
  93. package/dist/steps/index.d.ts +4 -2
  94. package/dist/steps/index.js +21 -9
  95. package/dist/steps/lambda.d.ts +5 -5
  96. package/dist/steps/lambda.js +4 -4
  97. package/dist/steps/last.d.ts +6 -5
  98. package/dist/steps/last.js +5 -4
  99. package/dist/steps/list.d.ts +7 -7
  100. package/dist/steps/list.js +3 -3
  101. package/dist/steps/listTransform.d.ts +14 -12
  102. package/dist/steps/listTransform.js +14 -7
  103. package/dist/steps/listen.d.ts +6 -8
  104. package/dist/steps/listen.js +7 -7
  105. package/dist/steps/load.d.ts +6 -6
  106. package/dist/steps/load.js +7 -7
  107. package/dist/steps/node.d.ts +16 -10
  108. package/dist/steps/node.js +14 -7
  109. package/dist/steps/object.d.ts +11 -11
  110. package/dist/steps/object.js +5 -5
  111. package/dist/steps/partitionByIndex.d.ts +3 -2
  112. package/dist/steps/partitionByIndex.js +1 -2
  113. package/dist/steps/polymorphicBranch.d.ts +8 -8
  114. package/dist/steps/polymorphicBranch.js +4 -4
  115. package/dist/steps/proxy.d.ts +8 -8
  116. package/dist/steps/proxy.js +3 -3
  117. package/dist/steps/remapKeys.d.ts +6 -6
  118. package/dist/steps/remapKeys.js +3 -3
  119. package/dist/steps/reverse.d.ts +5 -5
  120. package/dist/steps/reverse.js +4 -4
  121. package/dist/steps/setter.d.ts +9 -18
  122. package/dist/steps/setter.js +24 -14
  123. package/dist/steps/sideEffect.d.ts +4 -4
  124. package/dist/steps/sideEffect.js +3 -3
  125. package/dist/stringifyPayload.js +1 -2
  126. package/dist/stripAnsi.js +2 -2
  127. package/dist/subscribe.js +2 -3
  128. package/dist/timeSource.d.ts +0 -1
  129. package/dist/utils.d.ts +43 -31
  130. package/dist/utils.js +97 -61
  131. package/dist/version.d.ts +1 -1
  132. package/dist/version.js +1 -1
  133. package/package.json +2 -2
@@ -1,33 +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");
7
+ const index_js_1 = require("./index.js");
8
+ const inspect_js_1 = require("./inspect.js");
9
9
  const utils_js_1 = require("./utils.js");
10
- const { getNullableType, isEnumType, isInputObjectType, isListType, isScalarType, } = graphql;
10
+ const { getNullableType, isInputObjectType, isListType } = graphql;
11
11
  function assertNotRuntime(operationPlan, description) {
12
12
  if (operationPlan.phase === "ready") {
13
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
14
  }
15
15
  }
16
- function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAfterMode, callback) {
16
+ function withFieldArgsForArguments(operationPlan, $all, field, $parent, applyAfterMode, coordinate, callback) {
17
17
  if (operationPlan.loc !== null)
18
18
  operationPlan.loc.push(`withFieldArgsForArguments(${field.name})`);
19
- const schema = operationPlan.schema;
20
19
  const args = Object.create(null);
21
20
  for (const arg of field.args) {
22
21
  args[arg.name] = arg;
23
22
  }
24
- const got = new Map();
25
23
  const applied = new Map();
26
24
  let explicitlyApplied = false;
27
25
  const fieldArgs = {
26
+ typeAt(path) {
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
+ },
28
62
  getRaw(path) {
29
63
  assertNotRuntime(operationPlan, `fieldArgs.getRaw()`);
30
- if (typeof path === "string") {
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") {
31
68
  return $all.get(path);
32
69
  }
33
70
  else if (Array.isArray(path)) {
@@ -50,201 +87,47 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
50
87
  return $entry;
51
88
  }
52
89
  else {
53
- 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)}`);
54
91
  }
55
92
  },
56
- get(inPath) {
57
- assertNotRuntime(operationPlan, `fieldArgs.get()`);
58
- const path = Array.isArray(inPath)
59
- ? inPath
60
- : inPath
61
- ? [inPath]
62
- : [];
63
- const pathString = path.join(".");
64
- const $existing = got.get(pathString);
65
- if ($existing) {
66
- return $existing;
67
- }
68
- if (path.length === 0) {
69
- const values = Object.create(null);
70
- for (const argName of Object.keys(args)) {
71
- values[argName] = fieldArgs.get([argName]);
72
- }
73
- return (0, object_js_1.object)(values);
74
- }
75
- else {
76
- const [argName, ...rest] = path;
77
- if (typeof argName !== "string") {
78
- throw new Error(`Invalid path; argument '${argName}' is an invalid argument name`);
79
- }
80
- let entity = args[argName];
81
- if (!entity) {
82
- throw new Error(`Invalid path; argument '${argName}' does not exist`);
83
- }
84
- let entityType = entity.type;
85
- let $val = $all.get(argName);
86
- for (const pathSegment of rest) {
87
- const nullableType = getNullableType(entityType);
88
- if (typeof pathSegment === "string" &&
89
- isInputObjectType(nullableType)) {
90
- entity = nullableType.getFields()[pathSegment];
91
- entityType = entity.type;
92
- if ("get" in $val) {
93
- $val = $val.get(pathSegment);
94
- }
95
- else if ($val instanceof constant_js_1.ConstantStep && $val.isUndefined()) {
96
- $val = (0, constant_js_1.constant)(undefined);
97
- }
98
- else {
99
- throw new Error(`GrafastInternalError<b9e9a57a-bbdd-486c-bdcf-25cf99bf0243>: Processing input object type, but '${$val}' has no .get() method.`);
100
- }
101
- }
102
- else if (typeof pathSegment === "number" &&
103
- isListType(nullableType)) {
104
- entity = null;
105
- entityType = nullableType.ofType;
106
- if ("at" in $val) {
107
- $val = $val.at(pathSegment);
108
- }
109
- else {
110
- throw new Error(`GrafastInternalError<0abe76fa-c87a-4477-aebd-feffef848c2b>: Processing input object type, but '${$val}' has no .get() method.`);
111
- }
112
- }
113
- else {
114
- throw new Error(`Asked to navigate ('get' mode) to position '${pathSegment}' (${typeof pathSegment}) (in path '${path.join(".")}') for incompatible type '${nullableType}' (${nullableType.constructor.name})`);
115
- }
116
- }
117
- let result;
118
- const childFieldArgs = getFieldArgsForPath(path, entityType, $val, "input");
119
- if (rest.length === 0) {
120
- // Argument
121
- const arg = entity;
122
- const argInputPlan = arg.extensions.grafast?.inputPlan;
123
- const fnDescription = `???.${field.name}(${arg.name}:).inputPlan`;
124
- (0, utils_js_1.assertNotAsync)(argInputPlan, fnDescription);
125
- result = argInputPlan
126
- ? (0, utils_js_1.assertNotPromise)(argInputPlan($parent, childFieldArgs, {
127
- schema,
128
- entity: arg,
129
- }), argInputPlan, fnDescription)
130
- : childFieldArgs.get();
131
- }
132
- else {
133
- // Input field
134
- const inputField = entity;
135
- const inputFieldInputPlan = inputField?.extensions.grafast?.inputPlan;
136
- const fnDescription = `???.${inputField?.name}.inputPlan`;
137
- (0, utils_js_1.assertNotAsync)(inputFieldInputPlan, fnDescription);
138
- result = inputFieldInputPlan
139
- ? (0, utils_js_1.assertNotPromise)(inputFieldInputPlan(childFieldArgs, {
140
- schema,
141
- entity: inputField,
142
- }), inputFieldInputPlan, fnDescription)
143
- : childFieldArgs.get();
144
- }
145
- const nullableType = getNullableType(entityType);
146
- if (isInputObjectType(nullableType)) {
147
- processAfter(fieldArgs, path, result, nullableType.getFields(), "autoApplyAfterParentInputPlan");
148
- }
149
- return result;
150
- }
151
- },
152
- 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;
153
100
  assertNotRuntime(operationPlan, `fieldArgs.apply()`);
154
101
  const path = Array.isArray(inPath) ? inPath : inPath ? [inPath] : [];
155
102
  const pathString = path.join(".");
156
103
  const $existing = applied.get(pathString);
157
104
  if ($existing) {
158
- 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.`);
159
106
  }
160
107
  if (path.length === 0) {
161
108
  explicitlyApplied = true;
162
109
  // Auto-apply all the arguments
163
110
  for (const argName of Object.keys(args)) {
164
- const $target = typeof targetStepOrCallback === "function"
165
- ? targetStepOrCallback()
166
- : targetStepOrCallback;
167
111
  fieldArgs.apply($target, [argName]);
168
112
  }
169
113
  }
170
114
  else {
171
115
  const [argName, ...rest] = path;
172
- let entity = args[argName];
173
- 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) {
174
121
  throw new Error(`Invalid path; argument '${argName}' does not exist`);
175
122
  }
176
- let entityType = entity.type;
177
- let $val = $all.get(argName);
178
- for (const pathSegment of rest) {
179
- const nullableType = getNullableType(entityType);
180
- if (isInputObjectType(nullableType)) {
181
- entity = nullableType.getFields()[pathSegment];
182
- entityType = entity.type;
183
- if ("get" in $val) {
184
- $val = $val.get(pathSegment);
185
- }
186
- else {
187
- throw new Error(`GrafastInternalError<91e1e80d-cf24-4828-a749-3f24156c7b9c>: Processing input object type, but '${$val}' has no .get() method.`);
188
- }
189
- }
190
- else if (typeof pathSegment === "number" &&
191
- isListType(nullableType)) {
192
- entity = null;
193
- entityType = nullableType.ofType;
194
- if ("at" in $val) {
195
- $val = $val.at(pathSegment);
196
- }
197
- else {
198
- throw new Error(`GrafastInternalError<a097a130-f68f-4a5c-bd0c-24fcd26127a9>: Processing list type, but '${$val}' has no .at() method.`);
199
- }
200
- }
201
- else {
202
- throw new Error(`Asked to navigate ('apply' mode) to position '${pathSegment}' (${typeof pathSegment}) (in path '${path.join(".")}') for incompatible type '${nullableType}' (${nullableType.constructor.name})`);
203
- }
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!
204
128
  }
205
- if (notUndefined($val)) {
206
- const childFieldArgs = getFieldArgsForPath(path, entityType, $val, "apply");
207
- operationPlan.withModifiers(() => {
208
- let result;
209
- const $target = typeof targetStepOrCallback === "function"
210
- ? targetStepOrCallback()
211
- : targetStepOrCallback;
212
- if (rest.length === 0) {
213
- // Argument
214
- const arg = entity;
215
- const argApplyPlan = arg.extensions.grafast?.applyPlan;
216
- const fnDescription = `???.${field.name}(${arg.name}:).applyPlan`;
217
- (0, utils_js_1.assertNotAsync)(argApplyPlan, fnDescription);
218
- result = argApplyPlan
219
- ? (0, utils_js_1.assertNotPromise)(argApplyPlan($parent, $target, childFieldArgs, {
220
- schema,
221
- entity: arg,
222
- }), argApplyPlan, fnDescription)
223
- : undefined;
224
- }
225
- else if (entity) {
226
- // input field
227
- const inputField = entity;
228
- const inputFieldApplyPlan = inputField.extensions.grafast?.applyPlan;
229
- const fnDescription = `???.${inputField.name}.applyPlan`;
230
- (0, utils_js_1.assertNotAsync)(inputFieldApplyPlan, fnDescription);
231
- result = inputFieldApplyPlan
232
- ? (0, utils_js_1.assertNotPromise)(inputFieldApplyPlan($target, childFieldArgs, {
233
- schema,
234
- entity: inputField,
235
- }), inputFieldApplyPlan, fnDescription)
236
- : undefined;
237
- }
238
- else {
239
- childFieldArgs.apply($target);
240
- // Shortcut 'processAfter'
241
- return;
242
- }
243
- const nullableType = getNullableType(entityType);
244
- if (isInputObjectType(nullableType)) {
245
- processAfter(fieldArgs, path, result, nullableType.getFields(), "autoApplyAfterParentApplyPlan");
246
- }
247
- });
129
+ else {
130
+ $target.apply((0, index_js_1.applyInput)(typeAtPath, $valueAtPath, getTargetFromParent));
248
131
  }
249
132
  }
250
133
  },
@@ -253,237 +136,86 @@ function withFieldArgsForArguments(operationPlan, $parent, $all, field, applyAft
253
136
  let val;
254
137
  Object.defineProperty(fieldArgs, `$${argName}`, {
255
138
  get() {
256
- if (!val) {
257
- val = fieldArgs.getRaw(argName);
258
- }
259
- return val;
139
+ return (val ??= fieldArgs.getRaw(argName));
260
140
  },
261
141
  });
262
142
  }
263
- function getFieldArgsForPath(path, entityType, $input, mode) {
264
- const nullableEntityType = getNullableType(entityType);
265
- const localFieldArgs = {
266
- getRaw(subpath) {
267
- assertNotRuntime(operationPlan, `fieldArgs.getRaw()`);
268
- return fieldArgs.getRaw(concatPath(path, subpath));
269
- },
270
- get(subpath) {
271
- assertNotRuntime(operationPlan, `fieldArgs.get()`);
272
- if (!subpath || (Array.isArray(subpath) && subpath.length === 0)) {
273
- if (isListType(nullableEntityType)) {
274
- if (!("evalLength" in $input)) {
275
- throw new Error(`GrafastInternalError<6ef74af7-7be0-4117-870f-2ebabcf5161c>: Expected ${$input} to be a __InputListStep or __TrackedValueStep (i.e. to have 'evalLength')`);
276
- }
277
- const l = $input.evalLength();
278
- if (l == null) {
279
- return (0, constant_js_1.constant)(null);
280
- }
281
- const entries = [];
282
- for (let i = 0; i < l; i++) {
283
- const entry = fieldArgs.get([...path, i]);
284
- entries.push(entry);
285
- }
286
- return (0, list_js_1.list)(entries);
287
- }
288
- else if (isInputObjectType(nullableEntityType)) {
289
- const typeResolver = nullableEntityType.extensions.grafast?.inputPlan ||
290
- defaultInputObjectTypeInputPlanResolver;
291
- const fnDescription = `${nullableEntityType}.inputPlan`;
292
- (0, utils_js_1.assertNotAsync)(typeResolver, fnDescription);
293
- const resolvedResult = (0, utils_js_1.assertNotPromise)(typeResolver(getFieldArgsForPath(path, nullableEntityType, $input, "input"), {
294
- schema,
295
- type: nullableEntityType,
296
- }), typeResolver, fnDescription);
297
- if (mode === "apply") {
298
- // NOTE: if mode === 'input' then `.get()` won't need a
299
- // `processAfter` since that will already have been handled in
300
- // the parent fieldArgs.
301
- processAfter(fieldArgs, path, resolvedResult, nullableEntityType.getFields(), "autoApplyAfterParentInputPlan");
302
- }
303
- return resolvedResult;
304
- }
305
- else if (isScalarType(nullableEntityType)) {
306
- const scalarResolver = nullableEntityType.extensions.grafast?.inputPlan;
307
- const fnDescription = `${nullableEntityType}.inputPlan`;
308
- (0, utils_js_1.assertNotAsync)(scalarResolver, fnDescription);
309
- if (scalarResolver !== undefined) {
310
- return (0, utils_js_1.assertNotPromise)(scalarResolver($input, {
311
- schema,
312
- type: nullableEntityType,
313
- }), scalarResolver, fnDescription);
314
- }
315
- else {
316
- return $input;
317
- }
318
- }
319
- else if (isEnumType(nullableEntityType)) {
320
- /*
321
- const enumResolver = nullableEntityType.extensions.grafast?.inputPlan;
322
- if (enumResolver) {
323
- return enumResolver($input, { schema, type: nullableEntityType });
324
- } else {
325
- return $input;
326
- }
327
- */
328
- return $input;
329
- }
330
- else {
331
- throw new Error(`Call to fieldArgs.get() at input path '${path.join(".")}' must pass a non-empty subpath`);
332
- }
333
- }
334
- return fieldArgs.get(concatPath(path, subpath));
335
- },
336
- apply(targetStepOrCallback, subpath) {
337
- assertNotRuntime(operationPlan, `fieldArgs.apply()`);
338
- if (mode === "apply" &&
339
- (!subpath || (Array.isArray(subpath) && subpath.length === 0))) {
340
- if (isInputObjectType(nullableEntityType)) {
341
- if (!("evalKeys" in $input)) {
342
- throw new Error(`GrafastInternalError<d782160e-7a99-4a12-b690-435c1ab7b676>: Expected ${$input} to be a __InputObjectStep or __TrackedValueStep (i.e. to have 'evalKeys')`);
343
- }
344
- const keys = $input.evalKeys();
345
- if (keys == null) {
346
- return;
347
- }
348
- for (const fieldName of keys) {
349
- const $target = typeof targetStepOrCallback === "function"
350
- ? targetStepOrCallback()
351
- : targetStepOrCallback;
352
- fieldArgs.apply($target, [...path, fieldName]);
353
- }
354
- }
355
- else if (isListType(nullableEntityType)) {
356
- if (!("evalLength" in $input)) {
357
- throw new Error(`GrafastInternalError<6ef74af7-7be0-4117-870f-2ebabcf5161c>: Expected ${$input} to be a __InputListStep or __TrackedValueStep (i.e. to have 'evalLength')`);
358
- }
359
- const l = $input.evalLength();
360
- if (l == null) {
361
- return;
362
- }
363
- // const innerType = nullableEntityType.ofType;
364
- for (let i = 0; i < l; i++) {
365
- const $target = typeof targetStepOrCallback === "function"
366
- ? targetStepOrCallback()
367
- : targetStepOrCallback;
368
- fieldArgs.apply($target, [...path, i]);
369
- }
370
- }
371
- else if (isScalarType(nullableEntityType)) {
372
- // noop
373
- }
374
- else if (isEnumType(nullableEntityType)) {
375
- // PERF: only do this if this enum type has values that have side effects
376
- const value = $input.eval();
377
- const enumValue = nullableEntityType
378
- .getValues()
379
- .find((v) => v.value === value);
380
- if (enumValue) {
381
- const enumResolver = enumValue.extensions.grafast?.applyPlan;
382
- const fnDescription = `${nullableEntityType.name}.${enumValue.name}.applyPlan`;
383
- (0, utils_js_1.assertNotAsync)(enumResolver, fnDescription);
384
- if (enumResolver !== undefined) {
385
- const $target = typeof targetStepOrCallback === "function"
386
- ? targetStepOrCallback()
387
- : targetStepOrCallback;
388
- (0, utils_js_1.assertNotPromise)(enumResolver($target), enumResolver, fnDescription);
389
- }
390
- }
391
- }
392
- else {
393
- const never = nullableEntityType;
394
- throw new Error(`Unhandled input type ${never}`);
395
- }
396
- }
397
- else {
398
- const $target = typeof targetStepOrCallback === "function"
399
- ? targetStepOrCallback()
400
- : targetStepOrCallback;
401
- fieldArgs.apply($target, concatPath(path, subpath));
402
- }
403
- },
404
- };
405
- if (isInputObjectType(nullableEntityType)) {
406
- const inputFields = nullableEntityType.getFields();
407
- for (const fieldName of Object.keys(inputFields)) {
408
- let val;
409
- Object.defineProperty(localFieldArgs, `$${fieldName}`, {
410
- enumerable: true,
411
- get() {
412
- if (!val) {
413
- if ("get" in $input) {
414
- val = $input.get(fieldName);
415
- }
416
- else if ($input instanceof constant_js_1.ConstantStep &&
417
- $input.isUndefined()) {
418
- val = (0, constant_js_1.constant)(undefined);
419
- }
420
- else {
421
- throw new Error(`GrafastInternalError<9b70d5c0-c45f-4acd-8b94-eaa02f87ad41>: expected '${$input}' to have a .get() method`);
422
- }
423
- }
424
- return val;
425
- },
426
- });
427
- }
428
- }
429
- return localFieldArgs;
430
- }
431
143
  const result = callback(fieldArgs);
432
144
  (0, utils_js_1.assertNotPromise)(result, callback, operationPlan.loc?.join(">") ?? "???");
433
- if (!explicitlyApplied) {
434
- processAfter(fieldArgs, [], result, args, applyAfterMode);
145
+ if (!explicitlyApplied && result != null) {
146
+ processAfter($parent, fieldArgs, result, args, applyAfterMode, coordinate);
435
147
  }
436
148
  if (operationPlan.loc !== null)
437
149
  operationPlan.loc.pop();
438
150
  return (result ?? null);
439
151
  }
440
- exports.withFieldArgsForArguments = withFieldArgsForArguments;
441
- function processAfter(rootFieldArgs, path, result, fields, applyAfterMode) {
442
- if (result != null && !(result instanceof constant_js_1.ConstantStep && result.isNull())) {
443
- if (applyAfterMode === "autoApplyAfterParentApplyPlan" && result != null) {
444
- // `applyPlan` returned a step, so auto-apply every subfield to it
445
- for (const name of Object.keys(fields)) {
446
- 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}`);
447
198
  }
199
+ type = getNullableType(type.ofType);
448
200
  }
449
201
  else {
450
- for (const [name, spec] of Object.entries(fields)) {
451
- const autoApply = applyAfterMode === "autoApplyAfterParentPlan"
452
- ? spec.extensions.grafast
453
- ?.autoApplyAfterParentPlan
454
- : applyAfterMode === "autoApplyAfterParentSubscribePlan"
455
- ? spec.extensions.grafast
456
- ?.autoApplyAfterParentSubscribePlan
457
- : applyAfterMode === "autoApplyAfterParentInputPlan"
458
- ? spec.extensions.grafast
459
- ?.autoApplyAfterParentInputPlan
460
- : applyAfterMode === "autoApplyAfterParentApplyPlan"
461
- ? spec.extensions.grafast
462
- ?.autoApplyAfterParentApplyPlan
463
- : null;
464
- if (autoApply) {
465
- rootFieldArgs.apply(result, [...path, name]);
466
- }
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}`);
467
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);
468
211
  }
469
212
  }
213
+ return type;
470
214
  }
471
- function concatPath(path, subpath) {
472
- const localPath = Array.isArray(subpath) ? subpath : subpath ? [subpath] : [];
473
- return [...path, ...localPath];
474
- }
475
- function notUndefined($value) {
476
- // OPTIMIZE: having a lot of 'is undefined' checks is expensive; instead we
477
- // should optimize this so that it tracks the set of keys that are set and
478
- // matches against those as a single operation.
479
- 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];
480
220
  }
481
- const defaultInputObjectTypeInputPlanResolver = (input, info) => {
482
- const fields = info.type.getFields();
483
- const obj = Object.create(null);
484
- for (const fieldName in fields) {
485
- obj[fieldName] = input.get(fieldName);
486
- }
487
- return (0, object_js_1.object)(obj);
488
- };
489
221
  //# sourceMappingURL=operationPlan-input.js.map
@@ -16,6 +16,9 @@ export interface GrafastPlanStepJSONv1 {
16
16
  isSyncAndSafe: boolean | undefined;
17
17
  supportsUnbatched: boolean | undefined;
18
18
  hasSideEffects: boolean | undefined;
19
+ stream: {
20
+ initialCountStepId?: number;
21
+ } | undefined;
19
22
  extra?: Record<string, JSONValue | undefined>;
20
23
  }
21
24
  export interface GrafastPlanBucketPhaseJSONv1 {
@@ -37,8 +40,9 @@ export interface GrafastPlanBucketReasonListItemJSONv1 {
37
40
  parentStepId: string | number;
38
41
  /** If this listItem is to be streamed, the configuration for that streaming */
39
42
  stream?: {
40
- initialCount: number;
41
- label?: string;
43
+ initialCountStepId?: number;
44
+ ifStepId?: number;
45
+ labelStepId?: number;
42
46
  };
43
47
  }
44
48
  /** Non-branching, deferred */
@@ -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