grafast 0.0.1-alpha.9 → 0.0.1-beta.2

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 (69) hide show
  1. package/LICENSE.md +15 -17
  2. package/README.md +138 -1
  3. package/dist/LICENSES.txt +1 -1
  4. package/dist/args.d.ts +7 -1
  5. package/dist/assert.d.ts +2 -0
  6. package/dist/bucket.d.ts +66 -1
  7. package/dist/constraints.d.ts +31 -0
  8. package/dist/deferred.d.ts +7 -0
  9. package/dist/dev.d.ts +3 -0
  10. package/dist/engine/LayerPlan.d.ts +131 -0
  11. package/dist/engine/OperationPlan.d.ts +151 -0
  12. package/dist/engine/OutputPlan.d.ts +105 -1
  13. package/dist/engine/StepTracker.d.ts +56 -1
  14. package/dist/engine/executeBucket.d.ts +4 -1
  15. package/dist/engine/executeOutputPlan.d.ts +42 -1
  16. package/dist/envelop.d.ts +12 -0
  17. package/dist/envelop.js +2 -51
  18. package/dist/error.d.ts +23 -0
  19. package/dist/establishOperationPlan.d.ts +10 -31
  20. package/dist/execute.d.ts +8 -0
  21. package/dist/exportAs.d.ts +14 -0
  22. package/dist/grafastGraphql.d.ts +8 -3
  23. package/dist/grafastPrint.d.ts +8 -0
  24. package/dist/graphqlCollectFields.d.ts +22 -0
  25. package/dist/graphqlMergeSelectionSets.d.ts +4 -0
  26. package/dist/index.d.ts +9 -4
  27. package/dist/index.js +387 -53
  28. package/dist/input.d.ts +8 -1
  29. package/dist/interfaces.d.ts +356 -59
  30. package/dist/makeGrafastSchema.d.ts +30 -3
  31. package/dist/mermaid.d.ts +28 -0
  32. package/dist/polymorphic.d.ts +8 -0
  33. package/dist/prepare.d.ts +16 -2
  34. package/dist/step.d.ts +183 -0
  35. package/dist/steps/__inputDynamicScalar.d.ts +3 -0
  36. package/dist/steps/__inputList.d.ts +3 -0
  37. package/dist/steps/__inputObject.d.ts +3 -0
  38. package/dist/steps/__inputStaticLeaf.d.ts +5 -0
  39. package/dist/steps/__item.d.ts +8 -0
  40. package/dist/steps/__trackedValue.d.ts +74 -0
  41. package/dist/steps/__value.d.ts +5 -0
  42. package/dist/steps/access.d.ts +20 -0
  43. package/dist/steps/{deepEval.d.ts → applyTransforms.d.ts} +16 -3
  44. package/dist/steps/connection.d.ts +49 -0
  45. package/dist/steps/constant.d.ts +11 -3
  46. package/dist/steps/each.d.ts +3 -0
  47. package/dist/steps/filter.d.ts +4 -0
  48. package/dist/steps/first.d.ts +4 -0
  49. package/dist/steps/graphqlResolver.d.ts +18 -0
  50. package/dist/steps/groupBy.d.ts +6 -0
  51. package/dist/steps/index.d.ts +6 -2
  52. package/dist/steps/lambda.d.ts +8 -0
  53. package/dist/steps/last.d.ts +4 -0
  54. package/dist/steps/list.d.ts +7 -0
  55. package/dist/steps/listTransform.d.ts +21 -0
  56. package/dist/steps/listen.d.ts +16 -0
  57. package/dist/steps/load.d.ts +13 -0
  58. package/dist/steps/node.d.ts +20 -12
  59. package/dist/steps/object.d.ts +15 -0
  60. package/dist/steps/partitionByIndex.d.ts +35 -0
  61. package/dist/steps/proxy.d.ts +11 -0
  62. package/dist/steps/remapKeys.d.ts +8 -0
  63. package/dist/steps/reverse.d.ts +9 -0
  64. package/dist/subscribe.d.ts +4 -0
  65. package/dist/utils.d.ts +113 -5
  66. package/dist/version.d.ts +2 -0
  67. package/fwd/graphql/index.d.ts +1 -0
  68. package/fwd/graphql/index.js +1 -0
  69. package/package.json +14 -6
package/dist/input.d.ts CHANGED
@@ -3,5 +3,12 @@ import type { OperationPlan } from "./engine/OperationPlan.js";
3
3
  import type { AnyInputStep } from "./interfaces.js";
4
4
  export declare function assertInputStep(itemPlan: unknown): asserts itemPlan is AnyInputStep;
5
5
  export declare function graphqlGetTypeForNode(operationPlan: OperationPlan, node: NamedTypeNode | ListTypeNode | NonNullTypeNode): GraphQLType;
6
- export declare function inputPlan(operationPlan: OperationPlan, inputType: GraphQLInputType, rawInputValue: ValueNode | undefined, defaultValue?: ConstValueNode | undefined): AnyInputStep;
6
+ /**
7
+ * Returns a plan for the given `rawInputValue` AST node which could be a
8
+ * variable or a literal, and could be nested so that a variable (or more than
9
+ * one) appears somewhere. More than one plan may be created.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare function inputStep(operationPlan: OperationPlan, inputType: GraphQLInputType, rawInputValue: ValueNode | undefined, defaultValue?: ConstValueNode | undefined): AnyInputStep;
7
14
  //# sourceMappingURL=input.d.ts.map
@@ -1,35 +1,188 @@
1
+ import type LRU from "@graphile/lru";
1
2
  import type EventEmitter from "eventemitter3";
2
3
  import type { PluginHook } from "graphile-config";
3
- import type { ASTNode, ExecutionArgs, GraphQLArgument, GraphQLArgumentConfig, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLList, GraphQLNonNull, GraphQLOutputType, GraphQLScalarType, GraphQLSchema, GraphQLType, ValueNode, VariableNode } from "graphql";
4
+ import type { ASTNode, DocumentNode, ExecutionArgs as GraphQLExecutionArgs, FragmentDefinitionNode, GraphQLArgs, GraphQLArgument, GraphQLArgumentConfig, GraphQLError, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLList, GraphQLNonNull, GraphQLOutputType, GraphQLScalarType, GraphQLSchema, GraphQLType, OperationDefinitionNode, ValueNode, VariableNode } from "graphql";
4
5
  import type { Bucket, RequestTools } from "./bucket.js";
6
+ import type { OperationPlan } from "./engine/OperationPlan.js";
7
+ import type { SafeError } from "./error.js";
5
8
  import type { ExecutableStep, ListCapableStep, ModifierStep } from "./step.js";
6
9
  import type { __InputDynamicScalarStep } from "./steps/__inputDynamicScalar.js";
7
10
  import type { __InputListStep, __InputObjectStepWithDollars, __InputStaticLeafStep, __TrackedValueStep, __TrackedValueStepWithDollars, ConstantStep } from "./steps/index.js";
8
11
  import type { GrafastInputObjectType, GrafastObjectType } from "./utils.js";
9
12
  type PromiseOrValue<T> = T | Promise<T>;
10
13
  export interface GrafastTimeouts {
14
+ /**
15
+ * How many milliseconds should we allow for planning. Remember: planning is
16
+ * synchronous, so whilst it is happening the event loop is blocked.
17
+ */
11
18
  planning?: number;
19
+ /**
20
+ * How many milliseconds should we allow for execution. We will only check
21
+ * this immediately before triggering the execution of an asynchronous step,
22
+ * and if it is exceeded it will only prevent the execution of asynchronous
23
+ * steps, not synchronous ones.
24
+ *
25
+ * IMPORTANT: since we only check this _before_ an asynchronous step
26
+ * executes, there's nothing to stop an asynchronous step from continuing to
27
+ * execute long after the timeout has expired - therefore it's the
28
+ * responsibility of each step to abort itself if it goes over the allocated
29
+ * time budget (which is detailed in `ExecutionExtra.stopTime`).
30
+ */
12
31
  execution?: number;
13
32
  }
14
33
  export interface GrafastOptions {
15
- context?: Record<string, any> | (<TContext extends Record<string, any>>(ctx: Partial<Grafast.RequestContext>, currentContext?: Partial<TContext>) => PromiseOrValue<Partial<TContext>>);
34
+ /**
35
+ * An object to merge into the GraphQL context. Alternatively, pass an
36
+ * (optionally asynchronous) function that returns an object to merge into
37
+ * the GraphQL context.
38
+ */
39
+ context?: Partial<Grafast.Context> | ((ctx: Partial<Grafast.RequestContext>, args: Grafast.ExecutionArgs) => PromiseOrValue<Partial<Grafast.Context>>);
40
+ /**
41
+ * A list of 'explain' types that should be included in `extensions.explain`.
42
+ *
43
+ * - `mermaid-js` will cause the mermaid plan to be included
44
+ * - other values are dependent on the plugins in play
45
+ *
46
+ * If set to `true` then all possible explain types will be exposed.
47
+ */
16
48
  explain?: boolean | string[];
17
49
  timeouts?: GrafastTimeouts;
18
50
  }
51
+ export declare const $$queryCache: unique symbol;
52
+ /**
53
+ * We store the cache directly onto the GraphQLSchema so that it gets garbage
54
+ * collected along with the schema when it's not needed any more. To do so, we
55
+ * attach it using this symbol.
56
+ */
57
+ export declare const $$cacheByOperation: unique symbol;
58
+ export type Fragments = {
59
+ [key: string]: FragmentDefinitionNode;
60
+ };
61
+ export type OperationPlanOrError = OperationPlan | Error | SafeError<{
62
+ [$$timeout]: number;
63
+ [$$ts]: number;
64
+ } | {
65
+ [$$timeout]?: undefined;
66
+ [$$ts]?: undefined;
67
+ } | undefined>;
68
+ /**
69
+ * This represents the list of possible operationPlans for a specific document.
70
+ *
71
+ * @remarks
72
+ *
73
+ * It also includes the fragments for validation, but generally we trust that
74
+ * if the OperationDefinitionNode is the same then the request is equivalent.
75
+ */
76
+ export interface CacheByOperationEntry {
77
+ /**
78
+ * Implemented as a linked list so the hot operationPlans can be kept at the top of the
79
+ * list, and if the list grows beyond a maximum size we can drop the last
80
+ * element.
81
+ */
82
+ possibleOperationPlans: LinkedList<OperationPlanOrError> | null;
83
+ fragments: Fragments;
84
+ }
85
+ export interface LinkedList<T> {
86
+ value: T;
87
+ next: LinkedList<T> | null;
88
+ }
89
+ export declare const $$hooked: unique symbol;
19
90
  declare global {
20
91
  namespace Grafast {
92
+ type ExecutionArgs = Pick<GraphQLExecutionArgs, "schema" | "document" | "rootValue" | "variableValues" | "operationName"> & {
93
+ [$$hooked]?: boolean;
94
+ contextValue: Grafast.Context;
95
+ };
96
+ /**
97
+ * Details about the incoming GraphQL request - e.g. if it was sent over an
98
+ * HTTP request, the request itself so headers can be interrogated.
99
+ *
100
+ * It's anticipated this will be expanded via declaration merging, e.g. if
101
+ * your server is Koa then a `koaCtx` might be added.
102
+ */
21
103
  interface RequestContext {
22
104
  }
105
+ /**
106
+ * The GraphQL context our schemas expect, generally generated from details in Grafast.RequestContext
107
+ */
23
108
  interface Context {
24
109
  }
110
+ interface FieldExtensions {
111
+ plan?: FieldPlanResolver<any, any, any>;
112
+ subscribePlan?: FieldPlanResolver<any, any, any>;
113
+ }
114
+ interface ArgumentExtensions {
115
+ inputPlan?: ArgumentInputPlanResolver;
116
+ applyPlan?: ArgumentApplyPlanResolver;
117
+ autoApplyAfterParentPlan?: boolean;
118
+ autoApplyAfterParentSubscribePlan?: boolean;
119
+ }
120
+ interface InputObjectTypeExtensions {
121
+ inputPlan?: InputObjectTypeInputPlanResolver;
122
+ }
123
+ interface InputFieldExtensions {
124
+ inputPlan?: InputObjectFieldInputPlanResolver;
125
+ applyPlan?: InputObjectFieldApplyPlanResolver;
126
+ autoApplyAfterParentInputPlan?: boolean;
127
+ autoApplyAfterParentApplyPlan?: boolean;
128
+ }
129
+ interface ObjectTypeExtensions {
130
+ assertStep?: ((step: ExecutableStep) => asserts step is ExecutableStep) | {
131
+ new (...args: any[]): ExecutableStep;
132
+ } | null;
133
+ }
134
+ interface EnumTypeExtensions {
135
+ }
136
+ interface EnumValueExtensions {
137
+ /**
138
+ * EXPERIMENTAL!
139
+ *
140
+ * @internal
141
+ */
142
+ applyPlan?: EnumValueApplyPlanResolver<any>;
143
+ }
144
+ interface ScalarTypeExtensions {
145
+ plan?: ScalarPlanResolver;
146
+ inputPlan?: ScalarInputPlanResolver;
147
+ /**
148
+ * Set true if `serialize(serialize(foo)) === serialize(foo)` for all foo
149
+ */
150
+ idempotent?: boolean;
151
+ }
152
+ interface SchemaExtensions {
153
+ /**
154
+ * Maximum number of queries to store in this schema's query cache.
155
+ */
156
+ queryCacheMaxLength?: number;
157
+ /**
158
+ * The underlying query cache
159
+ */
160
+ [$$queryCache]?: LRU<string, DocumentNode | ReadonlyArray<GraphQLError>>;
161
+ /**
162
+ * Maximum number of operations to store an operation plan lookup cache for
163
+ */
164
+ operationsCacheMaxLength?: number;
165
+ /**
166
+ * Maximum number of operation plans to store in a single operation's cache
167
+ */
168
+ operationOperationPlansCacheMaxLength?: number;
169
+ /**
170
+ * The starting point for finding/storing the relevant OperationPlan for a request.
171
+ */
172
+ [$$cacheByOperation]?: LRU<OperationDefinitionNode, CacheByOperationEntry>;
173
+ }
25
174
  }
26
175
  namespace GraphileConfig {
27
176
  interface Preset {
177
+ /**
178
+ * Options that control how `grafast` should execute your GraphQL
179
+ * operations.
180
+ */
28
181
  grafast?: GrafastOptions;
29
182
  }
30
183
  interface GrafastHooks {
31
184
  args: PluginHook<(event: {
32
- args: ExecutionArgs;
185
+ args: Grafast.ExecutionArgs;
33
186
  ctx: Grafast.RequestContext;
34
187
  resolvedPreset: GraphileConfig.ResolvedPreset;
35
188
  }) => PromiseOrValue<void>>;
@@ -41,83 +194,88 @@ declare global {
41
194
  }
42
195
  }
43
196
  }
44
- export interface GrafastFieldExtensions {
45
- plan?: FieldPlanResolver<any, any, any>;
46
- subscribePlan?: FieldPlanResolver<any, any, any>;
47
- }
48
- export interface GrafastArgumentExtensions {
49
- inputPlan?: ArgumentInputPlanResolver;
50
- applyPlan?: ArgumentApplyPlanResolver;
51
- autoApplyAfterParentPlan?: boolean;
52
- autoApplyAfterParentSubscribePlan?: boolean;
53
- }
54
- export interface GrafastInputObjectTypeExtensions {
55
- inputPlan?: InputObjectTypeInputPlanResolver;
56
- }
57
- export interface GrafastInputFieldExtensions {
58
- inputPlan?: InputObjectFieldInputPlanResolver;
59
- applyPlan?: InputObjectFieldApplyPlanResolver;
60
- autoApplyAfterParentInputPlan?: boolean;
61
- autoApplyAfterParentApplyPlan?: boolean;
62
- }
63
- export interface GrafastObjectTypeExtensions {
64
- Step?: ((step: ExecutableStep) => asserts step is ExecutableStep) | {
65
- new (...args: any[]): ExecutableStep;
66
- displayName?: string;
67
- };
68
- }
69
- export interface GrafastEnumTypeExtensions {
70
- }
71
- export interface GrafastEnumValueExtensions {
72
- applyPlan?: EnumValueApplyPlanResolver<any>;
73
- }
74
- export interface GrafastScalarTypeExtensions {
75
- plan?: ScalarPlanResolver;
76
- inputPlan?: ScalarInputPlanResolver;
77
- idempotent?: boolean;
78
- }
79
197
  declare module "graphql" {
80
198
  interface GraphQLFieldExtensions<_TSource, _TContext, _TArgs = any> {
81
- grafast?: GrafastFieldExtensions;
199
+ grafast?: Grafast.FieldExtensions;
82
200
  }
83
201
  interface GraphQLArgumentExtensions {
84
- grafast?: GrafastArgumentExtensions;
202
+ grafast?: Grafast.ArgumentExtensions;
85
203
  }
86
204
  interface GraphQLInputObjectTypeExtensions {
87
- grafast?: GrafastInputObjectTypeExtensions;
205
+ grafast?: Grafast.InputObjectTypeExtensions;
88
206
  }
89
207
  interface GraphQLInputFieldExtensions {
90
- grafast?: GrafastInputFieldExtensions;
208
+ grafast?: Grafast.InputFieldExtensions;
91
209
  }
92
210
  interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
93
- grafast?: GrafastObjectTypeExtensions;
211
+ grafast?: Grafast.ObjectTypeExtensions;
94
212
  }
95
213
  interface GraphQLEnumTypeExtensions {
96
- grafast?: GrafastEnumTypeExtensions;
214
+ grafast?: Grafast.EnumTypeExtensions;
97
215
  }
98
216
  interface GraphQLEnumValueExtensions {
99
- grafast?: GrafastEnumValueExtensions;
217
+ grafast?: Grafast.EnumValueExtensions;
100
218
  }
101
219
  interface GraphQLScalarTypeExtensions {
102
- grafast?: GrafastScalarTypeExtensions;
220
+ grafast?: Grafast.ScalarTypeExtensions;
221
+ }
222
+ interface GraphQLSchemaExtensions {
223
+ grafast?: Grafast.SchemaExtensions;
103
224
  }
104
225
  }
105
226
  export declare const $$grafastContext: unique symbol;
106
227
  export declare const $$planResults: unique symbol;
107
228
  export declare const $$id: unique symbol;
229
+ /** Return the value verbatim, don't execute */
108
230
  export declare const $$verbatim: unique symbol;
231
+ /**
232
+ * If we're sure the data is the right shape and valid, we can set this key and
233
+ * it can be returned directly
234
+ */
109
235
  export declare const $$bypassGraphQL: unique symbol;
110
236
  export declare const $$data: unique symbol;
237
+ /**
238
+ * For attaching additional metadata to the GraphQL execution result, for
239
+ * example details of the plan or SQL queries or similar that were executed.
240
+ */
111
241
  export declare const $$extensions: unique symbol;
242
+ /**
243
+ * The "GraphQLObjectType" type name, useful when dealing with polymorphism.
244
+ *
245
+ * @internal
246
+ */
112
247
  export declare const $$concreteType: unique symbol;
248
+ /**
249
+ * Set this key on a type if that type's serialization is idempotent (that is
250
+ * to say `serialize(serialize(thing)) === serialize(thing)`). This means we
251
+ * don't have to "roll-back" serialization if we need to fallback to graphql-js
252
+ * execution.
253
+ */
113
254
  export declare const $$idempotent: unique symbol;
255
+ /**
256
+ * The event emitter used for outputting execution events.
257
+ */
114
258
  export declare const $$eventEmitter: unique symbol;
259
+ /**
260
+ * Used to indicate that an array has more results available via a stream.
261
+ */
115
262
  export declare const $$streamMore: unique symbol;
116
263
  export declare const $$proxy: unique symbol;
264
+ /**
265
+ * If an error has this property set then it's safe to send through to the user
266
+ * without being masked.
267
+ */
117
268
  export declare const $$safeError: unique symbol;
269
+ /** The layerPlan used as a subroutine for this step */
118
270
  export declare const $$subroutine: unique symbol;
271
+ /** For tracking the timeout a TimeoutError happened from */
119
272
  export declare const $$timeout: unique symbol;
273
+ /** For tracking _when_ the timeout happened (because once the JIT has warmed it might not need so long) */
120
274
  export declare const $$ts: unique symbol;
275
+ /**
276
+ * When dealing with a polymorphic thing we need to be able to determine what
277
+ * the concrete type of it is, we use the $$concreteType property for that.
278
+ */
121
279
  export interface PolymorphicData<TType extends string = string, TData = any> {
122
280
  [$$concreteType]: TType;
123
281
  [$$data]?: TData;
@@ -128,7 +286,7 @@ export interface IndexByListItemStepId {
128
286
  export type GrafastValuesList<T> = ReadonlyArray<T>;
129
287
  export type PromiseOrDirect<T> = PromiseLike<T> | T;
130
288
  export type GrafastResultsList<T> = ReadonlyArray<PromiseOrDirect<T>>;
131
- export type GrafastResultStreamList<T> = ReadonlyArray<PromiseOrDirect<AsyncIterable<PromiseOrDirect<T>>> | PromiseLike<never>>;
289
+ export type GrafastResultStreamList<T> = ReadonlyArray<PromiseOrDirect<AsyncIterable<PromiseOrDirect<T>> | null> | PromiseLike<never>>;
132
290
  export type BaseGraphQLRootValue = any;
133
291
  export interface BaseGraphQLVariables {
134
292
  [key: string]: unknown;
@@ -139,13 +297,21 @@ export interface BaseGraphQLArguments {
139
297
  export type BaseGraphQLInputObject = BaseGraphQLArguments;
140
298
  export type TargetStepOrCallback = ExecutableStep | ModifierStep | ((indexOrFieldName: number | string) => TargetStepOrCallback);
141
299
  export type FieldArgs = {
300
+ /** Gets the value, evaluating the `inputPlan` at each field if appropriate */
142
301
  get(path?: string | ReadonlyArray<string | number>): ExecutableStep;
302
+ /** Gets the value *without* calling any `inputPlan`s */
143
303
  getRaw(path?: string | ReadonlyArray<string | number>): AnyInputStep;
304
+ /** This also works (without path) to apply each list entry against $target */
144
305
  apply($target: ExecutableStep | ModifierStep | (() => ModifierStep), path?: string | ReadonlyArray<string | number>): void;
145
306
  } & AnyInputStepDollars;
146
307
  export type InputStep<TInputType extends GraphQLInputType = GraphQLInputType> = GraphQLInputType extends TInputType ? AnyInputStep : TInputType extends GraphQLNonNull<infer U> ? Exclude<InputStep<U & GraphQLInputType>, ConstantStep<undefined>> : TInputType extends GraphQLList<GraphQLInputType> ? __InputListStep<TInputType> | __TrackedValueStep<any, TInputType> | ConstantStep<undefined> : TInputType extends GraphQLInputObjectType ? __TrackedValueStepWithDollars<any, TInputType> | __InputObjectStepWithDollars<TInputType> | ConstantStep<undefined> : AnyInputStep;
147
308
  export type AnyInputStep = __TrackedValueStepWithDollars<any, GraphQLInputType> | __InputListStep | __InputStaticLeafStep | __InputDynamicScalarStep | __InputObjectStepWithDollars<GraphQLInputObjectType> | ConstantStep<undefined>;
148
309
  export type AnyInputStepWithDollars = AnyInputStep & AnyInputStepDollars;
310
+ /**
311
+ * Lies to make it easier to write TypeScript code like
312
+ * `{ $input: { $user: { $username } } }` without having to pass loads of
313
+ * generics.
314
+ */
149
315
  export type AnyInputStepDollars = {
150
316
  [key in string as `$${key}`]: AnyInputStepWithDollars;
151
317
  };
@@ -153,7 +319,30 @@ export interface FieldInfo {
153
319
  field: GraphQLField<any, any, any>;
154
320
  schema: GraphQLSchema;
155
321
  }
322
+ /**
323
+ * Step resolvers are like regular resolvers except they're called beforehand,
324
+ * they return plans rather than values, and they only run once for lists
325
+ * rather than for each item in the list.
326
+ *
327
+ * The idea is that the plan resolver returns a plan object which later will
328
+ * process the data and feed that into the actual resolver functions
329
+ * (preferably using the default resolver function?).
330
+ *
331
+ * They are stored onto `<field>.extensions.grafast.plan`
332
+ *
333
+ * @returns a plan for this field.
334
+ *
335
+ * @remarks
336
+ * We're using `TrackedObject<...>` so we can later consider caching these
337
+ * executions.
338
+ */
156
339
  export type FieldPlanResolver<_TArgs extends BaseGraphQLArguments, TParentStep extends ExecutableStep | null, TResultStep extends ExecutableStep> = ($parentPlan: TParentStep, args: FieldArgs, info: FieldInfo) => TResultStep | null;
340
+ /**
341
+ * Fields on input objects can have plans; the plan resolver is passed a parent plan
342
+ * (from an argument, or from a parent input object) or null if none, and an
343
+ * input plan that represents the value the user will pass to this field. The
344
+ * resolver must return either a ModifierStep or null.
345
+ */
157
346
  export type InputObjectFieldInputPlanResolver<TResultStep extends ExecutableStep = ExecutableStep> = (input: FieldArgs, info: {
158
347
  schema: GraphQLSchema;
159
348
  entity: GraphQLInputField;
@@ -166,6 +355,13 @@ export type InputObjectTypeInputPlanResolver = (input: FieldArgs, info: {
166
355
  schema: GraphQLSchema;
167
356
  type: GraphQLInputObjectType;
168
357
  }) => ExecutableStep;
358
+ /**
359
+ * Arguments can have plans; the plan resolver is passed the parent plan (the
360
+ * plan that represents the _parent_ field of the field the arg is defined on),
361
+ * the field plan (the plan that represents the field the arg is defined on)
362
+ * and an input plan that represents the value the user will pass to this
363
+ * argument. The resolver must return either a ModifierStep or null.
364
+ */
169
365
  export type ArgumentInputPlanResolver<TParentStep extends ExecutableStep = ExecutableStep, TResultStep extends ExecutableStep = ExecutableStep> = ($parentPlan: TParentStep, input: FieldArgs, info: {
170
366
  schema: GraphQLSchema;
171
367
  entity: GraphQLArgument;
@@ -174,29 +370,56 @@ export type ArgumentApplyPlanResolver<TParentStep extends ExecutableStep = Execu
174
370
  schema: GraphQLSchema;
175
371
  entity: GraphQLArgument;
176
372
  }) => TResultStep;
373
+ /**
374
+ * GraphQLScalarTypes can have plans, these are passed the field plan and must
375
+ * return an executable plan.
376
+ */
177
377
  export type ScalarPlanResolver<TParentStep extends ExecutableStep = ExecutableStep, TResultStep extends ExecutableStep = ExecutableStep> = ($parentPlan: TParentStep, info: {
178
378
  schema: GraphQLSchema;
179
379
  }) => TResultStep;
380
+ /**
381
+ * GraphQLScalarTypes can have plans, these are passed the field plan and must
382
+ * return an executable plan.
383
+ */
180
384
  export type ScalarInputPlanResolver<TResultStep extends ExecutableStep = ExecutableStep> = ($inputValue: InputStep, info: {
181
385
  schema: GraphQLSchema;
182
386
  type: GraphQLScalarType;
183
387
  }) => TResultStep;
388
+ /**
389
+ * EXPERIMENTAL!
390
+ *
391
+ * NOTE: this is an `any` because we want to allow users to specify
392
+ * subclasses of ExecutableStep but TypeScript only wants to allow
393
+ * superclasses.
394
+ *
395
+ * @internal
396
+ */
184
397
  export type EnumValueApplyPlanResolver<TParentStep extends ExecutableStep | ModifierStep = ExecutableStep | ModifierStep> = ($parent: TParentStep) => ModifierStep | void;
185
398
  type OutputPlanForNamedType<TType extends GraphQLType> = TType extends GrafastObjectType<any, infer TStep, any> ? TStep : ExecutableStep;
186
- export type OutputPlanForType<TType extends GraphQLOutputType> = TType extends GraphQLNonNull<GraphQLList<GraphQLNonNull<infer U>>> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep : TType extends GraphQLNonNull<GraphQLList<infer U>> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep : TType extends GraphQLList<GraphQLNonNull<infer U>> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep : TType extends GraphQLList<infer U> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep : TType extends GraphQLNonNull<infer U> ? OutputPlanForNamedType<U> : OutputPlanForNamedType<TType>;
399
+ export type OutputPlanForType<TType extends GraphQLOutputType> = TType extends GraphQLNonNull<GraphQLList<GraphQLNonNull<infer U>>> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep<ReadonlyArray<any>> : TType extends GraphQLNonNull<GraphQLList<infer U>> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep<ReadonlyArray<any>> : TType extends GraphQLList<GraphQLNonNull<infer U>> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep<ReadonlyArray<any>> : TType extends GraphQLList<infer U> ? ListCapableStep<any, OutputPlanForNamedType<U>> | ExecutableStep<ReadonlyArray<any>> : TType extends GraphQLNonNull<infer U> ? OutputPlanForNamedType<U> : OutputPlanForNamedType<TType>;
187
400
  type InputPlanForNamedType<TType extends GraphQLType> = TType extends GrafastInputObjectType<any, infer U, any> ? U : ModifierStep<any>;
188
401
  type InputPlanForType<TType extends GraphQLInputType> = TType extends GraphQLNonNull<GraphQLList<GraphQLNonNull<infer U>>> ? InputPlanForNamedType<U> : TType extends GraphQLNonNull<GraphQLList<infer U>> ? InputPlanForNamedType<U> : TType extends GraphQLList<GraphQLNonNull<infer U>> ? InputPlanForNamedType<U> : TType extends GraphQLList<infer U> ? InputPlanForNamedType<U> : TType extends GraphQLNonNull<infer U> ? InputPlanForNamedType<U> : InputPlanForNamedType<TType>;
189
402
  type InputTypeForNamedType<TType extends GraphQLType> = TType extends GraphQLScalarType<infer U> ? U : any;
190
403
  type InputTypeFor<TType extends GraphQLInputType> = TType extends GraphQLNonNull<GraphQLList<GraphQLNonNull<infer U>>> ? InputTypeForNamedType<U> : TType extends GraphQLNonNull<GraphQLList<infer U>> ? InputTypeForNamedType<U> : TType extends GraphQLList<GraphQLNonNull<infer U>> ? InputTypeForNamedType<U> : TType extends GraphQLList<infer U> ? InputTypeForNamedType<U> : TType extends GraphQLNonNull<infer U> ? InputTypeForNamedType<U> : InputTypeForNamedType<TType>;
191
- export type GrafastFieldConfig<TType extends GraphQLOutputType, TContext extends Grafast.Context, TParentStep extends ExecutableStep | null, TFieldStep extends ExecutableStep, TArgs extends BaseGraphQLArguments> = Omit<GraphQLFieldConfig<any, any>, "args" | "type"> & {
404
+ /**
405
+ * Basically GraphQLFieldConfig but with an easy to access `plan` method.
406
+ */
407
+ export type GrafastFieldConfig<TType extends GraphQLOutputType, TContext extends Grafast.Context, TParentStep extends ExecutableStep | null, TFieldStep extends ExecutableStep, // TODO: should be OutputPlanForType<TType>, but that results in everything thinking it should be a ListStep
408
+ TArgs extends BaseGraphQLArguments> = Omit<GraphQLFieldConfig<any, any>, "args" | "type"> & {
192
409
  type: TType;
193
410
  plan?: FieldPlanResolver<TArgs, TParentStep, TFieldStep>;
194
411
  subscribePlan?: FieldPlanResolver<TArgs, TParentStep, TFieldStep>;
195
412
  args?: GrafastFieldConfigArgumentMap<TType, TContext, TParentStep, TFieldStep>;
196
413
  };
414
+ /**
415
+ * Basically GraphQLFieldConfigArgumentMap but allowing for args to have plans.
416
+ */
197
417
  export type GrafastFieldConfigArgumentMap<_TType extends GraphQLOutputType, TContext extends Grafast.Context, TParentStep extends ExecutableStep | null, TFieldStep extends ExecutableStep> = {
198
418
  [argName: string]: GrafastArgumentConfig<any, TContext, TParentStep, TFieldStep, any, any>;
199
419
  };
420
+ /**
421
+ * Basically GraphQLArgumentConfig but allowing for a plan.
422
+ */
200
423
  export type GrafastArgumentConfig<TInputType extends GraphQLInputType = GraphQLInputType, _TContext extends Grafast.Context = Grafast.Context, _TParentStep extends ExecutableStep | null = ExecutableStep | null, TFieldStep extends ExecutableStep = ExecutableStep, _TArgumentStep extends TFieldStep extends ExecutableStep ? ModifierStep<TFieldStep> | null : null = TFieldStep extends ExecutableStep ? ModifierStep<TFieldStep> | null : null, _TInput extends InputTypeFor<TInputType> = InputTypeFor<TInputType>> = Omit<GraphQLArgumentConfig, "type"> & {
201
424
  type: TInputType;
202
425
  inputPlan?: ArgumentInputPlanResolver<any>;
@@ -204,6 +427,9 @@ export type GrafastArgumentConfig<TInputType extends GraphQLInputType = GraphQLI
204
427
  autoApplyAfterParentPlan?: boolean;
205
428
  autoApplyAfterParentSubscribePlan?: boolean;
206
429
  };
430
+ /**
431
+ * Basically GraphQLInputFieldConfig but allowing for the field to have a plan.
432
+ */
207
433
  export type GrafastInputFieldConfig<TInputType extends GraphQLInputType, _TContext extends Grafast.Context, _TParentStep extends ModifierStep<any>, _TResultStep extends InputPlanForType<TInputType>, _TInput extends InputTypeFor<TInputType>> = Omit<GraphQLInputFieldConfig, "type"> & {
208
434
  type: TInputType;
209
435
  inputPlan?: InputObjectFieldInputPlanResolver;
@@ -211,19 +437,40 @@ export type GrafastInputFieldConfig<TInputType extends GraphQLInputType, _TConte
211
437
  autoApplyAfterParentInputPlan?: boolean;
212
438
  autoApplyAfterParentApplyPlan?: boolean;
213
439
  };
440
+ /**
441
+ * The args passed to a field plan resolver, the values are plans.
442
+ */
214
443
  export type TrackedArguments<TArgs extends BaseGraphQLArguments = BaseGraphQLArguments> = {
215
444
  get<TKey extends keyof TArgs>(key: TKey): AnyInputStep;
216
445
  };
446
+ /**
447
+ * `@stream` directive meta.
448
+ */
217
449
  export interface StepStreamOptions {
218
450
  initialCount: number;
219
451
  }
452
+ /**
453
+ * Additional details about the planning for a field; currently only relates to
454
+ * the `@stream` directive.
455
+ */
220
456
  export interface StepOptions {
457
+ /**
458
+ * Details for the `@stream` directive.
459
+ */
221
460
  stream: StepStreamOptions | null;
222
461
  }
462
+ /**
463
+ * Options passed to the `optimize` method of a plan to give more context.
464
+ */
223
465
  export interface StepOptimizeOptions {
224
466
  stream: StepStreamOptions | null;
225
467
  meta: Record<string, unknown> | undefined;
226
468
  }
469
+ /**
470
+ * A subscriber provides realtime data, a SubscribeStep can subscribe to a
471
+ * given topic (string) and will receive an AsyncIterableIterator with messages
472
+ * published to that topic (standard pub/sub semantics).
473
+ */
227
474
  export type GrafastSubscriber<TTopics extends {
228
475
  [key: string]: any;
229
476
  } = {
@@ -231,20 +478,50 @@ export type GrafastSubscriber<TTopics extends {
231
478
  }> = {
232
479
  subscribe<TTopic extends keyof TTopics = keyof TTopics>(topic: TTopic): PromiseOrDirect<AsyncIterableIterator<TTopics[TTopic]>>;
233
480
  };
481
+ /**
482
+ * Specifically relates to the stringification of NodeIDs, e.g. `["User", 1]`
483
+ * to/from `WyJVc2VyIiwgMV0=`
484
+ */
234
485
  export interface NodeIdCodec<T = any> {
486
+ name: string;
235
487
  encode(value: T): string | null;
236
488
  decode(value: string): T;
237
489
  }
238
- export type NodeIdHandler<TCodecs extends {
239
- [key: string]: NodeIdCodec<any>;
240
- } = {
241
- [key: string]: NodeIdCodec<any>;
242
- }, TCodecName extends keyof TCodecs = keyof TCodecs, TNodeStep extends ExecutableStep = ExecutableStep, TSpec = any> = {
490
+ /**
491
+ * Determines if a NodeID relates to a given object type, and also relates to
492
+ * encoding the NodeID for that type.
493
+ */
494
+ export type NodeIdHandler<TCodec extends NodeIdCodec<any> = NodeIdCodec<any>, TNodeStep extends ExecutableStep = ExecutableStep, TSpec = any> = {
495
+ /**
496
+ * The name of the object type this handler is for.
497
+ */
243
498
  typeName: string;
244
- codecName: TCodecName & string;
245
- match(specifier: TCodecs[TCodecName] extends NodeIdCodec<infer U> ? U : any): boolean;
246
- plan($thing: TNodeStep): ExecutableStep<TCodecs[TCodecName] extends NodeIdCodec<infer U> ? U : any>;
247
- getSpec(plan: ExecutableStep<TCodecs[TCodecName] extends NodeIdCodec<infer U> ? U : any>): TSpec;
499
+ /**
500
+ * Which codec are we using to encode/decode the NodeID string?
501
+ */
502
+ codec: TCodec;
503
+ /**
504
+ * Returns true if the given decoded Node ID value represents this type.
505
+ */
506
+ match(specifier: TCodec extends NodeIdCodec<infer U> ? U : any): boolean;
507
+ /**
508
+ * Returns a plan that returns the value ready to be encoded. When the result
509
+ * of this plan is fed into `match`, it should return `true`.
510
+ */
511
+ plan($thing: TNodeStep): ExecutableStep<TCodec extends NodeIdCodec<infer U> ? U : any>;
512
+ /**
513
+ * Returns a specification based on the Node ID, this can be in any format
514
+ * you like. It is intended to then be fed into `get` or handled in your own
515
+ * code as you see fit. (When used directly, it's primarily useful for
516
+ * referencing a node without actually fetching it - e.g. allowing you to
517
+ * delete a node by its ID without first fetching it.)
518
+ */
519
+ getSpec(plan: ExecutableStep<TCodec extends NodeIdCodec<infer U> ? U : any>): TSpec;
520
+ /**
521
+ * Combined with `getSpec`, this forms the recprocal of `plan`; i.e.
522
+ * `get(getSpec( plan(node) ))` should return a plan that results in the
523
+ * original node.
524
+ */
248
525
  get(spec: TSpec): TNodeStep;
249
526
  deprecationReason?: string;
250
527
  };
@@ -260,6 +537,10 @@ export interface TypedEventEmitter<TEventMap extends BaseEventMap> extends Event
260
537
  emit<TEventName extends EventMapKey<TEventMap>>(eventName: TEventName, params: TEventMap[TEventName]): boolean;
261
538
  }
262
539
  export type ExecutionEventMap = {
540
+ /**
541
+ * Something that can be added to the
542
+ * ExecutionResult.extensions.explain.operations list.
543
+ */
263
544
  explainOperation: {
264
545
  operation: Record<string, any> & {
265
546
  type: string;
@@ -269,15 +550,21 @@ export type ExecutionEventMap = {
269
550
  };
270
551
  export type ExecutionEventEmitter = TypedEventEmitter<ExecutionEventMap>;
271
552
  export interface ExecutionExtra {
553
+ /** The `performance.now()` at which your step should stop executing */
272
554
  stopTime: number | null;
555
+ /** If you have set a `metaKey` on your step, the relevant meta object which you can write into (e.g. for caching) */
273
556
  meta: Record<string, unknown> | undefined;
274
557
  eventEmitter: ExecutionEventEmitter | undefined;
558
+ /** @internal */
275
559
  _bucket: Bucket;
560
+ /** @internal */
276
561
  _requestContext: RequestTools;
277
562
  }
278
563
  export interface LocationDetails {
279
564
  node: ASTNode | readonly ASTNode[];
565
+ /** This should only be null for the root selection */
280
566
  parentTypeName: string | null;
567
+ /** This should only be null for the root selection */
281
568
  fieldName: string | null;
282
569
  }
283
570
  export type JSONValue = boolean | number | string | null | JSONObject | JSONArray;
@@ -286,11 +573,21 @@ export interface JSONObject {
286
573
  }
287
574
  export interface JSONArray extends Array<JSONValue> {
288
575
  }
289
- export type UnwrapPlanTuple<TIn extends readonly ExecutableStep[]> = {
576
+ export type UnwrapPlanTuple</* const */ TIn extends readonly ExecutableStep[]> = {
290
577
  [Index in keyof TIn]: TIn[Index] extends ExecutableStep<infer U> ? U : never;
291
578
  } & {
292
579
  length: number;
293
580
  };
294
581
  export type NotVariableValueNode = Exclude<ValueNode, VariableNode>;
582
+ export type StreamMaybeMoreableArray<T = any> = Array<T> & {
583
+ [$$streamMore]?: AsyncIterator<any, any, any> | Iterator<any, any, any>;
584
+ };
585
+ export type StreamMoreableArray<T = any> = Array<T> & {
586
+ [$$streamMore]: AsyncIterator<any, any, any> | Iterator<any, any, any>;
587
+ };
588
+ export interface GrafastArgs extends GraphQLArgs {
589
+ resolvedPreset?: GraphileConfig.ResolvedPreset;
590
+ requestContext?: Partial<Grafast.RequestContext>;
591
+ }
295
592
  export {};
296
593
  //# sourceMappingURL=interfaces.d.ts.map