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.
- package/LICENSE.md +15 -17
- package/README.md +138 -1
- package/dist/LICENSES.txt +1 -1
- package/dist/args.d.ts +7 -1
- package/dist/assert.d.ts +2 -0
- package/dist/bucket.d.ts +66 -1
- package/dist/constraints.d.ts +31 -0
- package/dist/deferred.d.ts +7 -0
- package/dist/dev.d.ts +3 -0
- package/dist/engine/LayerPlan.d.ts +131 -0
- package/dist/engine/OperationPlan.d.ts +151 -0
- package/dist/engine/OutputPlan.d.ts +105 -1
- package/dist/engine/StepTracker.d.ts +56 -1
- package/dist/engine/executeBucket.d.ts +4 -1
- package/dist/engine/executeOutputPlan.d.ts +42 -1
- package/dist/envelop.d.ts +12 -0
- package/dist/envelop.js +2 -51
- package/dist/error.d.ts +23 -0
- package/dist/establishOperationPlan.d.ts +10 -31
- package/dist/execute.d.ts +8 -0
- package/dist/exportAs.d.ts +14 -0
- package/dist/grafastGraphql.d.ts +8 -3
- package/dist/grafastPrint.d.ts +8 -0
- package/dist/graphqlCollectFields.d.ts +22 -0
- package/dist/graphqlMergeSelectionSets.d.ts +4 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +387 -53
- package/dist/input.d.ts +8 -1
- package/dist/interfaces.d.ts +356 -59
- package/dist/makeGrafastSchema.d.ts +30 -3
- package/dist/mermaid.d.ts +28 -0
- package/dist/polymorphic.d.ts +8 -0
- package/dist/prepare.d.ts +16 -2
- package/dist/step.d.ts +183 -0
- package/dist/steps/__inputDynamicScalar.d.ts +3 -0
- package/dist/steps/__inputList.d.ts +3 -0
- package/dist/steps/__inputObject.d.ts +3 -0
- package/dist/steps/__inputStaticLeaf.d.ts +5 -0
- package/dist/steps/__item.d.ts +8 -0
- package/dist/steps/__trackedValue.d.ts +74 -0
- package/dist/steps/__value.d.ts +5 -0
- package/dist/steps/access.d.ts +20 -0
- package/dist/steps/{deepEval.d.ts → applyTransforms.d.ts} +16 -3
- package/dist/steps/connection.d.ts +49 -0
- package/dist/steps/constant.d.ts +11 -3
- package/dist/steps/each.d.ts +3 -0
- package/dist/steps/filter.d.ts +4 -0
- package/dist/steps/first.d.ts +4 -0
- package/dist/steps/graphqlResolver.d.ts +18 -0
- package/dist/steps/groupBy.d.ts +6 -0
- package/dist/steps/index.d.ts +6 -2
- package/dist/steps/lambda.d.ts +8 -0
- package/dist/steps/last.d.ts +4 -0
- package/dist/steps/list.d.ts +7 -0
- package/dist/steps/listTransform.d.ts +21 -0
- package/dist/steps/listen.d.ts +16 -0
- package/dist/steps/load.d.ts +13 -0
- package/dist/steps/node.d.ts +20 -12
- package/dist/steps/object.d.ts +15 -0
- package/dist/steps/partitionByIndex.d.ts +35 -0
- package/dist/steps/proxy.d.ts +11 -0
- package/dist/steps/remapKeys.d.ts +8 -0
- package/dist/steps/reverse.d.ts +9 -0
- package/dist/subscribe.d.ts +4 -0
- package/dist/utils.d.ts +113 -5
- package/dist/version.d.ts +2 -0
- package/fwd/graphql/index.d.ts +1 -0
- package/fwd/graphql/index.js +1 -0
- package/package.json +14 -6
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import type { GraphQLFieldResolver, GraphQLScalarLiteralParser, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLSchema } from "graphql";
|
|
2
|
-
import type { EnumValueApplyPlanResolver, FieldPlanResolver,
|
|
2
|
+
import type { EnumValueApplyPlanResolver, FieldPlanResolver, ScalarPlanResolver } from "./interfaces.js";
|
|
3
3
|
import type { ExecutableStep } from "./step.js";
|
|
4
|
+
/**
|
|
5
|
+
* When defining a field with `typeDefs/plans` you can declare the field plan
|
|
6
|
+
* directly, or you can define a configuration object that accepts the plan and
|
|
7
|
+
* more.
|
|
8
|
+
*/
|
|
4
9
|
export type FieldPlans = FieldPlanResolver<any, any, any> | {
|
|
5
10
|
plan?: FieldPlanResolver<any, any, any>;
|
|
6
11
|
subscribePlan?: FieldPlanResolver<any, any, any>;
|
|
7
12
|
resolve?: GraphQLFieldResolver<any, any>;
|
|
8
13
|
subscribe?: GraphQLFieldResolver<any, any>;
|
|
9
14
|
args?: {
|
|
10
|
-
[argName: string]:
|
|
15
|
+
[argName: string]: Grafast.ArgumentExtensions;
|
|
11
16
|
};
|
|
12
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* The plans/config for each field of a GraphQL object type.
|
|
20
|
+
*/
|
|
13
21
|
export type ObjectPlans = {
|
|
14
22
|
__Step?: {
|
|
15
23
|
new (...args: any[]): ExecutableStep;
|
|
@@ -17,27 +25,46 @@ export type ObjectPlans = {
|
|
|
17
25
|
} & {
|
|
18
26
|
[fieldName: string]: FieldPlans;
|
|
19
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* The plans for each field of a GraphQL input object type.
|
|
30
|
+
*/
|
|
20
31
|
export type InputObjectPlans = {
|
|
21
|
-
[fieldName: string]:
|
|
32
|
+
[fieldName: string]: Grafast.InputFieldExtensions;
|
|
22
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* The plan config for an interface or union type.
|
|
36
|
+
*/
|
|
23
37
|
export type InterfaceOrUnionPlans = {
|
|
24
38
|
__resolveType?: (o: unknown) => string;
|
|
25
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* The config for a GraphQL scalar type.
|
|
42
|
+
*/
|
|
26
43
|
export type ScalarPlans = {
|
|
27
44
|
serialize?: GraphQLScalarSerializer<any>;
|
|
28
45
|
parseValue?: GraphQLScalarValueParser<any>;
|
|
29
46
|
parseLiteral?: GraphQLScalarLiteralParser<any>;
|
|
30
47
|
plan?: ScalarPlanResolver<any, any>;
|
|
31
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* The values/configs for the entries in a GraphQL enum type.
|
|
51
|
+
*/
|
|
32
52
|
export type EnumPlans = {
|
|
33
53
|
[enumValueName: string]: EnumValueApplyPlanResolver | string | number | boolean | {
|
|
34
54
|
value?: unknown;
|
|
35
55
|
applyPlan?: EnumValueApplyPlanResolver;
|
|
36
56
|
};
|
|
37
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* A map from GraphQL named type to the config for that type.
|
|
60
|
+
*/
|
|
38
61
|
export interface GrafastPlans {
|
|
39
62
|
[typeName: string]: ObjectPlans | InputObjectPlans | InterfaceOrUnionPlans | ScalarPlans | EnumPlans;
|
|
40
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Takes a GraphQL schema definition in Interface Definition Language (IDL/SDL)
|
|
66
|
+
* syntax and configs for the types in it and returns a GraphQL schema.
|
|
67
|
+
*/
|
|
41
68
|
export declare function makeGrafastSchema(details: {
|
|
42
69
|
typeDefs: string;
|
|
43
70
|
plans: GrafastPlans;
|
package/dist/mermaid.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type { OperationPlan } from ".";
|
|
2
2
|
import type { ExecutableStep } from "./step.js";
|
|
3
|
+
/**
|
|
4
|
+
* An array of hex colour codes that we use for colouring the buckets/steps in
|
|
5
|
+
* the mermaid-js plan diagram.
|
|
6
|
+
*
|
|
7
|
+
* Generated by mokole.com/palette.html; re-ordered by Jem
|
|
8
|
+
*/
|
|
3
9
|
export declare const COLORS: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Given a string, escapes the string so that it can be embedded as the description of a node in a mermaid chart.
|
|
12
|
+
*
|
|
13
|
+
* 1. If it's already safe, returns it verbatim
|
|
14
|
+
* 2. If it contains disallowed characters, escape them by replacing them with similar-looking characters,
|
|
15
|
+
* 3. Wrap the string in quote marks.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
*
|
|
19
|
+
* NOTE: rather than doing literal escapes, we replace with lookalike characters because:
|
|
20
|
+
*
|
|
21
|
+
* 1. Mermaid has a bug when calculating the width of the node that doesn't respect escapes,
|
|
22
|
+
* 2. It's easier to read the raw mermaid markup with substitutes rather than messy escapes.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
4
26
|
export declare const mermaidEscape: (str: string) => string;
|
|
5
27
|
export interface PrintPlanGraphOptions {
|
|
6
28
|
printPathRelations?: boolean;
|
|
@@ -8,6 +30,12 @@ export interface PrintPlanGraphOptions {
|
|
|
8
30
|
concise?: boolean;
|
|
9
31
|
skipBuckets?: boolean;
|
|
10
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert an OpPlan into a plan graph; call this via `operationPlan.printPlanGraph()`
|
|
35
|
+
* rather than calling this function directly.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
11
39
|
export declare function printPlanGraph(operationPlan: OperationPlan, { concise, skipBuckets, }: PrintPlanGraphOptions, { steps, }: {
|
|
12
40
|
steps: {
|
|
13
41
|
[stepId: number]: ExecutableStep | null;
|
package/dist/polymorphic.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { PolymorphicData } from "./interfaces.js";
|
|
2
2
|
export declare function isPolymorphicData(data: unknown): data is PolymorphicData;
|
|
3
3
|
export declare function assertPolymorphicData(data: unknown): asserts data is PolymorphicData;
|
|
4
|
+
/**
|
|
5
|
+
* Returns an object with the given concrete type (and, optionally, associated
|
|
6
|
+
* data)
|
|
7
|
+
*/
|
|
4
8
|
export declare function polymorphicWrap<TType extends string, TData>(type: TType, data?: TData): PolymorphicData<TType, TData>;
|
|
9
|
+
/**
|
|
10
|
+
* All polymorphic objects in Grafast have a $$concreteType property which
|
|
11
|
+
* contains the GraphQL object's type name; we simply return that.
|
|
12
|
+
*/
|
|
5
13
|
export declare function resolveType(o: unknown): string;
|
|
6
14
|
//# sourceMappingURL=polymorphic.d.ts.map
|
package/dist/prepare.d.ts
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import type { ExecutionArgs } from "graphql";
|
|
2
2
|
import type { AsyncExecutionResult, ExecutionResult } from "graphql/execution/execute";
|
|
3
|
-
import type { OperationPlan } from "./index.js";
|
|
4
3
|
import type { GrafastTimeouts, PromiseOrDirect } from "./interfaces.js";
|
|
5
4
|
declare const $$contextPlanCache: unique symbol;
|
|
6
5
|
export interface GrafastPrepareOptions {
|
|
6
|
+
/**
|
|
7
|
+
* A list of 'explain' types that should be included in `extensions.explain`.
|
|
8
|
+
*
|
|
9
|
+
* - `mermaid-js` will cause the mermaid plan to be included
|
|
10
|
+
* - other values are dependent on the plugins in play
|
|
11
|
+
*
|
|
12
|
+
* If set to `true` then all possible explain types will be exposed.
|
|
13
|
+
*/
|
|
7
14
|
explain?: boolean | string[];
|
|
15
|
+
/**
|
|
16
|
+
* If true, the result will be returned as a string rather than an object -
|
|
17
|
+
* this is an optimization for returning the data over a network socket or
|
|
18
|
+
* similar.
|
|
19
|
+
*/
|
|
8
20
|
outputDataAsString?: boolean;
|
|
9
21
|
timeouts?: GrafastTimeouts;
|
|
10
22
|
}
|
|
11
|
-
export declare function executePreemptive(operationPlan: OperationPlan, variableValues: any, context: any, rootValue: any, outputDataAsString: boolean, executionTimeout: number | null): PromiseOrDirect<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, void>>;
|
|
12
23
|
declare module "./engine/OperationPlan.js" {
|
|
13
24
|
interface OperationPlan {
|
|
14
25
|
[$$contextPlanCache]?: string;
|
|
15
26
|
}
|
|
16
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
17
31
|
export declare function grafastPrepare(args: ExecutionArgs, options?: GrafastPrepareOptions): PromiseOrDirect<ExecutionResult | AsyncGenerator<AsyncExecutionResult, void, void>>;
|
|
18
32
|
export {};
|
|
19
33
|
//# sourceMappingURL=prepare.d.ts.map
|
package/dist/step.d.ts
CHANGED
|
@@ -4,51 +4,218 @@ import type { OperationPlan } from "./engine/OperationPlan.js";
|
|
|
4
4
|
import type { ExecutionExtra, GrafastResultsList, GrafastResultStreamList, GrafastValuesList, PromiseOrDirect, StepOptimizeOptions, StepOptions } from "./interfaces.js";
|
|
5
5
|
import { $$subroutine } from "./interfaces.js";
|
|
6
6
|
import type { __ItemStep } from "./steps/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export declare const $$deepDepSkip: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* This indicates that a step never executes (e.g. __ItemStep and __ValueStep)
|
|
13
|
+
* and thus when executed skips direct to reallyCompletedStep.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
8
17
|
export declare const $$noExec: unique symbol;
|
|
9
18
|
declare function reallyAssertFinalized(plan: BaseStep): void;
|
|
10
19
|
export declare const assertFinalized: typeof reallyAssertFinalized;
|
|
20
|
+
/**
|
|
21
|
+
* The base abstract plan type; you should not extend this directly - instead
|
|
22
|
+
* use an ExecutableStep (for use when planning output fields) or a
|
|
23
|
+
* ModifierStep (for use when planning arguments/input fields).
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
*
|
|
27
|
+
* Though it might seem that ModifierStep should be used for all inputs
|
|
28
|
+
* (arguments, input objects), this is not the case. When planning an output
|
|
29
|
+
* field, all inputs to it (including arguments, parent plan, context, etc)
|
|
30
|
+
* should be other executable plans. The only time that ModifierStep is used is
|
|
31
|
+
* when writing specific plans as part of the argument or input field
|
|
32
|
+
* definitions themself; even in these cases the inputs to these plan resolvers
|
|
33
|
+
* will be ExecutablePlans.
|
|
34
|
+
*/
|
|
11
35
|
export declare abstract class BaseStep {
|
|
36
|
+
/**
|
|
37
|
+
* This identifies the "bucket" into which this plan's results will be stored.
|
|
38
|
+
* New buckets are introduced when you cross boundaries that may change the
|
|
39
|
+
* number of results in the bucket, or where control over execution is desired.
|
|
40
|
+
*
|
|
41
|
+
* - Lists / list items (generally multiplies up)
|
|
42
|
+
* - Polymorphism - different entries may go into different buckets
|
|
43
|
+
* - Mutations - early termination is likely
|
|
44
|
+
* - Defer boundaries - don't execute this stuff until later
|
|
45
|
+
* - null boundaries - if a null is met, no need to continue execution
|
|
46
|
+
*
|
|
47
|
+
* This bucket influences:
|
|
48
|
+
*
|
|
49
|
+
* 1. how plans are deduplicated
|
|
50
|
+
* 2. the order in which the plans are executed
|
|
51
|
+
* 3. where the result of executing the plan is stored
|
|
52
|
+
* 4. when the plan execution cache is allowed to be GC'd
|
|
53
|
+
*
|
|
54
|
+
* NOTE: `__ListTransformStep`'s effectively have a temporary bucket inside
|
|
55
|
+
* them (built on the `__Item`) that's thrown away once the transform is
|
|
56
|
+
* complete.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
12
60
|
readonly layerPlan: LayerPlan;
|
|
13
61
|
readonly operationPlan: OperationPlan;
|
|
14
62
|
[$$subroutine]: LayerPlan<LayerPlanReasonSubroutine> | null;
|
|
15
63
|
isArgumentsFinalized: boolean;
|
|
16
64
|
isFinalized: boolean;
|
|
17
65
|
debug: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Set this true for plans that implement mutations; this will prevent them
|
|
68
|
+
* from being tree-shaken.
|
|
69
|
+
*/
|
|
18
70
|
hasSideEffects: boolean;
|
|
19
71
|
constructor();
|
|
20
72
|
toString(): string;
|
|
73
|
+
/**
|
|
74
|
+
* This metadata will be merged into toString when referencing this plan.
|
|
75
|
+
*/
|
|
21
76
|
toStringMeta(): string | null;
|
|
22
77
|
finalize(): void;
|
|
23
78
|
destroy(): void;
|
|
24
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Executable plans are the plans associated with leaves on the GraphQL tree,
|
|
82
|
+
* they must be able to execute to return values.
|
|
83
|
+
*/
|
|
25
84
|
export declare class ExecutableStep<TData = any> extends BaseStep {
|
|
26
85
|
static $$export: any;
|
|
86
|
+
/**
|
|
87
|
+
* Setting this true is a performance optimisation, but it comes with strong
|
|
88
|
+
* rules; we do not test you comply with these rules (as that would undo the
|
|
89
|
+
* performance gains) but should you break them the behaviour is undefined
|
|
90
|
+
* (and, basically, the schema may no longer be GraphQL compliant).
|
|
91
|
+
*
|
|
92
|
+
* Do not set this true unless the following hold:
|
|
93
|
+
*
|
|
94
|
+
* - The `execute` method must be a regular (not async) function
|
|
95
|
+
* - The `execute` method must NEVER return a promise
|
|
96
|
+
* - The values within the list returned from `execute` must NEVER include
|
|
97
|
+
* promises or GrafastError objects
|
|
98
|
+
* - The result of calling `execute` should not differ after a
|
|
99
|
+
* `step.hasSideEffects` has executed (i.e. it should be pure, only
|
|
100
|
+
* dependent on its deps and use no external state)
|
|
101
|
+
*
|
|
102
|
+
* It's acceptable for the `execute` method to throw if it needs to.
|
|
103
|
+
*
|
|
104
|
+
* This optimisation applies to the majority of the built in plans and allows
|
|
105
|
+
* the engine to execute without needing to resolve any promises which saves
|
|
106
|
+
* precious event-loop ticks.
|
|
107
|
+
*/
|
|
27
108
|
isSyncAndSafe: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The plan this plan will need data from in order to execute.
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
28
113
|
readonly dependencies: ReadonlyArray<ExecutableStep>;
|
|
114
|
+
/**
|
|
115
|
+
* Just for mermaid
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
29
118
|
readonly dependents: ReadonlyArray<{
|
|
30
119
|
step: ExecutableStep;
|
|
31
120
|
dependencyIndex: number;
|
|
32
121
|
}>;
|
|
122
|
+
/**
|
|
123
|
+
* We reserve the right to change our mind as to whether this is a string or
|
|
124
|
+
* number.
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
33
128
|
readonly id: number;
|
|
129
|
+
/**
|
|
130
|
+
/**
|
|
131
|
+
* True when `optimize` has been called at least once.
|
|
132
|
+
*/
|
|
34
133
|
isOptimized: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Set this true if your plan's optimize method can be called a second time;
|
|
136
|
+
* note that in this situation it's likely that your dependencies will not be
|
|
137
|
+
* what you expect them to be (e.g. a PgSelectSingleStep might become an
|
|
138
|
+
* AccessStep).
|
|
139
|
+
*/
|
|
35
140
|
allowMultipleOptimizations: boolean;
|
|
141
|
+
/** @internal */
|
|
36
142
|
_stepOptions: StepOptions;
|
|
143
|
+
/** @internal */
|
|
37
144
|
polymorphicPaths: ReadonlySet<string> | null;
|
|
145
|
+
/**
|
|
146
|
+
* True if this needs to be permanently stored; for example:
|
|
147
|
+
*
|
|
148
|
+
* - Is the dep of another LayerPlan
|
|
149
|
+
* - Is used in an OutputPlan
|
|
150
|
+
*
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
38
153
|
store: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Set the metaKey so `execute` will be passed a meta object to use.
|
|
156
|
+
* Depending on what you set it to, you can share execution meta between
|
|
157
|
+
* multiple steps of the same class (or even a family of step classes).
|
|
158
|
+
*
|
|
159
|
+
* A sensible value for it is `this.metaKey = this.id;`.
|
|
160
|
+
*/
|
|
39
161
|
metaKey: number | string | symbol | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Like `metaKey` but for the optimize phase
|
|
164
|
+
*/
|
|
40
165
|
optimizeMetaKey: number | string | symbol | undefined;
|
|
41
166
|
constructor();
|
|
42
167
|
protected withMyLayerPlan<T>(callback: () => T): T;
|
|
43
168
|
protected getStep(id: number): ExecutableStep;
|
|
44
169
|
getDep(depId: number): ExecutableStep;
|
|
170
|
+
/**
|
|
171
|
+
* Like getDep, except it skips over __ItemStep and similar steps to get to
|
|
172
|
+
* where the parent really is.
|
|
173
|
+
*
|
|
174
|
+
* @experimental
|
|
175
|
+
*/
|
|
45
176
|
protected getDepDeep(depId: number): ExecutableStep;
|
|
46
177
|
toString(): string;
|
|
47
178
|
protected addDependency(step: ExecutableStep, skipDeduplication?: boolean): number;
|
|
179
|
+
/**
|
|
180
|
+
* Given a list of "peer" steps, return a list of these `peers` that are
|
|
181
|
+
* equivalent to this step.
|
|
182
|
+
*
|
|
183
|
+
* NOTE: equivalence goes both ways: `a.deduplicate([b]).includes(b)` if and
|
|
184
|
+
* only if `b.deduplicate([a]).includes(a)`.
|
|
185
|
+
*
|
|
186
|
+
* If you need to transform the peer to be equivalent you should do so via
|
|
187
|
+
* the `deduplicatedWith` callback later.
|
|
188
|
+
*/
|
|
48
189
|
deduplicate?(_peers: readonly ExecutableStep[]): readonly ExecutableStep[];
|
|
190
|
+
/**
|
|
191
|
+
* If this plan is replaced via deduplication, this method gives it a chance
|
|
192
|
+
* to hand over its responsibilities to its replacement.
|
|
193
|
+
*/
|
|
49
194
|
deduplicatedWith?(replacement: ExecutableStep): void;
|
|
195
|
+
/**
|
|
196
|
+
* Our chance to optimise the plan (which could go as far as to inline the
|
|
197
|
+
* plan into the parent plan).
|
|
198
|
+
*/
|
|
50
199
|
optimize?(_options: StepOptimizeOptions): ExecutableStep;
|
|
51
200
|
finalize(): void;
|
|
201
|
+
/**
|
|
202
|
+
* This function will be called with a `values` list: an array of entries for
|
|
203
|
+
* each incoming grafast object, where each entry in the array is a list of
|
|
204
|
+
* the values retrieved from executing the plans in `this.dependencies` for
|
|
205
|
+
* that grafast object.
|
|
206
|
+
*
|
|
207
|
+
* It must return a list with the same length as `values`, where each value
|
|
208
|
+
* in the list relates to the result of executing this plan for the
|
|
209
|
+
* corresponding entry in the `values` list.
|
|
210
|
+
*
|
|
211
|
+
* IMPORTANT: it is up to the execute function to cache/memoize results as
|
|
212
|
+
* appropriate for performance, this can be done via the `meta` object.
|
|
213
|
+
*
|
|
214
|
+
* The `meta` object is an empty object stored to `grafastContext.metaByPlan`
|
|
215
|
+
* that can be used to store anything this plan needs. We recommend that you
|
|
216
|
+
* add attributes to meta for each purpose (e.g. use `meta.cache` for
|
|
217
|
+
* memoizing results) so that you can expand your usage of meta in future.
|
|
218
|
+
*/
|
|
52
219
|
execute(count: number, values: ReadonlyArray<GrafastValuesList<any>>, extra: ExecutionExtra): PromiseOrDirect<GrafastResultsList<TData>>;
|
|
53
220
|
destroy(): void;
|
|
54
221
|
}
|
|
@@ -79,6 +246,11 @@ export declare function isObjectLikeStep<TData extends {
|
|
|
79
246
|
[key: string]: ExecutableStep;
|
|
80
247
|
}>(plan: ExecutableStep): plan is ObjectLikeStep<TData>;
|
|
81
248
|
export type StreamableStep<TData> = ExecutableStep<ReadonlyArray<TData>> & {
|
|
249
|
+
/**
|
|
250
|
+
* If this plan supports streaming then it should implement this method. It's
|
|
251
|
+
* basically the same as `execute` except it returns a list of result streams
|
|
252
|
+
* rather than a list of results.
|
|
253
|
+
*/
|
|
82
254
|
stream(count: number, values: ReadonlyArray<GrafastValuesList<any>>, extra: ExecutionExtra, streamOptions: {
|
|
83
255
|
initialCount: number;
|
|
84
256
|
}): PromiseOrDirect<GrafastResultStreamList<TData>>;
|
|
@@ -88,12 +260,23 @@ export type PolymorphicStep = ExecutableStep & {
|
|
|
88
260
|
planForType(objectType: GraphQLObjectType): ExecutableStep;
|
|
89
261
|
};
|
|
90
262
|
export declare function isPolymorphicStep(s: ExecutableStep): s is PolymorphicStep;
|
|
263
|
+
/**
|
|
264
|
+
* Modifier plans modify their parent plan (which may be another ModifierStep
|
|
265
|
+
* or an ExecutableStep). First they gather all the requirements from their
|
|
266
|
+
* children (if any) being applied to them, then they apply themselves to their
|
|
267
|
+
* parent plan. This application is done through the `apply()` method.
|
|
268
|
+
*
|
|
269
|
+
* Modifier plans do not use dependencies.
|
|
270
|
+
*/
|
|
91
271
|
export declare abstract class ModifierStep<TParentStep extends BaseStep = BaseStep> extends BaseStep {
|
|
92
272
|
protected readonly $parent: TParentStep;
|
|
93
273
|
static $$export: any;
|
|
94
274
|
readonly id: string;
|
|
95
275
|
constructor($parent: TParentStep);
|
|
96
276
|
toString(): string;
|
|
277
|
+
/**
|
|
278
|
+
* In this method, you should apply the changes to your `this.$parent` plan
|
|
279
|
+
*/
|
|
97
280
|
abstract apply(): void;
|
|
98
281
|
}
|
|
99
282
|
export declare function isModifierStep<TParentStep extends ExecutableStep | ModifierStep<any>>(plan: BaseStep): plan is ModifierStep<TParentStep>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { GraphQLScalarType, ListValueNode, ObjectValueNode } from "graphql";
|
|
2
2
|
import type { ExecutionExtra } from "../interfaces.js";
|
|
3
3
|
import { UnbatchedExecutableStep } from "../step.js";
|
|
4
|
+
/**
|
|
5
|
+
* Handles "leaves" (scalars)
|
|
6
|
+
*/
|
|
4
7
|
export declare class __InputDynamicScalarStep<TLeaf = any> extends UnbatchedExecutableStep<TLeaf> {
|
|
5
8
|
private value;
|
|
6
9
|
static $$export: {
|
|
@@ -3,6 +3,9 @@ import * as graphql from "graphql";
|
|
|
3
3
|
import type { InputStep, NotVariableValueNode } from "../interfaces.js";
|
|
4
4
|
import { ExecutableStep } from "../step.js";
|
|
5
5
|
import type { ConstantStep } from "./constant.js";
|
|
6
|
+
/**
|
|
7
|
+
* Implements `__InputListStep`.
|
|
8
|
+
*/
|
|
6
9
|
export declare class __InputListStep<TInputType extends graphql.GraphQLList<GraphQLInputType> = graphql.GraphQLList<GraphQLInputType>> extends ExecutableStep {
|
|
7
10
|
private readonly inputValues;
|
|
8
11
|
static $$export: {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { GraphQLInputObjectType } from "graphql";
|
|
2
2
|
import type { ExecutionExtra, InputStep, NotVariableValueNode } from "../interfaces.js";
|
|
3
3
|
import { UnbatchedExecutableStep } from "../step.js";
|
|
4
|
+
/**
|
|
5
|
+
* Implements `InputObjectStep`
|
|
6
|
+
*/
|
|
4
7
|
export declare class __InputObjectStep<TInputType extends GraphQLInputObjectType = GraphQLInputObjectType> extends UnbatchedExecutableStep {
|
|
5
8
|
private inputObjectType;
|
|
6
9
|
private inputValues;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { BooleanValueNode, EnumValueNode, FloatValueNode, GraphQLLeafType, IntValueNode, NullValueNode, StringValueNode } from "graphql";
|
|
2
2
|
import { UnbatchedExecutableStep } from "../step.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implements `InputStaticLeafStep`
|
|
5
|
+
*
|
|
6
|
+
* @see __InputDynamicScalarStep
|
|
7
|
+
*/
|
|
3
8
|
export declare class __InputStaticLeafStep<TLeaf = any> extends UnbatchedExecutableStep<TLeaf> {
|
|
4
9
|
static $$export: {
|
|
5
10
|
moduleName: string;
|
package/dist/steps/__item.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ExecutableStep } from "../step.js";
|
|
2
2
|
import { $$deepDepSkip, $$noExec, UnbatchedExecutableStep } from "../step.js";
|
|
3
|
+
/**
|
|
4
|
+
* An __ItemStep is an internal plan (users must never construct it
|
|
5
|
+
* themselves!) that Grafast uses to refer to an individual item within a list
|
|
6
|
+
* or stream.
|
|
7
|
+
*/
|
|
3
8
|
export declare class __ItemStep<TData> extends UnbatchedExecutableStep<TData> {
|
|
4
9
|
readonly depth: number;
|
|
5
10
|
static $$export: {
|
|
@@ -8,6 +13,9 @@ export declare class __ItemStep<TData> extends UnbatchedExecutableStep<TData> {
|
|
|
8
13
|
};
|
|
9
14
|
isSyncAndSafe: boolean;
|
|
10
15
|
[$$noExec]: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
11
19
|
transformStepId?: number;
|
|
12
20
|
constructor(parentPlan: ExecutableStep<TData> | ExecutableStep<TData[]>, depth?: number);
|
|
13
21
|
toStringMeta(): string;
|
|
@@ -5,28 +5,102 @@ import type { ExecutionExtra, GrafastResultsList, GrafastValuesList } from "../i
|
|
|
5
5
|
import { UnbatchedExecutableStep } from "../step.js";
|
|
6
6
|
import type { __ValueStep } from "./__value.js";
|
|
7
7
|
import type { AccessStep } from "./access.js";
|
|
8
|
+
/**
|
|
9
|
+
* Implements the `__TrackedValueStep(operationPlan, object, constraints, path)`
|
|
10
|
+
* algorithm used to allow runtime AND plan-time access to the three special
|
|
11
|
+
* entities: `variableValues`, `rootValue` and `context`.
|
|
12
|
+
*
|
|
13
|
+
* ExecutableStep-time access can evaluate the `object` passed to the constructor, and
|
|
14
|
+
* will add constraints to the relevant operationPlan.variableValuesConstraints,
|
|
15
|
+
* operationPlan.rootValueConstraints or operationPlan.contextConstraints to
|
|
16
|
+
* ensure that all future variableValues, rootValues and context will match the
|
|
17
|
+
* assumptions made.
|
|
18
|
+
*
|
|
19
|
+
* Run-time access will see the runtime values of these properties, it will
|
|
20
|
+
* **NOT** reference the `object` passed to the constructor.
|
|
21
|
+
*
|
|
22
|
+
* In core this will be used for evaluating `@skip`, `@include`, `@defer` and
|
|
23
|
+
* `@stream` directives so that a different OpPlan will be used if these would
|
|
24
|
+
* change the query plan, but it can also be used within plan resolvers to
|
|
25
|
+
* branch the logic of a plan based on something in these entities.
|
|
26
|
+
*/
|
|
8
27
|
export declare class __TrackedValueStep<TData = any, TInputType extends GraphQLInputType | ReadonlyArray<VariableDefinitionNode> | undefined = undefined> extends UnbatchedExecutableStep<TData> {
|
|
9
28
|
static $$export: {
|
|
10
29
|
moduleName: string;
|
|
11
30
|
exportName: string;
|
|
12
31
|
};
|
|
13
32
|
isSyncAndSafe: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Could be anything. In the case of context it could even have exotic
|
|
35
|
+
* entries such as `pgClient`.
|
|
36
|
+
*/
|
|
14
37
|
private readonly value;
|
|
38
|
+
/**
|
|
39
|
+
* A reference to the relevant
|
|
40
|
+
* operationPlan.variableValuesConstraints/contextConstraints/rootValueConstraints.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
15
44
|
private readonly constraints;
|
|
45
|
+
/**
|
|
46
|
+
* The path that we are through the original value (the one that
|
|
47
|
+
* `constraints` relates to).
|
|
48
|
+
*/
|
|
16
49
|
private readonly path;
|
|
17
50
|
static withGraphQLType<TInputType extends GraphQLInputType, TData = any>(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path: (string | number)[] | undefined, graphqlType: TInputType): __TrackedValueStepWithDollars<TData, TInputType>;
|
|
18
51
|
private nullableGraphQLType;
|
|
19
52
|
private variableDefinitions;
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
20
56
|
constructor(value: TData | undefined, valuePlan: __ValueStep<TData> | AccessStep<TData>, constraints: Constraint[], path?: Array<string | number>, graphqlTypeOrVariableDefinitions?: TInputType);
|
|
21
57
|
execute(_count: number, values: [GrafastValuesList<TData>]): GrafastResultsList<TData>;
|
|
22
58
|
unbatchedExecute(_extra: ExecutionExtra, v: TData): TData;
|
|
23
59
|
private getValuePlan;
|
|
60
|
+
/**
|
|
61
|
+
* Get the named property of an object.
|
|
62
|
+
*/
|
|
24
63
|
get<TAttribute extends keyof TData & string>(attrName: TAttribute): __TrackedValueStepWithDollars<TData[TAttribute], TInputType extends GraphQLInputObjectType ? ReturnType<TInputType["getFields"]>[TAttribute]["type"] : undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the entry at the given index in an array.
|
|
66
|
+
*/
|
|
25
67
|
at<TIndex extends keyof TData & number>(index: TIndex): __TrackedValueStepWithDollars<TData[TIndex], TInputType extends GraphQLList<infer U> ? U & GraphQLInputType : TInputType extends GraphQLNonNull<GraphQLList<infer U>> ? U & GraphQLInputType : undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* Evaluates the current value, and adds a constraint to the OpPlan to ensure
|
|
70
|
+
* that all future evaluations of this property will always return the same
|
|
71
|
+
* value.
|
|
72
|
+
*
|
|
73
|
+
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
|
|
74
|
+
*
|
|
75
|
+
* **WARNING**: this is the most expensive eval, if you need to eval, prefer evalIs, evalHas, etc instead.
|
|
76
|
+
*/
|
|
26
77
|
eval(): TData | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Evaluates if the current value is equal to this specific value, and adds a
|
|
80
|
+
* constraint to the OpPlan to ensure that all future evaluations of this
|
|
81
|
+
* check will always return the same (boolean) result.
|
|
82
|
+
*
|
|
83
|
+
* Should only be used on scalars.
|
|
84
|
+
*
|
|
85
|
+
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
|
|
86
|
+
*/
|
|
27
87
|
evalIs(expectedValue: unknown): boolean;
|
|
28
88
|
evalIsEmpty(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Evaluates if the current value is an object with the given key, and adds a
|
|
91
|
+
* constraint to the OpPlan to ensure that all future evaluations of this
|
|
92
|
+
* check will always return the same (boolean) result.
|
|
93
|
+
*
|
|
94
|
+
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
|
|
95
|
+
*/
|
|
29
96
|
evalHas(key: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Evaluates the length of the current value (assumed to be an array), and
|
|
99
|
+
* adds a constraint to the OpPlan to ensure that all future values will have
|
|
100
|
+
* the same length.
|
|
101
|
+
*
|
|
102
|
+
* **WARNING**: avoid using this where possible, it causes OpPlans to split.
|
|
103
|
+
*/
|
|
30
104
|
evalLength(): number | null;
|
|
31
105
|
optimize(): import("../step.js").ExecutableStep<any>;
|
|
32
106
|
}
|
package/dist/steps/__value.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { $$noExec, ExecutableStep } from "../step.js";
|
|
2
2
|
import type { AccessStep } from "./access.js";
|
|
3
|
+
/**
|
|
4
|
+
* Implements `__ValueStep(operationPlan)` which is never executed; it's purely
|
|
5
|
+
* internal - we populate the value as part of the algorithm - see
|
|
6
|
+
* `GetValueStepId` and `PopulateValueStep`.
|
|
7
|
+
*/
|
|
3
8
|
export declare class __ValueStep<TData> extends ExecutableStep<TData> {
|
|
4
9
|
static $$export: {
|
|
5
10
|
moduleName: string;
|
package/dist/steps/access.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { ExecutionExtra } from "../interfaces.js";
|
|
2
2
|
import type { ExecutableStep } from "../step.js";
|
|
3
3
|
import { UnbatchedExecutableStep } from "../step.js";
|
|
4
|
+
/** @internal */
|
|
4
5
|
export declare const expressionSymbol: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Accesses a (potentially nested) property from the result of a plan.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: this could lead to unexpected results (which could introduce security
|
|
10
|
+
* issues) if it is not used carefully; only use it on JSON-like data,
|
|
11
|
+
* preferably where the objects have null prototypes, and be sure to adhere to
|
|
12
|
+
* the naming conventions detailed in assertSafeToAccessViaBraces.
|
|
13
|
+
*/
|
|
5
14
|
export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
|
|
6
15
|
readonly fallback?: any;
|
|
7
16
|
static $$export: {
|
|
@@ -13,11 +22,22 @@ export declare class AccessStep<TData> extends UnbatchedExecutableStep<TData> {
|
|
|
13
22
|
readonly path: (string | number | symbol)[];
|
|
14
23
|
constructor(parentPlan: ExecutableStep<unknown>, path: (string | number | symbol)[], fallback?: any);
|
|
15
24
|
toStringMeta(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get the named property of an object.
|
|
27
|
+
*/
|
|
16
28
|
get<TAttr extends keyof TData>(attrName: TAttr): AccessStep<TData[TAttr]>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the entry at the given index in an array.
|
|
31
|
+
*/
|
|
17
32
|
at<TIndex extends keyof TData>(index: TIndex): AccessStep<TData[TIndex]>;
|
|
18
33
|
optimize(): AccessStep<TData>;
|
|
34
|
+
finalize(): void;
|
|
19
35
|
unbatchedExecute(_extra: ExecutionExtra, ..._values: any[]): any;
|
|
20
36
|
deduplicate(peers: AccessStep<unknown>[]): AccessStep<TData>[];
|
|
21
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Access the property at path `path` in the value returned from `parentPlan`,
|
|
40
|
+
* falling back to `fallback` if it were null-ish.
|
|
41
|
+
*/
|
|
22
42
|
export declare function access<TData>(parentPlan: ExecutableStep<unknown>, path: (string | number | symbol)[] | string | number | symbol, fallback?: any): AccessStep<TData>;
|
|
23
43
|
//# sourceMappingURL=access.d.ts.map
|