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,6 +1,6 @@
1
- import type { GrafastResultsList } from "../interfaces.js";
2
- import { UnbatchedExecutableStep } from "../step.js";
3
- export declare class ErrorStep<TError extends Error> extends UnbatchedExecutableStep<never> {
1
+ import type { ExecutionDetails, GrafastResultsList } from "../interfaces.js";
2
+ import { UnbatchedStep } from "../step.js";
3
+ export declare class ErrorStep<TError extends Error> extends UnbatchedStep<never> {
4
4
  static $$export: {
5
5
  moduleName: string;
6
6
  exportName: string;
@@ -8,7 +8,7 @@ export declare class ErrorStep<TError extends Error> extends UnbatchedExecutable
8
8
  isSyncAndSafe: boolean;
9
9
  error: TError;
10
10
  constructor(error: TError);
11
- execute(count: number): GrafastResultsList<any>;
11
+ execute({ count }: ExecutionDetails): GrafastResultsList<any>;
12
12
  unbatchedExecute(): any;
13
13
  }
14
14
  export declare function error<TError extends Error>(error: TError): ErrorStep<TError>;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.error = exports.ErrorStep = void 0;
3
+ exports.ErrorStep = void 0;
4
+ exports.error = error;
5
+ const error_js_1 = require("../error.js");
4
6
  const inspect_js_1 = require("../inspect.js");
5
7
  const step_js_1 = require("../step.js");
6
8
  const utils_js_1 = require("../utils.js");
7
- class ErrorStep extends step_js_1.UnbatchedExecutableStep {
9
+ class ErrorStep extends step_js_1.UnbatchedStep {
8
10
  static { this.$$export = {
9
11
  moduleName: "grafast",
10
12
  exportName: "ErrorStep",
@@ -17,16 +19,15 @@ class ErrorStep extends step_js_1.UnbatchedExecutableStep {
17
19
  }
18
20
  this.error = error;
19
21
  }
20
- execute(count) {
21
- return (0, utils_js_1.arrayOfLength)(count, this.error);
22
+ execute({ count }) {
23
+ return (0, utils_js_1.arrayOfLength)(count, (0, error_js_1.flagError)(this.error));
22
24
  }
23
25
  unbatchedExecute() {
24
- return this.error;
26
+ return (0, error_js_1.flagError)(this.error);
25
27
  }
26
28
  }
27
29
  exports.ErrorStep = ErrorStep;
28
30
  function error(error) {
29
31
  return new ErrorStep(error);
30
32
  }
31
- exports.error = error;
32
33
  //# sourceMappingURL=error.js.map
@@ -1,10 +1,11 @@
1
- import type { ExecutableStep, ListCapableStep } from "../step.js";
1
+ import type { ListCapableStep, Step } from "../step.js";
2
2
  import type { __ItemStep } from "./__item.js";
3
+ import type { ConnectionCapableStep, ItemsStep } from "./connection.js";
3
4
  import type { __ListTransformStep, ListTransformItemPlanCallback } from "./listTransform.js";
4
5
  export type FilterPlanMemo = unknown[];
5
6
  /**
6
7
  * Filters a list plan to only include entries for which the `filterCallback`
7
8
  * plan results in a truthy value.
8
9
  */
9
- export declare function filter<TListStep extends ExecutableStep<readonly any[]>, TItemStep extends ExecutableStep<boolean>>(listStep: TListStep, filterCallback: ListTransformItemPlanCallback<TListStep, TItemStep>): __ListTransformStep<TListStep, TItemStep, FilterPlanMemo, TListStep extends ListCapableStep<any, any> ? ReturnType<TListStep["listItem"]> : __ItemStep<any>>;
10
+ export declare function filter<TListStep extends Step<readonly any[]> | ConnectionCapableStep<any, any>, TItemStep extends Step<boolean>>(listStep: TListStep, filterCallback: ListTransformItemPlanCallback<ItemsStep<TListStep>, TItemStep>): __ListTransformStep<TListStep, TItemStep, FilterPlanMemo, TListStep extends ListCapableStep<any, any> ? ReturnType<TListStep["listItem"]> : __ItemStep<any>>;
10
11
  //# sourceMappingURL=filter.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filter = void 0;
3
+ exports.filter = filter;
4
4
  const tslib_1 = require("tslib");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const step_js_1 = require("../step.js");
@@ -28,5 +28,4 @@ function filter(listStep, filterCallback) {
28
28
  meta: `filter:${chalk_1.default.yellow(listStep.id)}${filterCallback.name ? `/${filterCallback.name}` : ""}`,
29
29
  });
30
30
  }
31
- exports.filter = filter;
32
31
  //# sourceMappingURL=filter.js.map
@@ -1,22 +1,23 @@
1
- import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../interfaces.js";
2
- import type { ExecutableStep } from "../step.js";
3
- import { UnbatchedExecutableStep } from "../step.js";
4
- export declare class FirstStep<TData> extends UnbatchedExecutableStep<TData> {
1
+ import type { ExecutionDetails, GrafastResultsList, UnbatchedExecutionExtra } from "../interfaces.js";
2
+ import type { Step } from "../step.js";
3
+ import { UnbatchedStep } from "../step.js";
4
+ import type { ConnectionCapableStep } from "./connection.js";
5
+ export declare class FirstStep<TData> extends UnbatchedStep<TData> {
5
6
  static $$export: {
6
7
  moduleName: string;
7
8
  exportName: string;
8
9
  };
9
10
  isSyncAndSafe: boolean;
10
11
  allowMultipleOptimizations: boolean;
11
- constructor(parentPlan: ExecutableStep<ReadonlyArray<TData>>);
12
- execute(count: number, values: GrafastValuesList<[ReadonlyArray<TData>]>): GrafastResultsList<TData>;
13
- unbatchedExecute(_extra: ExecutionExtra, list: any[]): any;
12
+ constructor(parentPlan: Step<ReadonlyArray<TData>> | ConnectionCapableStep<Step<TData>, any>);
13
+ execute({ indexMap, values: [values0], }: ExecutionDetails<[ReadonlyArray<TData>]>): GrafastResultsList<TData>;
14
+ unbatchedExecute(_extra: UnbatchedExecutionExtra, list: any[]): any;
14
15
  deduplicate(peers: FirstStep<TData>[]): FirstStep<TData>[];
15
- optimize(): ExecutableStep<any> | this;
16
+ optimize(): any;
16
17
  }
17
18
  /**
18
19
  * A plan that resolves to the first entry in the list returned by the given
19
20
  * plan.
20
21
  */
21
- export declare function first<TData>(plan: ExecutableStep<ReadonlyArray<TData>>): FirstStep<TData>;
22
+ export declare function first<TData>(plan: Step<ReadonlyArray<TData>> | ConnectionCapableStep<Step<TData>, any>): FirstStep<TData>;
22
23
  //# sourceMappingURL=first.d.ts.map
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.first = exports.FirstStep = void 0;
3
+ exports.FirstStep = void 0;
4
+ exports.first = first;
4
5
  const step_js_1 = require("../step.js");
6
+ const connection_js_1 = require("./connection.js");
5
7
  const list_js_1 = require("./list.js");
6
- class FirstStep extends step_js_1.UnbatchedExecutableStep {
8
+ class FirstStep extends step_js_1.UnbatchedStep {
7
9
  static { this.$$export = {
8
10
  moduleName: "grafast",
9
11
  exportName: "FirstStep",
@@ -12,15 +14,10 @@ class FirstStep extends step_js_1.UnbatchedExecutableStep {
12
14
  super();
13
15
  this.isSyncAndSafe = true;
14
16
  this.allowMultipleOptimizations = true;
15
- this.addDependency(parentPlan);
17
+ this.addDependency((0, connection_js_1.itemsOrStep)(parentPlan));
16
18
  }
17
- execute(count, values) {
18
- const result = [];
19
- const dep = values[0];
20
- for (let i = 0; i < count; i++) {
21
- result[i] = dep[i]?.[0];
22
- }
23
- return result;
19
+ execute({ indexMap, values: [values0], }) {
20
+ return indexMap((i) => values0.at(i)?.[0]);
24
21
  }
25
22
  unbatchedExecute(_extra, list) {
26
23
  return list?.[0];
@@ -32,7 +29,7 @@ class FirstStep extends step_js_1.UnbatchedExecutableStep {
32
29
  const parent = this.getDep(0);
33
30
  // The first of a list plan is just the first dependency of the list plan.
34
31
  if (parent instanceof list_js_1.ListStep) {
35
- return parent.getDep(0);
32
+ return parent.first();
36
33
  }
37
34
  return this;
38
35
  }
@@ -43,7 +40,6 @@ exports.FirstStep = FirstStep;
43
40
  * plan.
44
41
  */
45
42
  function first(plan) {
46
- return new FirstStep(plan);
43
+ return plan.operationPlan.cacheStep(plan, "GrafastInternal:first()", "", () => new FirstStep(plan));
47
44
  }
48
- exports.first = first;
49
45
  //# sourceMappingURL=first.js.map
@@ -1,77 +1,4 @@
1
- import type { GraphQLFieldResolver, GraphQLNullableType, GraphQLOutputType, GraphQLResolveInfo } from "graphql";
2
- import type { __ItemStep, ObjectStep } from "../index.js";
3
- import type { ExecutionExtra, GrafastResultsList, GrafastResultStreamList, GrafastValuesList } from "../interfaces.js";
4
- import type { PolymorphicStep } from "../step.js";
5
- import { ExecutableStep, UnbatchedExecutableStep } from "../step.js";
6
- type ResolveInfoBase = Omit<GraphQLResolveInfo, "path" | "rootValue" | "variableValues">;
7
- /**
8
- * Calls the given GraphQL resolver for each input - emulates GraphQL
9
- * resolution.
10
- *
11
- * @internal
12
- */
13
- export declare class GraphQLResolverStep extends UnbatchedExecutableStep {
14
- private resolver;
15
- private subscriber;
16
- private resolveInfoBase;
17
- private returnContextAndResolveInfo;
18
- static $$export: {
19
- moduleName: string;
20
- exportName: string;
21
- };
22
- isSyncAndSafe: boolean;
23
- allowMultipleOptimizations: boolean;
24
- private planDep;
25
- private argsDep;
26
- private contextDep;
27
- private variableValuesDep;
28
- private rootValueDep;
29
- /** root fields can have null parent */
30
- private isNotRoot;
31
- constructor(resolver: (GraphQLFieldResolver<any, any> & {
32
- displayName?: string;
33
- }) | null | undefined, subscriber: (GraphQLFieldResolver<any, any> & {
34
- displayName?: string;
35
- }) | null | undefined, $plan: ExecutableStep, $args: ObjectStep, resolveInfoBase: ResolveInfoBase, returnContextAndResolveInfo?: boolean);
36
- toStringMeta(): string | null;
37
- deduplicate(peers: GraphQLResolverStep[]): GraphQLResolverStep[];
38
- unbatchedExecute(_extra: ExecutionExtra, source: any, args: any, context: any, variableValues: any, rootValue: any): any;
39
- unbatchedStream(_extra: ExecutionExtra, source: any, args: any, context: any, variableValues: any, rootValue: any): any;
40
- stream(count: number, values: ReadonlyArray<GrafastValuesList<any>>, extra: ExecutionExtra): Promise<GrafastResultStreamList<any>>;
41
- }
42
- /** @internal */
43
- export declare class GraphQLItemHandler extends ExecutableStep implements PolymorphicStep {
44
- static $$export: {
45
- moduleName: string;
46
- exportName: string;
47
- };
48
- private abstractType?;
49
- private nullableInnerType;
50
- isSyncAndSafe: boolean;
51
- constructor($parent: ExecutableStep, nullableType: GraphQLNullableType & GraphQLOutputType);
52
- planForType(): this;
53
- listItem($item: __ItemStep<any>): GraphQLItemHandler;
54
- /**
55
- * Akin to graphql-js' completeAbstractValue... but just the typeName
56
- * resolution part.
57
- */
58
- private figureOutTheTypeOf;
59
- private actuallyWrapData;
60
- private polymorphicWrapData;
61
- wrapListData(data: unknown, context: unknown, resolveInfo: GraphQLResolveInfo): ({
62
- data: {};
63
- context: unknown;
64
- resolveInfo: GraphQLResolveInfo;
65
- } | null | undefined)[] | null;
66
- execute(_count: number, values: [GrafastValuesList<any>]): GrafastResultsList<any>;
67
- }
68
- export declare function graphqlItemHandler($item: ExecutableStep, nullableType: GraphQLNullableType & GraphQLOutputType): GraphQLItemHandler;
69
- /**
70
- * Emulates what GraphQL does when calling a resolver, including handling of
71
- * polymorphism.
72
- *
73
- * @internal
74
- */
75
- export declare function graphqlResolver(resolver: GraphQLFieldResolver<any, any> | null | undefined, subscriber: GraphQLFieldResolver<any, any> | null | undefined, $step: ExecutableStep, $args: ObjectStep, resolveInfoBase: ResolveInfoBase): ExecutableStep;
76
- export {};
1
+ import type { GraphQLNullableType, GraphQLOutputType } from "graphql";
2
+ import { Step } from "../step.js";
3
+ export declare function graphqlItemHandler($item: Step, nullableType: GraphQLNullableType & GraphQLOutputType): GraphQLItemHandler;
77
4
  //# sourceMappingURL=graphqlResolver.d.ts.map
@@ -1,18 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.graphqlResolver = exports.graphqlItemHandler = exports.GraphQLItemHandler = exports.GraphQLResolverStep = void 0;
3
+ exports.GraphQLItemHandler = exports.GraphQLResolverStep = void 0;
4
+ exports.graphqlItemHandler = graphqlItemHandler;
5
+ exports.graphqlResolver = graphqlResolver;
4
6
  const tslib_1 = require("tslib");
5
7
  const graphql = tslib_1.__importStar(require("graphql"));
8
+ const iterall_1 = require("iterall");
6
9
  const index_js_1 = require("../index.js");
7
10
  const polymorphic_js_1 = require("../polymorphic.js");
8
11
  const step_js_1 = require("../step.js");
9
12
  const utils_js_1 = require("../utils.js");
10
- const { defaultTypeResolver, getNamedType, getNullableType, isAbstractType, isListType, } = graphql;
13
+ const { defaultTypeResolver, getNamedType, getNullableType, isAbstractType, isListType, isNonNullType, } = graphql;
11
14
  function dcr(data, // but not a promise
12
15
  context, resolveInfo) {
13
16
  if (data == null) {
14
17
  return data;
15
18
  }
19
+ else if (data instanceof Error) {
20
+ return (0, index_js_1.flagError)(data);
21
+ }
22
+ else if ((0, utils_js_1.isPromiseLike)(data)) {
23
+ return data.then((data) => dcr(data, context, resolveInfo));
24
+ }
25
+ if ((0, iterall_1.isIterable)(data)) {
26
+ const list = Array.isArray(data) ? data : [...data];
27
+ if (list.some(utils_js_1.isPromiseLike)) {
28
+ const resolved = Promise.all(list.map((entry) => (0, utils_js_1.isPromiseLike)(entry) ? entry.then(null, index_js_1.flagError) : entry));
29
+ // TODO: this does recursion which is inefficient and also incorrect. We
30
+ // should only traverse as deep as the GraphQL type has lists.
31
+ return dcr(resolved, context, resolveInfo);
32
+ }
33
+ }
34
+ // TODO: support async iterables
16
35
  return { data, context, resolveInfo };
17
36
  }
18
37
  /**
@@ -21,7 +40,7 @@ context, resolveInfo) {
21
40
  *
22
41
  * @internal
23
42
  */
24
- class GraphQLResolverStep extends step_js_1.UnbatchedExecutableStep {
43
+ class GraphQLResolverStep extends step_js_1.UnbatchedStep {
25
44
  static { this.$$export = {
26
45
  moduleName: "grafast",
27
46
  exportName: "GraphQLResolverStep",
@@ -52,75 +71,54 @@ class GraphQLResolverStep extends step_js_1.UnbatchedExecutableStep {
52
71
  this.subscriber?.name ||
53
72
  null);
54
73
  }
55
- deduplicate(peers) {
56
- return peers.filter((peer) => peer.resolver === this.resolver && peer.subscriber === this.subscriber);
57
- }
58
- unbatchedExecute(_extra, source, args, context, variableValues, rootValue) {
59
- if (this.isNotRoot && source == null) {
60
- return source;
61
- }
62
- const resolveInfo = Object.assign(Object.create(this.resolveInfoBase), {
63
- variableValues,
64
- rootValue,
65
- path: {
66
- typename: this.resolveInfoBase.parentType.name,
67
- key: this.resolveInfoBase.fieldName,
68
- // ENHANCE: add full support for path (requires runtime indexes)
69
- prev: undefined,
70
- },
71
- });
72
- const data = this.resolver?.(source, args, context, resolveInfo);
73
- if (this.returnContextAndResolveInfo) {
74
- if ((0, utils_js_1.isPromiseLike)(data)) {
75
- return data.then((data) => dcr(data, context, resolveInfo));
74
+ unbatchedExecute(extra, source, args, context, variableValues, rootValue) {
75
+ if (!extra.stream) {
76
+ if (this.isNotRoot && source == null) {
77
+ return source;
76
78
  }
77
- else {
79
+ const resolveInfo = Object.assign(Object.create(this.resolveInfoBase), {
80
+ variableValues,
81
+ rootValue,
82
+ path: {
83
+ typename: this.resolveInfoBase.parentType.name,
84
+ key: this.resolveInfoBase.fieldName,
85
+ // ENHANCE: add full support for path (requires runtime indexes)
86
+ prev: undefined,
87
+ },
88
+ });
89
+ const data = this.resolver?.(source, args, context, resolveInfo);
90
+ if (this.returnContextAndResolveInfo) {
78
91
  return dcr(data, context, resolveInfo);
79
92
  }
93
+ else {
94
+ return flagErrorIfErrorAsync(data);
95
+ }
80
96
  }
81
97
  else {
82
- return data;
83
- }
84
- }
85
- unbatchedStream(_extra, source, args, context, variableValues, rootValue) {
86
- if (this.isNotRoot) {
87
- return Promise.reject(new Error(`Invalid non-root subscribe`));
88
- }
89
- if (this.subscriber == null) {
90
- return Promise.reject(new Error(`Cannot subscribe to field`));
91
- }
92
- if (this.returnContextAndResolveInfo) {
93
- return Promise.reject(new Error(`Subscription with returnContextAndResolveInfo is not supported`));
94
- }
95
- const resolveInfo = Object.assign(Object.create(this.resolveInfoBase), {
96
- // ENHANCE: add support for path
97
- variableValues,
98
- rootValue,
99
- });
100
- const data = this.subscriber(source, args, context, resolveInfo);
101
- return data;
102
- }
103
- async stream(count, values, extra) {
104
- const results = [];
105
- const depCount = this.dependencies.length;
106
- for (let i = 0; i < count; i++) {
107
- try {
108
- const tuple = [];
109
- for (let j = 0; j < depCount; j++) {
110
- tuple[j] = values[j][i];
111
- }
112
- results[i] = this.unbatchedStream(extra, ...tuple);
98
+ if (this.isNotRoot) {
99
+ return Promise.reject(new Error(`Invalid non-root subscribe`));
100
+ }
101
+ if (this.subscriber == null) {
102
+ return Promise.reject(new Error(`Cannot subscribe to field`));
113
103
  }
114
- catch (e) {
115
- results[i] = e instanceof Error ? e : Promise.reject(e);
104
+ if (this.returnContextAndResolveInfo) {
105
+ return Promise.reject(new Error(`Subscription with returnContextAndResolveInfo is not supported`));
116
106
  }
107
+ const resolveInfo = Object.assign(Object.create(this.resolveInfoBase), {
108
+ // ENHANCE: add support for path
109
+ variableValues,
110
+ rootValue,
111
+ });
112
+ // TODO: we also need to call the resolver on each result?
113
+ const data = this.subscriber(source, args, context, resolveInfo);
114
+ // TODO: should apply flagErrorIfError to each value data yields
115
+ return flagErrorIfErrorAsync(data);
117
116
  }
118
- return results;
119
117
  }
120
118
  }
121
119
  exports.GraphQLResolverStep = GraphQLResolverStep;
122
120
  /** @internal */
123
- class GraphQLItemHandler extends step_js_1.ExecutableStep {
121
+ class GraphQLItemHandler extends step_js_1.Step {
124
122
  static { this.$$export = {
125
123
  moduleName: "grafast",
126
124
  exportName: "GraphQLItemHandler",
@@ -131,7 +129,13 @@ class GraphQLItemHandler extends step_js_1.ExecutableStep {
131
129
  this.isSyncAndSafe = false;
132
130
  this.addDependency($parent);
133
131
  if (isListType(nullableType)) {
134
- this.nullableInnerType = nullableType.ofType;
132
+ const innerType = nullableType.ofType;
133
+ if (isNonNullType(innerType)) {
134
+ this.nullableInnerType = innerType.ofType;
135
+ }
136
+ else {
137
+ this.nullableInnerType = innerType;
138
+ }
135
139
  }
136
140
  else {
137
141
  if (!isAbstractType(nullableType)) {
@@ -196,13 +200,14 @@ class GraphQLItemHandler extends step_js_1.ExecutableStep {
196
200
  }
197
201
  return data.map((data) => dcr(data, context, resolveInfo));
198
202
  }
199
- execute(_count, values) {
203
+ execute({ indexMap, values: [values0], }) {
200
204
  if (this.abstractType !== undefined) {
201
- return values[0].map((data) => {
205
+ return indexMap((i) => {
206
+ const data = values0.at(i);
202
207
  if (data == null) {
203
208
  return data;
204
209
  }
205
- if ((0, utils_js_1.isPromiseLike)(data.data)) {
210
+ else if ((0, utils_js_1.isPromiseLike)(data.data)) {
206
211
  return data.data.then((resolvedData) => this.polymorphicWrapData(resolvedData, data.context, data.resolveInfo));
207
212
  }
208
213
  else {
@@ -211,16 +216,19 @@ class GraphQLItemHandler extends step_js_1.ExecutableStep {
211
216
  });
212
217
  }
213
218
  else if (this.nullableInnerType != null) {
214
- return values[0].map((d) => {
219
+ return indexMap((i) => {
220
+ const d = values0.at(i);
215
221
  if (d == null) {
216
222
  return null;
217
223
  }
218
- const { data, context, resolveInfo } = d;
219
- if ((0, utils_js_1.isPromiseLike)(data)) {
220
- return data.then((data) => this.wrapListData(data, context, resolveInfo));
221
- }
222
224
  else {
223
- return this.wrapListData(data, context, resolveInfo);
225
+ const { data, context, resolveInfo } = d;
226
+ if ((0, utils_js_1.isPromiseLike)(data)) {
227
+ return data.then((data) => this.wrapListData(data, context, resolveInfo));
228
+ }
229
+ else {
230
+ return this.wrapListData(data, context, resolveInfo);
231
+ }
224
232
  }
225
233
  });
226
234
  }
@@ -233,7 +241,6 @@ exports.GraphQLItemHandler = GraphQLItemHandler;
233
241
  function graphqlItemHandler($item, nullableType) {
234
242
  return new GraphQLItemHandler($item, nullableType);
235
243
  }
236
- exports.graphqlItemHandler = graphqlItemHandler;
237
244
  /**
238
245
  * Emulates what GraphQL does when calling a resolver, including handling of
239
246
  * polymorphism.
@@ -256,5 +263,15 @@ function graphqlResolver(resolver, subscriber, $step, $args, resolveInfoBase) {
256
263
  return $resolverResult;
257
264
  }
258
265
  }
259
- exports.graphqlResolver = graphqlResolver;
266
+ function flagErrorIfError(data) {
267
+ return data instanceof Error ? (0, index_js_1.flagError)(data) : data;
268
+ }
269
+ function flagErrorIfErrorAsync(data) {
270
+ if ((0, utils_js_1.isPromiseLike)(data)) {
271
+ return data.then(flagErrorIfError);
272
+ }
273
+ else {
274
+ return flagErrorIfError(data);
275
+ }
276
+ }
260
277
  //# sourceMappingURL=graphqlResolver.js.map
@@ -1,4 +1,5 @@
1
- import type { ExecutableStep } from "../step.js";
1
+ import type { Step } from "../step.js";
2
+ import type { ConnectionCapableStep, ItemsStep } from "./connection.js";
2
3
  import type { __ListTransformStep, ListTransformItemPlanCallback } from "./listTransform.js";
3
4
  export type GroupByPlanMemo = Map<unknown, unknown[]>;
4
5
  /**
@@ -7,5 +8,5 @@ export type GroupByPlanMemo = Map<unknown, unknown[]>;
7
8
  * keys and the values are lists of the original entries that match these
8
9
  * grouping keys.
9
10
  */
10
- export declare function groupBy<TListStep extends ExecutableStep<readonly any[]>, TItemStep extends ExecutableStep<number>>(listStep: TListStep, mapper: ListTransformItemPlanCallback<TListStep, TItemStep>): __ListTransformStep<TListStep, TItemStep, GroupByPlanMemo, any>;
11
+ export declare function groupBy<TListStep extends Step<readonly any[]> | ConnectionCapableStep<any, any>, TItemStep extends Step<number>>(listStep: TListStep, mapper: ListTransformItemPlanCallback<ItemsStep<TListStep>, TItemStep>): __ListTransformStep<TListStep, TItemStep, GroupByPlanMemo, any>;
11
12
  //# sourceMappingURL=groupBy.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.groupBy = void 0;
3
+ exports.groupBy = groupBy;
4
4
  const tslib_1 = require("tslib");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const step_js_1 = require("../step.js");
@@ -36,5 +36,4 @@ function groupBy(listStep, mapper) {
36
36
  meta: `groupBy:${chalk_1.default.yellow(listStep.id)}${mapper.name ? `/${mapper.name}` : ""}`,
37
37
  });
38
38
  }
39
- exports.groupBy = groupBy;
40
39
  //# sourceMappingURL=groupBy.js.map
@@ -1,12 +1,16 @@
1
- import type { OperationPlan } from "../index.js";
1
+ import type { __TrackedValueStep, OperationPlan } from "../index.js";
2
2
  import type { __ValueStep } from "./__value.js";
3
3
  export declare function operationPlan(): OperationPlan;
4
4
  export declare function context<TContext extends Grafast.Context = Grafast.Context>(): __ValueStep<TContext>;
5
+ export declare function rootValue(): __ValueStep<Record<string, any>>;
6
+ export declare function trackedContext<TContext extends Grafast.Context = Grafast.Context>(): __TrackedValueStep<TContext>;
7
+ export declare function trackedRootValue(): __TrackedValueStep<Record<string, any>>;
5
8
  /**
6
9
  * Turns on debug mode, calls the callback, and then turns debug mode back off
7
10
  * again.
8
11
  */
9
12
  export declare function debugPlans<T>(callback: () => T): T;
13
+ export { __FlagStep, assertNotNull, inhibitOnNull, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED, } from "./__flag.js";
10
14
  export { access, AccessStep } from "./access.js";
11
15
  export { assertEdgeCapableStep, assertPageInfoCapableStep, connection, ConnectionCapableStep, ConnectionStep, EdgeCapableStep, EdgeStep, PageInfoCapableStep, } from "./connection.js";
12
16
  export { constant, ConstantStep } from "./constant.js";
@@ -20,20 +24,25 @@ export { last, LastStep } from "./last.js";
20
24
  export { list, ListStep } from "./list.js";
21
25
  export { listen, ListenStep } from "./listen.js";
22
26
  export { __ListTransformStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, } from "./listTransform.js";
23
- export { makeDecodeNodeId, node, NodeStep, specFromNodeId } from "./node.js";
27
+ export { makeDecodeNodeId, makeDecodeNodeIdRuntime, node, nodeIdFromNode, NodeStep, specFromNodeId, } from "./node.js";
24
28
  export { object, ObjectPlanMeta, ObjectStep } from "./object.js";
25
29
  export { partitionByIndex } from "./partitionByIndex.js";
26
30
  export { ActualKeyByDesiredKey, remapKeys, RemapKeysStep, } from "./remapKeys.js";
27
31
  export { reverse, reverseArray, ReverseStep } from "./reverse.js";
28
- export { setter, SetterCapableStep, SetterStep } from "./setter.js";
32
+ export { createObjectAndApplyChildren, Setter, setter, SetterCapable, } from "./setter.js";
33
+ export { sideEffect, SideEffectStep } from "./sideEffect.js";
29
34
  export { __InputListStep } from "./__inputList.js";
30
35
  export { __InputObjectStep, __InputObjectStepWithDollars, } from "./__inputObject.js";
31
36
  export { __InputStaticLeafStep } from "./__inputStaticLeaf.js";
32
37
  export { __ItemStep } from "./__item.js";
33
38
  export { __TrackedValueStep, __TrackedValueStepWithDollars, } from "./__trackedValue.js";
34
39
  export { __ValueStep } from "./__value.js";
40
+ export { applyInput, ApplyInputStep, assertModifier, isModifier, Modifier, } from "./applyInput.js";
35
41
  export { applyTransforms, ApplyTransformsStep } from "./applyTransforms.js";
42
+ export { bakedInput, bakedInputRuntime, BakedInputStep } from "./bakedInput.js";
43
+ export { condition, ConditionStep } from "./condition.js";
36
44
  export { GraphQLItemHandler, graphqlItemHandler, graphqlResolver, GraphQLResolverStep, } from "./graphqlResolver.js";
37
45
  export { LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, } from "./load.js";
46
+ export { polymorphicBranch, PolymorphicBranchMatcher, PolymorphicBranchMatchers, PolymorphicBranchStep, } from "./polymorphicBranch.js";
38
47
  export { proxy, ProxyStep } from "./proxy.js";
39
48
  //# sourceMappingURL=index.d.ts.map