grafast 0.1.1-beta.23 → 0.1.1-beta.25

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultPlanResolver = void 0;
4
- const access_js_1 = require("../../steps/access.js");
5
- const defaultPlanResolver = ($step, _, info) => (0, access_js_1.get)($step, info.fieldName);
4
+ const get_js_1 = require("../../steps/get.js");
5
+ const defaultPlanResolver = ($step, _, info) => (0, get_js_1.get)($step, info.fieldName);
6
6
  exports.defaultPlanResolver = defaultPlanResolver;
7
7
  //# sourceMappingURL=defaultPlanResolver.js.map
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { DataFromObjectSteps } from "./steps/object.js";
6
6
  type PromiseOrValue<T> = T | Promise<T>;
7
7
  import { exportAs, exportAsMany } from "./exportAs.js";
8
8
  import { grafastPrint } from "./grafastPrint.js";
9
- import { AbstractTypePlan, DeprecatedInputObjectPlan, DeprecatedObjectPlan, EnumPlan, EnumValueConfig, EnumValueInput, FieldPlan, GrafastSchemaConfig, InputFieldPlan, InputObjectPlan, InterfacePlan, makeGrafastSchema, ObjectFieldConfig, ObjectPlan, ScalarPlan, UnionPlan } from "./makeGrafastSchema.js";
9
+ import { AbstractTypePlan, DeprecatedInputObjectPlan, DeprecatedObjectPlan, EnumPlan, EnumValueConfig, EnumValueInput, FieldPlan, GrafastSchemaConfig, InputFieldPlan, InputObjectFieldConfig, InputObjectPlan, InterfacePlan, makeGrafastSchema, ObjectFieldConfig, ObjectPlan, ScalarPlan, UnionPlan } from "./makeGrafastSchema.js";
10
10
  import type { $$cacheByOperation, $$hooked, $$queryCache } from "./constants.js";
11
11
  import { $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$verbatim, DEFAULT_ACCEPT_FLAGS } from "./constants.js";
12
12
  import { defer, Deferred } from "./deferred.js";
@@ -31,7 +31,7 @@ import { stripAnsi } from "./stripAnsi.js";
31
31
  import { subscribe } from "./subscribe.js";
32
32
  import { arrayOfLength, arraysMatch, getEnumValueConfig, getEnumValueConfigs, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, inputObjectFieldSpec, InputObjectTypeSpec, isPromiseLike, mapsMatch, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, objectFieldSpec, objectSpec, ObjectTypeFields, ObjectTypeSpec, recordsMatch, setsMatch, stepADependsOnStepB, stepAMayDependOnStepB, stepAShouldTryAndInlineIntoStepB, stepsAreInSamePhase } from "./utils.js";
33
33
  export { isAsyncIterable } from "iterall";
34
- export { __FlagStep, __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$inhibit, $$verbatim, AbstractTypePlan, AbstractTypePlanner, access, AccessStep, ActualKeyByDesiredKey, applyInput, ApplyInputStep, applyTransforms, ApplyTransformsStep, arrayOfLength, arraysMatch, assertEdgeCapableStep, assertExecutableStep, assertListCapableStep, assertModifier, assertNotNull, assertPageInfoCapableStep, assertStep, bakedInput, bakedInputRuntime, BakedInputStep, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, BatchExecutionValue, coalesce, CoalesceStep, condition, ConditionStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, createObjectAndApplyChildren, DataFromObjectSteps, DataFromStep, debugPlans, DEFAULT_ACCEPT_FLAGS, defaultPlanResolver, defer, Deferred, DeprecatedInputObjectPlan, DeprecatedObjectPlan, each, EdgeCapableStep, EdgeStep, EnumPlan, EnumValueConfig, EnumValueInput, error, ErrorStep, EventCallback, EventMapKey, Step as ExecutableStep, execute, ExecutionDetails, ExecutionDetailsStream, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, ExecutionResults, ExecutionResultValue, ExecutionValue, exportAs, exportAsMany, FieldArg, FieldArgs, FieldInfo, FieldPlan, FieldPlanResolver, filter, FilterPlanMemo, first, FirstStep, flagError, get, getEnumValueConfig, getEnumValueConfigs, getGrafastMiddleware, getNullableInputTypeAtPath, grafast, GrafastArgumentConfig, GrafastExecutionArgs, GrafastFieldConfig, GrafastFieldConfigArgumentMap, grafast as grafastGraphql, grafastSync as grafastGraphqlSync, GrafastInputFieldConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, GrafastPlanJSON, grafastPrint, GrafastResultsList, GrafastResultStreamList, GrafastSchemaConfig, GrafastSubscriber, grafastSync, GrafastValuesList, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, inhibitOnNull, InputFieldPlan, InputObjectFieldApplyResolver, inputObjectFieldSpec, InputObjectPlan, InputObjectTypeBakedInfo, InputObjectTypeBakedResolver, InputObjectTypeSpec, inspect, AbstractTypePlan as InterfaceOrUnionPlans, InterfacePlan, isDev, isExecutableStep, isListCapableStep, isListLikeStep, isModifier, isObjectLikeStep, isPromiseLike, isSafeError, isStep, isUnaryStep, JSONArray, JSONObject, JSONValue, lambda, LambdaStep, last, LastStep, list, ListCapableStep, listen, ListenStep, ListLikeStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, makeDecodeNodeIdRuntime, makeGrafastSchema, mapsMatch, Maybe, Modifier, Multistep, multistep, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, node, NodeIdCodec, nodeIdFromNode, NodeIdHandler, NodeStep, noop, object, ObjectFieldConfig, objectFieldSpec, ObjectLikeStep, ObjectPlan, ObjectPlanMeta, objectSpec, ObjectStep, ObjectTypeFields, ObjectTypeSpec, OperationPlan, operationPlan, PageInfoCapableStep, partitionByIndex, PlanTypeInfo, PromiseOrDirect, proxy, ProxyStep, recordsMatch, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, rootValue, SafeError, ScalarPlan, ScalarPlanResolver, setsMatch, Setter, setter, SetterCapable, sideEffect, SideEffectStep, specFromNodeId, Step, stepADependsOnStepB, stepAMayDependOnStepB, stepAShouldTryAndInlineIntoStepB, StepOptimizeOptions, stepsAreInSamePhase, StepStreamOptions, stringifyPayload, stripAnsi, subscribe, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED, TypedEventEmitter, UnaryExecutionValue, UnbatchedStep as UnbatchedExecutableStep, UnbatchedExecutionExtra, UnbatchedStep, UnionPlan, UnwrapMultistep, };
34
+ export { __FlagStep, __InputListStep, __InputObjectStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __ItemStep, __ListTransformStep, __TrackedValueStep, __TrackedValueStepWithDollars, __ValueStep, $$bypassGraphQL, $$eventEmitter, $$extensions, $$idempotent, $$inhibit, $$verbatim, AbstractTypePlan, AbstractTypePlanner, access, AccessStep, ActualKeyByDesiredKey, applyInput, ApplyInputStep, applyTransforms, ApplyTransformsStep, arrayOfLength, arraysMatch, assertEdgeCapableStep, assertExecutableStep, assertListCapableStep, assertModifier, assertNotNull, assertPageInfoCapableStep, assertStep, bakedInput, bakedInputRuntime, BakedInputStep, BaseEventMap, BaseGraphQLArguments, BaseGraphQLRootValue, BaseGraphQLVariables, BatchExecutionValue, coalesce, CoalesceStep, condition, ConditionStep, connection, ConnectionCapableStep, ConnectionStep, constant, ConstantStep, context, createObjectAndApplyChildren, DataFromObjectSteps, DataFromStep, debugPlans, DEFAULT_ACCEPT_FLAGS, defaultPlanResolver, defer, Deferred, DeprecatedInputObjectPlan, DeprecatedObjectPlan, each, EdgeCapableStep, EdgeStep, EnumPlan, EnumValueConfig, EnumValueInput, error, ErrorStep, EventCallback, EventMapKey, Step as ExecutableStep, execute, ExecutionDetails, ExecutionDetailsStream, ExecutionEventEmitter, ExecutionEventMap, ExecutionExtra, ExecutionResults, ExecutionResultValue, ExecutionValue, exportAs, exportAsMany, FieldArg, FieldArgs, FieldInfo, FieldPlan, FieldPlanResolver, filter, FilterPlanMemo, first, FirstStep, flagError, get, getEnumValueConfig, getEnumValueConfigs, getGrafastMiddleware, getNullableInputTypeAtPath, grafast, GrafastArgumentConfig, GrafastExecutionArgs, GrafastFieldConfig, GrafastFieldConfigArgumentMap, grafast as grafastGraphql, grafastSync as grafastGraphqlSync, GrafastInputFieldConfig, GrafastInputFieldConfigMap, GrafastInputObjectType, GrafastObjectType, GrafastPlanJSON, grafastPrint, GrafastResultsList, GrafastResultStreamList, GrafastSchemaConfig, GrafastSubscriber, grafastSync, GrafastValuesList, graphqlResolver, GraphQLResolverStep, groupBy, GroupByPlanMemo, inhibitOnNull, InputFieldPlan, InputObjectFieldApplyResolver, InputObjectFieldConfig, inputObjectFieldSpec, InputObjectPlan, InputObjectTypeBakedInfo, InputObjectTypeBakedResolver, InputObjectTypeSpec, inspect, AbstractTypePlan as InterfaceOrUnionPlans, InterfacePlan, isDev, isExecutableStep, isListCapableStep, isListLikeStep, isModifier, isObjectLikeStep, isPromiseLike, isSafeError, isStep, isUnaryStep, JSONArray, JSONObject, JSONValue, lambda, LambdaStep, last, LastStep, list, ListCapableStep, listen, ListenStep, ListLikeStep, ListStep, listTransform, ListTransformItemPlanCallback, ListTransformOptions, ListTransformReduce, LoadedRecordStep, loadMany, LoadManyCallback, loadManyCallback, loadOne, LoadOneCallback, loadOneCallback, LoadOptions, LoadStep, makeDecodeNodeId, makeDecodeNodeIdRuntime, makeGrafastSchema, mapsMatch, Maybe, Modifier, Multistep, multistep, newGrafastFieldConfigBuilder, newInputObjectTypeBuilder, newObjectTypeBuilder, node, NodeIdCodec, nodeIdFromNode, NodeIdHandler, NodeStep, noop, object, ObjectFieldConfig, objectFieldSpec, ObjectLikeStep, ObjectPlan, ObjectPlanMeta, objectSpec, ObjectStep, ObjectTypeFields, ObjectTypeSpec, OperationPlan, operationPlan, PageInfoCapableStep, partitionByIndex, PlanTypeInfo, PromiseOrDirect, proxy, ProxyStep, recordsMatch, remapKeys, RemapKeysStep, reverse, reverseArray, ReverseStep, rootValue, SafeError, ScalarPlan, ScalarPlanResolver, setsMatch, Setter, setter, SetterCapable, sideEffect, SideEffectStep, specFromNodeId, Step, stepADependsOnStepB, stepAMayDependOnStepB, stepAShouldTryAndInlineIntoStepB, StepOptimizeOptions, stepsAreInSamePhase, StepStreamOptions, stringifyPayload, stripAnsi, subscribe, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED, TypedEventEmitter, UnaryExecutionValue, UnbatchedStep as UnbatchedExecutableStep, UnbatchedExecutionExtra, UnbatchedStep, UnionPlan, UnwrapMultistep, };
35
35
  export { hookArgs } from "./args.js";
36
36
  export { version } from "./version.js";
37
37
  /** @deprecated Renamed to 'applyTransforms' */
@@ -71,6 +71,22 @@ declare global {
71
71
  }
72
72
  interface InputObjectTypeExtensions {
73
73
  baked?: InputObjectTypeBakedResolver;
74
+ /**
75
+ * EXPERIMENTAL!
76
+ *
77
+ * Scope to pass to `.apply()` methods called by `applyInput()` step.
78
+ *
79
+ * IMPORTANT: the scope is only evaluated for the top-level named type
80
+ * that `applyInput()` is applied against, so any type that nests this
81
+ * (e.g. other input objects) needs to ensure they have an `applyScope()`
82
+ * that's compatible; similarly this `applyPlan()` needs to supply values
83
+ * that are compatible with all the descendant input objects, enums and
84
+ * scalars. For this reason we recommend that you return an object with a
85
+ * scoped key that you care about so it's easily merged.
86
+ *
87
+ * @experimental
88
+ */
89
+ applyScope?: () => Step;
74
90
  }
75
91
  interface InputFieldExtensions {
76
92
  apply?: InputObjectFieldApplyResolver<any>;
@@ -130,6 +146,20 @@ declare global {
130
146
  planType?($stepOrSpecifier: Step, info: PlanTypeInfo): AbstractTypePlanner;
131
147
  }
132
148
  interface EnumTypeExtensions {
149
+ /**
150
+ * EXPERIMENTAL!
151
+ *
152
+ * Scope to pass to `.apply()` methods called by `applyInput()` step.
153
+ *
154
+ * IMPORTANT: the scope is only evaluated for the top-level named type
155
+ * that `applyInput()` is applied against, so any type that nests this
156
+ * (e.g. input objects) needs to ensure they have an `applyScope()`
157
+ * that's compatible. For this reason we recommend that you return an
158
+ * object with a scoped key that you care about so it's easily merged.
159
+ *
160
+ * @experimental
161
+ */
162
+ applyScope?: () => Step;
133
163
  }
134
164
  interface EnumValueExtensions {
135
165
  /**
@@ -143,6 +173,20 @@ declare global {
143
173
  interface ScalarTypeExtensions {
144
174
  plan?: ScalarPlanResolver;
145
175
  inputPlan?: ScalarInputPlanResolver;
176
+ /**
177
+ * EXPERIMENTAL!
178
+ *
179
+ * Scope to pass to `.apply()` methods called by `applyInput()` step.
180
+ *
181
+ * IMPORTANT: the scope is only evaluated for the top-level named type
182
+ * that `applyInput()` is applied against, so any type that nests this
183
+ * (e.g. input objects) needs to ensure they have an `applyScope()`
184
+ * that's compatible. For this reason we recommend that you return an
185
+ * object with a scoped key that you care about so it's easily merged.
186
+ *
187
+ * @experimental
188
+ */
189
+ applyScope?: () => Step;
146
190
  /**
147
191
  * Set true if `serialize(serialize(foo)) === serialize(foo)` for all foo
148
192
  */
@@ -1,6 +1,6 @@
1
1
  import type EventEmitter from "eventemitter3";
2
2
  import type { Middleware } from "graphile-config";
3
- import type { ASTNode, ExecutionArgs, FragmentDefinitionNode, GraphQLArgs, GraphQLArgument, GraphQLArgumentConfig, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLObjectType, GraphQLOutputType, GraphQLScalarType, GraphQLSchema, GraphQLUnionType, OperationDefinitionNode, Source, ValueNode, VariableNode } from "graphql";
3
+ import type { ASTNode, ExecutionArgs, FragmentDefinitionNode, GraphQLArgs, GraphQLArgument, GraphQLArgumentConfig, GraphQLEnumValue, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLObjectType, GraphQLOutputType, GraphQLScalarType, GraphQLSchema, GraphQLUnionType, OperationDefinitionNode, Source, ValueNode, VariableNode } from "graphql";
4
4
  import type { ObjMap } from "graphql/jsutils/ObjMap.js";
5
5
  import type { $$streamMore, $$timeout, $$ts, ExecutionEntryFlags } from "./constants.js";
6
6
  import type { Constraint } from "./constraints.js";
@@ -158,11 +158,12 @@ export interface FieldInfo {
158
158
  * executions.
159
159
  */
160
160
  export type FieldPlanResolver<TParentStep extends Step = Step, TArgs extends BaseGraphQLArguments = any, TResultStep extends Step = Step> = ($parentPlan: TParentStep, args: FieldArgs<TArgs>, info: FieldInfo) => TResultStep | null;
161
- export type InputObjectFieldApplyResolver<TParent = any, TData = any> = (target: TParent, input: TData, // Don't use unknown here, otherwise users can't easily cast it
161
+ export type InputObjectFieldApplyResolver<TParent = any, TData = any, TScope = any> = (target: TParent, input: TData, // Don't use unknown here, otherwise users can't easily cast it
162
162
  info: {
163
163
  schema: GraphQLSchema;
164
164
  fieldName: string;
165
165
  field: GraphQLInputField;
166
+ scope: TScope;
166
167
  }) => any;
167
168
  export type InputObjectTypeBakedInfo = {
168
169
  schema: GraphQLSchema;
@@ -199,7 +200,10 @@ export type ScalarInputPlanResolver<TResultStep extends Step = Step> = ($inputVa
199
200
  *
200
201
  * @experimental
201
202
  */
202
- export type EnumValueApplyResolver<TParent = any> = (parent: TParent) => void;
203
+ export type EnumValueApplyResolver<TParent = any, TScope = any> = (parent: TParent, info: {
204
+ value: GraphQLEnumValue;
205
+ scope: TScope;
206
+ }) => void;
203
207
  /**
204
208
  * Basically GraphQLFieldConfig but with an easy to access `plan` method.
205
209
  */
@@ -118,11 +118,11 @@ export type EnumValueInput = EnumValueApplyResolver | EnumValueConfig | string |
118
118
  /**
119
119
  * The values/configs for the entries in a GraphQL enum type.
120
120
  */
121
- export type EnumPlan = {
121
+ export interface EnumPlan {
122
122
  values?: {
123
123
  [enumValueName: string]: EnumValueInput | undefined;
124
124
  };
125
- };
125
+ }
126
126
  /**
127
127
  * A map from GraphQL named type to the config for that type.
128
128
  *
@@ -47,6 +47,9 @@ export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLI
47
47
  execute({ count, values: [values0], }: ExecutionDetails<[TData]>): GrafastResultsList<TData>;
48
48
  unbatchedExecute(_extra: UnbatchedExecutionExtra, v: TData): TData;
49
49
  private getValuePlan;
50
+ __inferGet?: {
51
+ [TAttribute in keyof TData & string]: __TrackedValueStepWithDollars<TData[TAttribute], TInputType extends GraphQLInputObjectType ? ReturnType<TInputType["getFields"]>[TAttribute]["type"] : undefined>;
52
+ };
50
53
  /**
51
54
  * Get the named property of an object.
52
55
  */
@@ -17,6 +17,9 @@ export declare class __ValueStep<TData> extends Step<TData> {
17
17
  planJSONExtra(): undefined | Record<string, JSONValue>;
18
18
  toStringMeta(): string | null;
19
19
  execute(): GrafastResultsList<TData>;
20
+ __inferGet?: {
21
+ [TAttr in keyof TData]: AccessStep<TData[TAttr]>;
22
+ };
20
23
  get<TAttr extends keyof TData>(attrName: TAttr): AccessStep<TData[TAttr]>;
21
24
  at<TIndex extends keyof TData>(index: TIndex): AccessStep<TData[TIndex]>;
22
25
  }
@@ -22,6 +22,9 @@ export declare class AccessStep<TData> extends UnbatchedStep<TData> {
22
22
  constructor(parentPlan: Step<unknown>, path: (string | number | symbol)[], fallback?: any | undefined);
23
23
  toStringMeta(): string;
24
24
  getParentStep(): Step<any> | import("./__flag.js").__FlagStep<Step<any>>;
25
+ __inferGet?: {
26
+ [TAttr in keyof TData]: AccessStep<TData[TAttr]>;
27
+ };
25
28
  /**
26
29
  * Get the named property of an object.
27
30
  */
@@ -40,20 +43,4 @@ export declare class AccessStep<TData> extends UnbatchedStep<TData> {
40
43
  * falling back to `fallback` if it were null-ish.
41
44
  */
42
45
  export declare function access<TData>(parentPlan: Step<unknown>, rawPath?: (string | number | symbol)[] | string | number | symbol, fallback?: any): AccessStep<TData>;
43
- type StepGetReturn<TStep, TAttr extends string> = TStep extends {
44
- get: (attr: TAttr) => infer U;
45
- } ? U : TStep extends {
46
- get: (attr: string) => infer U;
47
- } ? U : never;
48
- type StepGetKeys<TStep extends Step> = TStep extends {
49
- get(attr: infer U): any;
50
- } ? U : TStep extends Step<infer UData> ? UData extends Record<string, any> ? keyof UData : string : never;
51
- type StepAccessKey<TStep extends Step, TAttr extends StepGetKeys<TStep> & string> = TStep extends {
52
- get(attr: any): any;
53
- } ? StepGetReturn<TStep, TAttr> : TStep extends Step<infer UData> ? UData extends Record<string, any> ? Step<UData[TAttr]> : Step<any> : never;
54
- /**
55
- * Call `$step.get(attr)` if possible, falling back to `access($step, attr)`.
56
- */
57
- export declare function get<TStep extends Step, TAttr extends StepGetKeys<TStep> & string>($step: TStep, attr: TAttr): StepAccessKey<TStep, TAttr>;
58
- export {};
59
46
  //# sourceMappingURL=access.d.ts.map
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AccessStep = exports.expressionSymbol = void 0;
4
4
  exports.access = access;
5
- exports.get = get;
6
5
  const tslib_1 = require("tslib");
7
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
7
  const tamedevil_1 = tslib_1.__importDefault(require("tamedevil"));
@@ -218,12 +217,4 @@ function access(parentPlan, rawPath, fallback) {
218
217
  }
219
218
  return new AccessStep(parentPlan, path, fallback);
220
219
  }
221
- /**
222
- * Call `$step.get(attr)` if possible, falling back to `access($step, attr)`.
223
- */
224
- function get($step, attr) {
225
- return "get" in $step && typeof $step.get === "function"
226
- ? $step.get(attr)
227
- : access($step, attr);
228
- }
229
220
  //# sourceMappingURL=access.js.map
@@ -13,13 +13,20 @@ export declare class ApplyInputStep<TParent extends object = any, TTarget extend
13
13
  isSyncAndSafe: boolean;
14
14
  allowMultipleOptimizations: boolean;
15
15
  valueDepId: 0;
16
- constructor(inputType: GraphQLInputType, $value: AnyInputStep, getTargetFromParent: ((parent: TParent, inputValue: any) => TTarget | undefined | (() => TTarget)) | undefined);
16
+ scopeDepId: 1 | null;
17
+ constructor(inputType: GraphQLInputType, $value: AnyInputStep, getTargetFromParent: ((parent: TParent, inputValue: any, info: {
18
+ scope: unknown;
19
+ }) => TTarget | undefined | (() => TTarget)) | undefined, $scope?: Step | null);
17
20
  deduplicate(peers: readonly ApplyInputStep[]): ApplyInputStep<any, any>[];
18
21
  optimize(): this | ConstantStep<(parent: TParent) => void>;
19
- unbatchedExecute(extra: UnbatchedExecutionExtra, value: any): (parentThing: TParent) => void;
22
+ unbatchedExecute(extra: UnbatchedExecutionExtra, value: any, scope: unknown): (parentThing: TParent) => void;
20
23
  }
21
- export declare function inputArgsApply<TArg extends object, TTarget extends object = TArg>(schema: GraphQLSchema, inputType: GraphQLInputType, parent: TArg, inputValue: unknown, getTargetFromParent: ((parent: TArg, inputValue: any) => TTarget | undefined | (() => TTarget)) | undefined): void;
22
- export declare function applyInput<TParent extends object = any, TTarget extends object = TParent>(inputType: GraphQLInputType, $value: AnyInputStep, getTargetFromParent?: (parent: TParent, inputValue: any) => TTarget | undefined): ConstantStep<(parent: TParent) => void> | ApplyInputStep<TParent, TTarget>;
24
+ export declare function inputArgsApply<TArg extends object, TTarget extends object = TArg>(schema: GraphQLSchema, inputType: GraphQLInputType, parent: TArg, inputValue: unknown, getTargetFromParent: ((parent: TArg, inputValue: any, info: {
25
+ scope: unknown;
26
+ }) => TTarget | undefined | (() => TTarget)) | undefined, scope: unknown): void;
27
+ export declare function applyInput<TParent extends object = any, TTarget extends object = TParent>(inputType: GraphQLInputType, $value: AnyInputStep, getTargetFromParent?: (parent: TParent, inputValue: any, info: {
28
+ scope: unknown;
29
+ }) => TTarget | undefined): ConstantStep<(parent: TParent) => void> | ApplyInputStep<TParent, TTarget>;
23
30
  /**
24
31
  * Modifiers modify their parent (which may be another modifier or anything
25
32
  * else). First they gather all the requirements from their children (if any)
@@ -18,13 +18,14 @@ class ApplyInputStep extends step_js_1.UnbatchedStep {
18
18
  moduleName: "grafast",
19
19
  exportName: "ApplyInputStep",
20
20
  }; }
21
- constructor(inputType, $value, getTargetFromParent) {
21
+ constructor(inputType, $value, getTargetFromParent, $scope) {
22
22
  super();
23
23
  this.inputType = inputType;
24
24
  this.getTargetFromParent = getTargetFromParent;
25
25
  this.isSyncAndSafe = true;
26
26
  this.allowMultipleOptimizations = true;
27
27
  this.valueDepId = this.addUnaryDependency($value);
28
+ this.scopeDepId = $scope ? this.addUnaryDependency($scope) : null;
28
29
  if (!this._isUnary) {
29
30
  throw new Error(`applyInput() must be unary`);
30
31
  }
@@ -36,30 +37,33 @@ class ApplyInputStep extends step_js_1.UnbatchedStep {
36
37
  }
37
38
  optimize() {
38
39
  const $value = this.getDep(this.valueDepId);
39
- if ($value instanceof constant_js_1.ConstantStep) {
40
+ const $scope = this.scopeDepId === null ? null : this.getDep(this.scopeDepId);
41
+ if ((!$scope || $scope instanceof constant_js_1.ConstantStep) &&
42
+ $value instanceof constant_js_1.ConstantStep) {
40
43
  // Replace myself with a constant!
41
44
  const { operationPlan: { schema }, inputType, getTargetFromParent, } = this;
42
45
  const { data } = $value;
46
+ const scope = $scope?.data;
43
47
  return (0, constant_js_1.constant)(function applyInputConstant(parent) {
44
- inputArgsApply(schema, inputType, parent, data, getTargetFromParent);
48
+ inputArgsApply(schema, inputType, parent, data, getTargetFromParent, scope);
45
49
  }, false);
46
50
  }
47
51
  return this;
48
52
  }
49
- unbatchedExecute(extra, value) {
53
+ unbatchedExecute(extra, value, scope) {
50
54
  const { getTargetFromParent } = this;
51
- return (parentThing) => inputArgsApply(this.operationPlan.schema, this.inputType, parentThing, value, getTargetFromParent);
55
+ return (parentThing) => inputArgsApply(this.operationPlan.schema, this.inputType, parentThing, value, getTargetFromParent, scope);
52
56
  }
53
57
  }
54
58
  exports.ApplyInputStep = ApplyInputStep;
55
- function inputArgsApply(schema, inputType, parent, inputValue, getTargetFromParent) {
59
+ function inputArgsApply(schema, inputType, parent, inputValue, getTargetFromParent, scope) {
56
60
  try {
57
61
  inputArgsApplyDepth++;
58
62
  const target = getTargetFromParent
59
- ? getTargetFromParent(parent, inputValue)
63
+ ? getTargetFromParent(parent, inputValue, { scope })
60
64
  : parent;
61
65
  if (target != null) {
62
- _inputArgsApply(schema, inputType, target, inputValue);
66
+ _inputArgsApply(schema, inputType, target, inputValue, scope);
63
67
  }
64
68
  }
65
69
  finally {
@@ -82,16 +86,20 @@ function inputArgsApply(schema, inputType, parent, inputValue, getTargetFromPare
82
86
  function applyInput(inputType, $value, getTargetFromParent) {
83
87
  const opPlan = (0, global_js_1.operationPlan)();
84
88
  const { schema } = opPlan;
89
+ const namedType = (0, graphql_1.getNamedType)(inputType);
85
90
  return opPlan.withRootLayerPlan(() => {
86
- if ($value instanceof constant_js_1.ConstantStep) {
91
+ const $scope = namedType.extensions?.grafast?.applyScope?.() ?? null;
92
+ if ((!$scope || $scope instanceof constant_js_1.ConstantStep) &&
93
+ $value instanceof constant_js_1.ConstantStep) {
87
94
  // Replace us with a constant
88
95
  const { data } = $value;
96
+ const scope = $scope?.data;
89
97
  return (0, constant_js_1.constant)(function applyInputConstant(parent) {
90
- inputArgsApply(schema, inputType, parent, data, getTargetFromParent);
98
+ inputArgsApply(schema, inputType, parent, data, getTargetFromParent, scope);
91
99
  }, false);
92
100
  }
93
101
  else {
94
- return new ApplyInputStep(inputType, $value, getTargetFromParent);
102
+ return new ApplyInputStep(inputType, $value, getTargetFromParent, $scope);
95
103
  }
96
104
  });
97
105
  }
@@ -106,7 +114,7 @@ const defaultInputObjectTypeInputPlanResolver: InputObjectTypeInputPlanResolver
106
114
  return object(obj);
107
115
  };
108
116
  */
109
- function _inputArgsApply(schema, inputType, target, inputValue) {
117
+ function _inputArgsApply(schema, inputType, target, inputValue, scope) {
110
118
  // PERF: we should have the plan generate a digest of `inputType` so that we
111
119
  // can jump right to the relevant parts without too much traversal cost.
112
120
  if (inputValue === undefined) {
@@ -116,7 +124,7 @@ function _inputArgsApply(schema, inputType, target, inputValue) {
116
124
  if (inputValue === null) {
117
125
  throw new Error(`null value found in non-null position`);
118
126
  }
119
- _inputArgsApply(schema, inputType.ofType, target, inputValue);
127
+ _inputArgsApply(schema, inputType.ofType, target, inputValue, scope);
120
128
  }
121
129
  else if ((0, graphql_1.isListType)(inputType)) {
122
130
  if (inputValue == null)
@@ -126,7 +134,7 @@ function _inputArgsApply(schema, inputType, target, inputValue) {
126
134
  }
127
135
  for (const item of inputValue) {
128
136
  const itemTarget = typeof target === "function" ? target() : target;
129
- _inputArgsApply(schema, inputType.ofType, itemTarget, item);
137
+ _inputArgsApply(schema, inputType.ofType, itemTarget, item, scope);
130
138
  }
131
139
  }
132
140
  else if (typeof target === "function") {
@@ -146,9 +154,10 @@ function _inputArgsApply(schema, inputType, target, inputValue) {
146
154
  schema,
147
155
  field,
148
156
  fieldName,
157
+ scope,
149
158
  });
150
159
  if (newTarget != null) {
151
- _inputArgsApply(schema, field.type, newTarget, val);
160
+ _inputArgsApply(schema, field.type, newTarget, val, scope);
152
161
  }
153
162
  }
154
163
  }
@@ -165,7 +174,7 @@ function _inputArgsApply(schema, inputType, target, inputValue) {
165
174
  const value = values.find((v) => v.value === inputValue);
166
175
  if (value) {
167
176
  if (value.extensions.grafast?.apply) {
168
- value.extensions.grafast.apply(target);
177
+ value.extensions.grafast.apply(target, { scope, value });
169
178
  }
170
179
  }
171
180
  else {
@@ -78,11 +78,11 @@ function bakedInputRuntime(schema, inputType, value) {
78
78
  schema,
79
79
  applyChildren(parent) {
80
80
  applied = true;
81
- (0, applyInput_js_1.inputArgsApply)(schema, nullableInputType, parent, value, undefined);
81
+ (0, applyInput_js_1.inputArgsApply)(schema, nullableInputType, parent, value, undefined, undefined);
82
82
  },
83
83
  });
84
84
  if (!applied) {
85
- (0, applyInput_js_1.inputArgsApply)(schema, nullableInputType, bakedObj, value, undefined);
85
+ (0, applyInput_js_1.inputArgsApply)(schema, nullableInputType, bakedObj, value, undefined, undefined);
86
86
  }
87
87
  return bakedObj;
88
88
  }
@@ -1,6 +1,7 @@
1
1
  import type { ExecutionDetails, GrafastResultsList, Maybe, UnbatchedExecutionExtra } from "../interfaces.js";
2
2
  import type { Step } from "../step.js";
3
3
  import { UnbatchedStep } from "../step.js";
4
+ import { ConstantStep } from "./constant.js";
4
5
  type ParametersExceptFirst<F> = F extends (arg0: any, ...rest: infer R) => any ? R : never[];
5
6
  /**
6
7
  * Describes what a plan needs to implement in order to be suitable for
@@ -96,7 +97,7 @@ export declare class ConnectionStep<TItemStep extends Step, TCursorStep extends
96
97
  * functions so that they are thrown "earlier", avoiding error bubbling.
97
98
  */
98
99
  addValidation(callback: () => Step): void;
99
- get(fieldName: string): Step<any> | undefined;
100
+ get(fieldName: string): Step<any>;
100
101
  edges(): Step;
101
102
  nodes(): import("./listTransform.js").__ListTransformStep<any, any, any, any> | TStep;
102
103
  wrapEdge($edge: TItemStep): EdgeStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>;
@@ -120,7 +121,7 @@ export declare class EdgeStep<TItemStep extends Step, TCursorStep extends Step,
120
121
  private readonly cursorDepId;
121
122
  private needCursor;
122
123
  constructor($connection: ConnectionStep<TItemStep, TCursorStep, TStep, TEdgeDataStep, TNodeStep>, $item: TItemStep, skipCursor?: boolean);
123
- get(fieldName: string): Step<string | null> | TNodeStep | undefined;
124
+ get(fieldName: string): ConstantStep<undefined> | Step<string | null> | TNodeStep;
124
125
  private getConnectionStep;
125
126
  private getItemStep;
126
127
  data(): TEdgeDataStep;
@@ -216,6 +216,8 @@ class ConnectionStep extends step_js_1.UnbatchedStep {
216
216
  return this.nodes();
217
217
  case "pageInfo":
218
218
  return this.pageInfo();
219
+ default:
220
+ return (0, constant_js_1.constant)(undefined);
219
221
  }
220
222
  }
221
223
  edges() {
@@ -298,6 +300,8 @@ class EdgeStep extends step_js_1.UnbatchedStep {
298
300
  return this.node();
299
301
  case "cursor":
300
302
  return this.cursor();
303
+ default:
304
+ return (0, constant_js_1.constant)(undefined);
301
305
  }
302
306
  }
303
307
  getConnectionStep() {
@@ -19,7 +19,10 @@ export declare class ConstantStep<TData> extends UnbatchedStep<TData> {
19
19
  unbatchedExecute(): TData;
20
20
  isNull(): boolean;
21
21
  isUndefined(): boolean;
22
- get(key: string): ConstantStep<any>;
22
+ __inferGet?: {
23
+ [TKey in keyof TData]: ConstantStep<TData[TKey]>;
24
+ };
25
+ get<TKey extends keyof TData>(key: TKey): ConstantStep<TData[TKey]>;
23
26
  at(index: number): ConstantStep<any>;
24
27
  }
25
28
  /**
@@ -0,0 +1,50 @@
1
+ import type { Step } from "../step.js";
2
+ /**
3
+ * If your step class has a `get` method you should implement this so users
4
+ * benefit from type safety.
5
+ *
6
+ * e.g.
7
+ * ```ts
8
+ * class MyStep extends Step {
9
+ * __inferGet?: {
10
+ * [TKey in keyof MyData]: MySpecialStep<MyData[TKey]>;
11
+ * };
12
+ * get<TKey extends keyof MyData>(key: TKey): MySpecialStep<MyData[TKey]> {
13
+ * // ...
14
+ * }
15
+ * }
16
+ * ```
17
+ */
18
+ interface HasInferredGet<TStepByKey extends Record<string, Step>> {
19
+ /**
20
+ * TypeScript hack so we can infer the type of getting each key; this key
21
+ * won't actually have a value
22
+ */
23
+ __inferGet?: TStepByKey;
24
+ }
25
+ /**
26
+ * Determines the keys that a given step represents
27
+ *
28
+ * 1. If it implements HasInferredGet, get the explicit keys
29
+ * 2. Otherwise, if it has a get method, figure out which attributes it accepts
30
+ * 3. Otherwise, determine the type the Step encodes and extract the keys of that
31
+ */
32
+ type StepGetKeys<TStep extends Step> = TStep extends HasInferredGet<infer UStepByKey> ? keyof UStepByKey : TStep extends {
33
+ get(attr: infer U): any;
34
+ } ? U : TStep extends Step<infer UData | null | undefined> ? keyof UData : never;
35
+ /**
36
+ * Determines the type of the step returned from `get(step, attr)`.
37
+ *
38
+ * 1. If it implements HasInferredGet, get a step representing that specific attribute
39
+ * 2. Otherwise, if it has a get method, return the ReturnType of that method
40
+ * 3. Otherwise, determine the type the Step encodes and return a Step representing the relevant key of that
41
+ */
42
+ type GetResult<TStep extends Step, TAttr extends StepGetKeys<TStep>> = TStep extends HasInferredGet<infer UStepByKey> ? TAttr extends keyof UStepByKey ? UStepByKey[TAttr] : never : TStep extends {
43
+ get(attr: any): infer UGetStep;
44
+ } ? UGetStep : TStep extends Step<infer UData | null | undefined> ? TAttr extends keyof UData ? Step<UData[TAttr]> : never : never;
45
+ /**
46
+ * Call `$step.get(attr)` if possible, falling back to `access($step, attr)`.
47
+ */
48
+ export declare function get<TStep extends Step, TAttr extends StepGetKeys<TStep> & string>($step: TStep, attr: TAttr): GetResult<TStep, TAttr>;
49
+ export {};
50
+ //# sourceMappingURL=get.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get = get;
4
+ const access_js_1 = require("./access.js");
5
+ /**
6
+ * Call `$step.get(attr)` if possible, falling back to `access($step, attr)`.
7
+ */
8
+ function get($step, attr) {
9
+ return "get" in $step && typeof $step.get === "function"
10
+ ? $step.get(attr)
11
+ : (0, access_js_1.access)($step, attr);
12
+ }
13
+ //# sourceMappingURL=get.js.map
@@ -1,5 +1,5 @@
1
1
  export { __FlagStep, assertNotNull, inhibitOnNull, trap, TRAP_ERROR, TRAP_ERROR_OR_INHIBITED, TRAP_INHIBITED, } from "./__flag.js";
2
- export { access, AccessStep, get } from "./access.js";
2
+ export { access, AccessStep } from "./access.js";
3
3
  export { coalesce, CoalesceStep } from "./coalesce.js";
4
4
  export { assertEdgeCapableStep, assertPageInfoCapableStep, connection, ConnectionCapableStep, ConnectionStep, EdgeCapableStep, EdgeStep, PageInfoCapableStep, } from "./connection.js";
5
5
  export { constant, ConstantStep } from "./constant.js";
@@ -7,6 +7,7 @@ export { each } from "./each.js";
7
7
  export { error, ErrorStep } from "./error.js";
8
8
  export { filter, FilterPlanMemo } from "./filter.js";
9
9
  export { first, FirstStep } from "./first.js";
10
+ export { get } from "./get.js";
10
11
  export { groupBy, GroupByPlanMemo } from "./groupBy.js";
11
12
  export { lambda, LambdaStep } from "./lambda.js";
12
13
  export { last, LastStep } from "./last.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReverseStep = exports.reverseArray = exports.reverse = exports.RemapKeysStep = exports.remapKeys = exports.partitionByIndex = exports.ObjectStep = exports.object = exports.specFromNodeId = exports.NodeStep = exports.nodeIdFromNode = exports.node = exports.makeDecodeNodeIdRuntime = exports.makeDecodeNodeId = exports.listTransform = exports.__ListTransformStep = exports.ListenStep = exports.listen = exports.ListStep = exports.list = exports.LastStep = exports.last = exports.LambdaStep = exports.lambda = exports.groupBy = exports.FirstStep = exports.first = exports.filter = exports.ErrorStep = exports.error = exports.each = exports.ConstantStep = exports.constant = exports.EdgeStep = exports.ConnectionStep = exports.connection = exports.assertPageInfoCapableStep = exports.assertEdgeCapableStep = exports.CoalesceStep = exports.coalesce = exports.get = exports.AccessStep = exports.access = exports.TRAP_INHIBITED = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_ERROR = exports.trap = exports.inhibitOnNull = exports.assertNotNull = exports.__FlagStep = void 0;
3
+ exports.ReverseStep = exports.reverseArray = exports.reverse = exports.RemapKeysStep = exports.remapKeys = exports.partitionByIndex = exports.ObjectStep = exports.object = exports.specFromNodeId = exports.NodeStep = exports.nodeIdFromNode = exports.node = exports.makeDecodeNodeIdRuntime = exports.makeDecodeNodeId = exports.listTransform = exports.__ListTransformStep = exports.ListenStep = exports.listen = exports.ListStep = exports.list = exports.LastStep = exports.last = exports.LambdaStep = exports.lambda = exports.groupBy = exports.get = exports.FirstStep = exports.first = exports.filter = exports.ErrorStep = exports.error = exports.each = exports.ConstantStep = exports.constant = exports.EdgeStep = exports.ConnectionStep = exports.connection = exports.assertPageInfoCapableStep = exports.assertEdgeCapableStep = exports.CoalesceStep = exports.coalesce = exports.AccessStep = exports.access = exports.TRAP_INHIBITED = exports.TRAP_ERROR_OR_INHIBITED = exports.TRAP_ERROR = exports.trap = exports.inhibitOnNull = exports.assertNotNull = exports.__FlagStep = void 0;
4
4
  exports.ProxyStep = exports.proxy = exports.LoadStep = exports.loadOneCallback = exports.loadOne = exports.loadManyCallback = exports.loadMany = exports.LoadedRecordStep = exports.GraphQLResolverStep = exports.graphqlResolver = exports.ConditionStep = exports.condition = exports.BakedInputStep = exports.bakedInputRuntime = exports.bakedInput = exports.ApplyTransformsStep = exports.applyTransforms = exports.Modifier = exports.isModifier = exports.assertModifier = exports.ApplyInputStep = exports.applyInput = exports.__ValueStep = exports.__TrackedValueStep = exports.__ItemStep = exports.__InputStaticLeafStep = exports.__InputObjectStep = exports.__InputListStep = exports.SideEffectStep = exports.sideEffect = exports.setter = exports.Setter = exports.createObjectAndApplyChildren = void 0;
5
5
  var __flag_js_1 = require("./__flag.js");
6
6
  Object.defineProperty(exports, "__FlagStep", { enumerable: true, get: function () { return __flag_js_1.__FlagStep; } });
@@ -13,7 +13,6 @@ Object.defineProperty(exports, "TRAP_INHIBITED", { enumerable: true, get: functi
13
13
  var access_js_1 = require("./access.js");
14
14
  Object.defineProperty(exports, "access", { enumerable: true, get: function () { return access_js_1.access; } });
15
15
  Object.defineProperty(exports, "AccessStep", { enumerable: true, get: function () { return access_js_1.AccessStep; } });
16
- Object.defineProperty(exports, "get", { enumerable: true, get: function () { return access_js_1.get; } });
17
16
  var coalesce_js_1 = require("./coalesce.js");
18
17
  Object.defineProperty(exports, "coalesce", { enumerable: true, get: function () { return coalesce_js_1.coalesce; } });
19
18
  Object.defineProperty(exports, "CoalesceStep", { enumerable: true, get: function () { return coalesce_js_1.CoalesceStep; } });
@@ -36,6 +35,8 @@ Object.defineProperty(exports, "filter", { enumerable: true, get: function () {
36
35
  var first_js_1 = require("./first.js");
37
36
  Object.defineProperty(exports, "first", { enumerable: true, get: function () { return first_js_1.first; } });
38
37
  Object.defineProperty(exports, "FirstStep", { enumerable: true, get: function () { return first_js_1.FirstStep; } });
38
+ var get_js_1 = require("./get.js");
39
+ Object.defineProperty(exports, "get", { enumerable: true, get: function () { return get_js_1.get; } });
39
40
  var groupBy_js_1 = require("./groupBy.js");
40
41
  Object.defineProperty(exports, "groupBy", { enumerable: true, get: function () { return groupBy_js_1.groupBy; } });
41
42
  var lambda_js_1 = require("./lambda.js");
@@ -57,6 +57,7 @@ export declare class ObjectStep<TPlans extends {
57
57
  unbatchedExecute(_extra: UnbatchedExecutionExtra, ..._values: any[]): any;
58
58
  deduplicate(peers: ObjectStep<any>[]): ObjectStep<TPlans>[];
59
59
  optimize(opts: StepOptimizeOptions): ConstantStep<any> | this | ConstantStep<Record<string, any>>;
60
+ __inferGet?: TPlans;
60
61
  /**
61
62
  * Get the original plan with the given key back again.
62
63
  */
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "0.1.1-beta.23";
1
+ export declare const version = "0.1.1-beta.25";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // This file is autogenerated by /scripts/postversion.mjs
5
- exports.version = "0.1.1-beta.23";
5
+ exports.version = "0.1.1-beta.25";
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grafast",
3
- "version": "0.1.1-beta.23",
3
+ "version": "0.1.1-beta.25",
4
4
  "description": "Cutting edge GraphQL planning and execution engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -73,6 +73,12 @@
73
73
  "peerDependenciesMeta": {
74
74
  "@envelop/core": {
75
75
  "optional": true
76
+ },
77
+ "graphql": {
78
+ "optional": true
79
+ },
80
+ "tamedevil": {
81
+ "optional": true
76
82
  }
77
83
  },
78
84
  "files": [