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/utils.d.ts CHANGED
@@ -4,30 +4,65 @@ import type { Deferred } from "./deferred.js";
4
4
  import type { OperationPlan } from "./engine/OperationPlan.js";
5
5
  import type { BaseGraphQLArguments, GrafastFieldConfig, GrafastInputFieldConfig, InputStep, OutputPlanForType } from "./interfaces.js";
6
6
  import type { ExecutableStep, ModifierStep } from "./step.js";
7
+ /**
8
+ * The parent object is used as the key in `GetValueStepId()`; for root level
9
+ * fields it's possible that the parent will be null/undefined (in all other
10
+ * cases it will be an object), so we need a value that can be the key in a
11
+ * WeakMap to represent the root.
12
+ */
7
13
  export declare const ROOT_VALUE_OBJECT: any;
8
14
  export declare function assertNullPrototype(object: Record<string, unknown>, description: string): void;
15
+ /**
16
+ * Specifically allows for the `defaultValue` to be undefined, but otherwise
17
+ * defers to {@link rawValueToValueNode}
18
+ */
9
19
  export declare function defaultValueToValueNode(type: GraphQLInputType, defaultValue: unknown): ConstValueNode | undefined;
10
20
  export declare function isPromise<T>(t: T | Promise<T>): t is Promise<T>;
21
+ /**
22
+ * Is "thenable".
23
+ */
11
24
  export declare function isPromiseLike<T>(t: T | Promise<T> | PromiseLike<T>): t is PromiseLike<T>;
25
+ /**
26
+ * Is a promise that can be externally resolved.
27
+ */
12
28
  export declare function isDeferred<T>(t: T | Promise<T> | Deferred<T>): t is Deferred<T>;
29
+ /**
30
+ * Returns true if array1 and array2 have the same length, and every pair of
31
+ * values within them pass the `comparator` check (which defaults to `===`).
32
+ */
13
33
  export declare function arraysMatch<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T>, comparator?: (val1: T, val2: T) => boolean): boolean;
14
34
  export type ObjectTypeFields<TContext extends Grafast.Context, TParentStep extends ExecutableStep> = {
15
35
  [key: string]: GrafastFieldConfig<GraphQLOutputType, TContext, TParentStep, any, any>;
16
36
  };
17
37
  export type ObjectTypeSpec<TContext extends Grafast.Context, TParentStep extends ExecutableStep, TFields extends ObjectTypeFields<TContext, TParentStep>> = Omit<GraphQLObjectTypeConfig<any, TContext>, "fields"> & {
18
38
  fields: TFields | (() => TFields);
39
+ assertStep?: TParentStep extends ExecutableStep ? ((step: ExecutableStep) => asserts step is TParentStep) | {
40
+ new (...args: any[]): TParentStep;
41
+ } : null;
19
42
  };
20
- export declare function objectSpec<TContext extends Grafast.Context, TParentStep extends ExecutableStep, TFields extends ObjectTypeFields<TContext, TParentStep>>(spec: ObjectTypeSpec<TContext, TParentStep, TFields>, Step: ((step: ExecutableStep) => asserts step is ExecutableStep) | {
21
- new (...args: any[]): TParentStep;
22
- } | null): GraphQLObjectTypeConfig<any, TContext>;
43
+ /**
44
+ * Saves us having to write `extensions: {grafast: {...}}` everywhere.
45
+ */
46
+ export declare function objectSpec<TContext extends Grafast.Context, TParentStep extends ExecutableStep, TFields extends ObjectTypeFields<TContext, TParentStep>>(spec: ObjectTypeSpec<TContext, TParentStep, TFields>): GraphQLObjectTypeConfig<any, TContext>;
23
47
  export type GrafastObjectType<TContext extends Grafast.Context, TParentStep extends ExecutableStep, TFields extends ObjectTypeFields<TContext, TParentStep>> = graphql.GraphQLObjectType<TParentStep extends ExecutableStep<infer U> ? U : never, TContext> & {
24
48
  TParentStep: TParentStep;
25
49
  TFields: TFields;
26
50
  };
27
- export declare function newObjectTypeBuilder<TContext extends Grafast.Context, TParentStep extends ExecutableStep>(Step: {
51
+ /**
52
+ * @remarks This is a mess because the first two generics need to be specified manually, but the latter one we want inferred.
53
+ */
54
+ export declare function newObjectTypeBuilder<TContext extends Grafast.Context, TParentStep extends ExecutableStep>(assertStep: TParentStep extends ExecutableStep ? ((step: ExecutableStep) => asserts step is TParentStep) | {
28
55
  new (...args: any[]): TParentStep;
29
- }): <TFields extends ObjectTypeFields<TContext, TParentStep>>(spec: ObjectTypeSpec<TContext, TParentStep, TFields>) => GrafastObjectType<TContext, TParentStep, TFields>;
56
+ } : never): <TFields extends ObjectTypeFields<TContext, TParentStep>>(spec: ObjectTypeSpec<TContext, TParentStep, TFields>) => GrafastObjectType<TContext, TParentStep, TFields>;
57
+ /**
58
+ * Saves us having to write `extensions: {grafast: {...}}` everywhere.
59
+ */
30
60
  export declare function objectFieldSpec<TContext extends Grafast.Context, TSource extends ExecutableStep, TResult extends ExecutableStep = ExecutableStep, TArgs extends BaseGraphQLArguments = BaseGraphQLArguments>(grafastSpec: GrafastFieldConfig<GraphQLOutputType, TContext, TSource, TResult, TArgs>, path: string): GraphQLFieldConfig<any, TContext, TArgs>;
61
+ /**
62
+ * "Constrainted identity function" for field configs.
63
+ *
64
+ * @see {@link https://kentcdodds.com/blog/how-to-write-a-constrained-identity-function-in-typescript}
65
+ */
31
66
  export declare function newGrafastFieldConfigBuilder<TContext extends Grafast.Context, TParentStep extends ExecutableStep>(): <TType extends GraphQLOutputType, TFieldStep extends OutputPlanForType<TType>, TArgs extends BaseGraphQLArguments>(config: GrafastFieldConfig<TType, TContext, TParentStep, TFieldStep, TArgs>) => typeof config;
32
67
  export type GrafastInputFieldConfigMap<TContext extends Grafast.Context, TParentStep extends ModifierStep<any>> = {
33
68
  [key: string]: GrafastInputFieldConfig<GraphQLInputType, TContext, TParentStep, any, any>;
@@ -41,6 +76,9 @@ export type GrafastInputObjectType<TContext extends Grafast.Context, TParentStep
41
76
  TFields: TFields;
42
77
  };
43
78
  export declare function newInputObjectTypeBuilder<TContext extends Grafast.Context, TParentStep extends ModifierStep<any>>(): <TFields extends GrafastInputFieldConfigMap<TContext, TParentStep>>(spec: InputObjectTypeSpec<TContext, TParentStep, TFields>) => GrafastInputObjectType<TContext, TParentStep, TFields>;
79
+ /**
80
+ * Saves us having to write `extensions: {grafast: {...}}` everywhere.
81
+ */
44
82
  export declare function inputObjectFieldSpec<TContext extends Grafast.Context, TParent extends ModifierStep<any>, TResult extends ModifierStep<TParent> = ModifierStep<TParent>, TInput extends InputStep = InputStep>(grafastSpec: GrafastInputFieldConfig<GraphQLInputType, TContext, TParent, TResult, TInput>, path: string): GraphQLInputFieldConfig;
45
83
  declare module "graphql" {
46
84
  interface GraphQLEnumType {
@@ -48,17 +86,87 @@ declare module "graphql" {
48
86
  }
49
87
  }
50
88
  declare const $$valueConfigByValue: unique symbol;
89
+ /**
90
+ * This would be equivalent to `enumType._valueLookup.get(outputValue)` except
91
+ * that's not a public API so we have to do a bit of heavy lifting here. Since
92
+ * it is heavy lifting, we cache the result, but we don't know when enumType
93
+ * will go away so we use a weakmap.
94
+ */
51
95
  export declare function getEnumValueConfig(enumType: graphql.GraphQLEnumType, outputValue: string): GraphQLEnumValueConfig | undefined;
96
+ /**
97
+ * It's a peculiarity of V8 that `{}` is twice as fast as
98
+ * `Object.create(null)`, but `Object.create(sharedNull)` is the same speed as
99
+ * `{}`. Hat tip to `@purge` for bringing this to my attention.
100
+ *
101
+ * @internal
102
+ */
52
103
  export declare const sharedNull: any;
104
+ /**
105
+ * Prints out the stack trace to the current position with a message; useful
106
+ * for debugging which code path has hit this line.
107
+ *
108
+ * @internal
109
+ */
53
110
  export declare function stack(message: string, length?: number): void;
111
+ /**
112
+ * Ridiculously, this is faster than `new Array(length).fill(fill)`
113
+ *
114
+ * @internal
115
+ */
54
116
  export declare function arrayOfLength(length: number, fill?: any): any[];
117
+ /**
118
+ * Builds an array of length `length` calling `fill` for each entry in the
119
+ * list and storing the result.
120
+ *
121
+ * @internal
122
+ */
55
123
  export declare function arrayOfLengthCb(length: number, fill: () => any): any[];
124
+ /**
125
+ * Given a FieldNode, recursively walks and finds all the variable references,
126
+ * returning a list of the (unique) variable names used.
127
+ */
56
128
  export declare function findVariableNamesUsed(operationPlan: OperationPlan, field: FieldNode): string[];
57
129
  export declare function isTypePlanned(schema: GraphQLSchema, namedType: GraphQLNamedType): boolean;
58
130
  export declare function stepADependsOnStepB(stepA: ExecutableStep, stepB: ExecutableStep): boolean;
131
+ /**
132
+ * Returns true if stepA is allowed to depend on stepB, false otherwise. (This
133
+ * mostly relates to heirarchy.)
134
+ */
59
135
  export declare function stepAMayDependOnStepB($a: ExecutableStep, $b: ExecutableStep): boolean;
136
+ /**
137
+ * For a regular GraphQL query with no `@stream`/`@defer`, the entire result is
138
+ * calculated and then the output is generated and sent to the client at once.
139
+ * Thus you can think of this as every plan is in the same "phase".
140
+ *
141
+ * However, if you introduce a `@stream`/`@defer` selection, then the steps
142
+ * inside that selection should run _later_ than the steps in the parent
143
+ * selection - they should run in two different phases. Similar is true for
144
+ * subscriptions.
145
+ *
146
+ * When optimizing your plans, if you are not careful you may end up pushing
147
+ * what should be later work into the earlier phase, resulting in the initial
148
+ * payload being delayed whilst things that should have been deferred are being
149
+ * calculated. Thus, you should generally check that two plans are in the same phase
150
+ * before you try and merge them.
151
+ *
152
+ * This is not a strict rule, though, because sometimes it makes more sense to
153
+ * push work into the parent phase because it would be faster overall to do
154
+ * that work there, and would not significantly delay the initial payload's
155
+ * execution time - for example it's unlikely that it would make sense to defer
156
+ * selecting an additional boolean column from a database table even if the
157
+ * operation indicates that's what you should do.
158
+ *
159
+ * As a step class author, it's your responsiblity to figure out the right
160
+ * approach. Once you have, you can use this function to help you, should you
161
+ * need it.
162
+ */
60
163
  export declare function stepsAreInSamePhase(ancestor: ExecutableStep, descendent: ExecutableStep): boolean;
61
164
  export declare const canonicalJSONStringify: (o: object) => string;
62
165
  export declare function assertNotAsync(fn: any, name: string): void;
166
+ export declare function hasItemPlan(step: ExecutableStep & {
167
+ itemPlan?: ($item: ExecutableStep) => ExecutableStep;
168
+ }): step is ExecutableStep & {
169
+ itemPlan: ($item: ExecutableStep) => ExecutableStep;
170
+ };
63
171
  export {};
64
172
  //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.0.1-beta.2";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ export * from "graphql";
@@ -0,0 +1 @@
1
+ module.exports = require("graphql");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grafast",
3
- "version": "0.0.1-alpha.9",
3
+ "version": "0.0.1-beta.2",
4
4
  "description": "Cutting edge GraphQL planning and execution engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,6 +14,11 @@
14
14
  "types": "./dist/envelop.d.ts",
15
15
  "node": "./dist/envelop.js",
16
16
  "default": "./dist/envelop.js"
17
+ },
18
+ "./graphql": {
19
+ "types": "./fwd/graphql/index.d.ts",
20
+ "node": "./fwd/graphql/index.js",
21
+ "default": "./fwd/graphql/index.js"
17
22
  }
18
23
  },
19
24
  "repository": {
@@ -36,7 +41,7 @@
36
41
  "graphite"
37
42
  ],
38
43
  "author": "Benjie Gillam <code@benjiegillam.com>",
39
- "license": "SEE LICENSE IN LICENSE.md",
44
+ "license": "MIT",
40
45
  "bugs": {
41
46
  "url": "https://github.com/graphile/heart/issues"
42
47
  },
@@ -45,14 +50,16 @@
45
50
  "node": ">=14.17"
46
51
  },
47
52
  "dependencies": {
48
- "@graphile/lru": "^5.0.0-alpha.2",
53
+ "@graphile/lru": "^5.0.0-beta.1",
49
54
  "debug": "^4.3.3",
50
- "tamedevil": "^0.0.0-alpha.3"
55
+ "graphql": "^16.1.0-experimental-stream-defer.6",
56
+ "tamedevil": "^0.0.0-beta.1"
51
57
  },
52
58
  "peerDependencies": {
53
59
  "@envelop/core": "^3.0.4",
54
- "graphile-config": "^0.0.1-alpha.4",
55
- "graphql": "^16.1.0-experimental-stream-defer.6"
60
+ "graphile-config": "^0.0.1-beta.1",
61
+ "graphql": "^16.1.0-experimental-stream-defer.6",
62
+ "tamedevil": "^0.0.0-beta.1"
56
63
  },
57
64
  "peerDependenciesMeta": {
58
65
  "@envelop/core": {
@@ -63,6 +70,7 @@
63
70
  }
64
71
  },
65
72
  "files": [
73
+ "fwd",
66
74
  "dist"
67
75
  ],
68
76
  "publishConfig": {