grafast 0.1.1-beta.20 → 0.1.1-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/args.js +2 -3
  2. package/dist/assert.js +2 -3
  3. package/dist/constraints.js +1 -2
  4. package/dist/deferred.js +1 -2
  5. package/dist/dev.js +2 -2
  6. package/dist/engine/LayerPlan.d.ts +20 -16
  7. package/dist/engine/LayerPlan.js +5 -10
  8. package/dist/engine/OperationPlan.d.ts +12 -13
  9. package/dist/engine/OperationPlan.js +210 -146
  10. package/dist/engine/OutputPlan.d.ts +4 -4
  11. package/dist/engine/OutputPlan.js +13 -10
  12. package/dist/engine/StepTracker.js +11 -2
  13. package/dist/engine/executeBucket.js +135 -94
  14. package/dist/engine/executeOutputPlan.js +1 -2
  15. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  16. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  17. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -2
  18. package/dist/engine/lib/withGlobalLayerPlan.js +4 -5
  19. package/dist/engine/lock.d.ts +3 -3
  20. package/dist/engine/lock.js +3 -3
  21. package/dist/error.js +4 -4
  22. package/dist/establishOperationPlan.js +2 -3
  23. package/dist/execute.js +3 -4
  24. package/dist/exportAs.js +2 -3
  25. package/dist/global.js +2 -3
  26. package/dist/grafastGraphql.js +2 -3
  27. package/dist/grafastPrint.js +7 -8
  28. package/dist/graphqlCollectFields.js +6 -7
  29. package/dist/graphqlMergeSelectionSets.js +1 -2
  30. package/dist/index.d.ts +22 -18
  31. package/dist/index.js +41 -16
  32. package/dist/input.js +75 -28
  33. package/dist/inspect.d.ts +9 -4
  34. package/dist/inspect.js +2 -2
  35. package/dist/interfaces.d.ts +110 -89
  36. package/dist/makeGrafastSchema.d.ts +18 -9
  37. package/dist/makeGrafastSchema.js +64 -30
  38. package/dist/mermaid.js +53 -14
  39. package/dist/middleware.js +1 -2
  40. package/dist/multistep.d.ts +6 -6
  41. package/dist/multistep.js +6 -7
  42. package/dist/operationPlan-input.d.ts +5 -4
  43. package/dist/operationPlan-input.js +131 -399
  44. package/dist/planJSONInterfaces.d.ts +6 -2
  45. package/dist/polymorphic.js +4 -5
  46. package/dist/prepare.js +6 -6
  47. package/dist/step.d.ts +67 -99
  48. package/dist/step.js +99 -127
  49. package/dist/steps/__flag.d.ts +16 -16
  50. package/dist/steps/__flag.js +9 -6
  51. package/dist/steps/__inputDefault.d.ts +14 -0
  52. package/dist/steps/__inputDefault.js +48 -0
  53. package/dist/steps/__inputDynamicScalar.d.ts +2 -4
  54. package/dist/steps/__inputDynamicScalar.js +4 -2
  55. package/dist/steps/__inputList.d.ts +5 -9
  56. package/dist/steps/__inputList.js +4 -1
  57. package/dist/steps/__inputObject.d.ts +6 -11
  58. package/dist/steps/__inputObject.js +13 -3
  59. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  60. package/dist/steps/__inputStaticLeaf.js +3 -1
  61. package/dist/steps/__item.d.ts +6 -6
  62. package/dist/steps/__item.js +1 -1
  63. package/dist/steps/__trackedValue.d.ts +4 -49
  64. package/dist/steps/__trackedValue.js +24 -6
  65. package/dist/steps/__value.d.ts +3 -3
  66. package/dist/steps/__value.js +3 -2
  67. package/dist/steps/access.d.ts +7 -6
  68. package/dist/steps/access.js +14 -7
  69. package/dist/steps/applyInput.d.ts +44 -0
  70. package/dist/steps/applyInput.js +206 -0
  71. package/dist/steps/applyTransforms.d.ts +2 -2
  72. package/dist/steps/applyTransforms.js +7 -5
  73. package/dist/steps/bakedInput.d.ts +23 -0
  74. package/dist/steps/bakedInput.js +90 -0
  75. package/dist/steps/condition.d.ts +5 -5
  76. package/dist/steps/condition.js +3 -3
  77. package/dist/steps/connection.d.ts +42 -39
  78. package/dist/steps/connection.js +51 -35
  79. package/dist/steps/constant.d.ts +4 -8
  80. package/dist/steps/constant.js +54 -6
  81. package/dist/steps/each.d.ts +3 -3
  82. package/dist/steps/each.js +1 -2
  83. package/dist/steps/error.d.ts +2 -2
  84. package/dist/steps/error.js +3 -3
  85. package/dist/steps/filter.d.ts +3 -2
  86. package/dist/steps/filter.js +1 -2
  87. package/dist/steps/first.d.ts +6 -5
  88. package/dist/steps/first.js +5 -4
  89. package/dist/steps/graphqlResolver.d.ts +2 -2
  90. package/dist/steps/graphqlResolver.js +44 -56
  91. package/dist/steps/groupBy.d.ts +3 -2
  92. package/dist/steps/groupBy.js +1 -2
  93. package/dist/steps/index.d.ts +4 -2
  94. package/dist/steps/index.js +21 -9
  95. package/dist/steps/lambda.d.ts +5 -5
  96. package/dist/steps/lambda.js +4 -4
  97. package/dist/steps/last.d.ts +6 -5
  98. package/dist/steps/last.js +5 -4
  99. package/dist/steps/list.d.ts +7 -7
  100. package/dist/steps/list.js +3 -3
  101. package/dist/steps/listTransform.d.ts +14 -12
  102. package/dist/steps/listTransform.js +14 -7
  103. package/dist/steps/listen.d.ts +6 -8
  104. package/dist/steps/listen.js +7 -7
  105. package/dist/steps/load.d.ts +6 -6
  106. package/dist/steps/load.js +7 -7
  107. package/dist/steps/node.d.ts +16 -10
  108. package/dist/steps/node.js +14 -7
  109. package/dist/steps/object.d.ts +11 -11
  110. package/dist/steps/object.js +5 -5
  111. package/dist/steps/partitionByIndex.d.ts +3 -2
  112. package/dist/steps/partitionByIndex.js +1 -2
  113. package/dist/steps/polymorphicBranch.d.ts +8 -8
  114. package/dist/steps/polymorphicBranch.js +4 -4
  115. package/dist/steps/proxy.d.ts +8 -8
  116. package/dist/steps/proxy.js +3 -3
  117. package/dist/steps/remapKeys.d.ts +6 -6
  118. package/dist/steps/remapKeys.js +3 -3
  119. package/dist/steps/reverse.d.ts +5 -5
  120. package/dist/steps/reverse.js +4 -4
  121. package/dist/steps/setter.d.ts +9 -18
  122. package/dist/steps/setter.js +24 -14
  123. package/dist/steps/sideEffect.d.ts +4 -4
  124. package/dist/steps/sideEffect.js +3 -3
  125. package/dist/stringifyPayload.js +1 -2
  126. package/dist/stripAnsi.js +2 -2
  127. package/dist/subscribe.js +2 -3
  128. package/dist/timeSource.d.ts +0 -1
  129. package/dist/utils.d.ts +43 -31
  130. package/dist/utils.js +97 -61
  131. package/dist/version.d.ts +1 -1
  132. package/dist/version.js +1 -1
  133. package/package.json +2 -2
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { ConstValueNode, FieldNode, GraphQLEnumValueConfig, GraphQLFieldConfig, GraphQLInputFieldConfig, GraphQLInputObjectTypeConfig, GraphQLInputType, GraphQLNamedType, GraphQLObjectTypeConfig, GraphQLOutputType, GraphQLSchema } from "graphql";
1
+ import type { ConstValueNode, DirectiveNode, FieldNode, GraphQLEnumValueConfig, GraphQLFieldConfig, GraphQLInputFieldConfig, GraphQLInputObjectTypeConfig, GraphQLInputType, GraphQLNamedType, GraphQLObjectTypeConfig, GraphQLOutputType, GraphQLSchema, ValueNode } from "graphql";
2
2
  import * as graphql from "graphql";
3
3
  import type { Deferred } from "./deferred.js";
4
4
  import type { OperationPlan } from "./engine/OperationPlan.js";
5
- import type { BaseGraphQLArguments, GrafastFieldConfig, GrafastInputFieldConfig, InputStep, OutputPlanForType } from "./interfaces.js";
6
- import type { ExecutableStep, ModifierStep } from "./step.js";
5
+ import type { BaseGraphQLArguments, GrafastFieldConfig, GrafastInputFieldConfig, OutputPlanForType } from "./interfaces.js";
6
+ import type { Step } from "./step.js";
7
7
  /**
8
8
  * The parent object is used as the key in `GetValueStepId()`; for root level
9
9
  * fields it's possible that the parent will be null/undefined (in all other
@@ -21,7 +21,7 @@ export declare function isPromise<T>(t: T | Promise<T>): t is Promise<T>;
21
21
  /**
22
22
  * Is "thenable".
23
23
  */
24
- export declare function isPromiseLike<T>(t: T | Promise<T> | PromiseLike<T>): t is PromiseLike<T> | Promise<T>;
24
+ export declare function isPromiseLike<T>(t: T | PromiseLike<T>): t is PromiseLike<T>;
25
25
  /**
26
26
  * Is a promise that can be externally resolved.
27
27
  */
@@ -31,61 +31,62 @@ export declare function isDeferred<T>(t: T | Promise<T> | Deferred<T>): t is Def
31
31
  * values within them pass the `comparator` check (which defaults to `===`).
32
32
  */
33
33
  export declare function arraysMatch<T>(array1: ReadonlyArray<T>, array2: ReadonlyArray<T>, comparator?: (val1: T, val2: T) => boolean): boolean;
34
- export type ObjectTypeFields<TContext extends Grafast.Context, TParentStep extends ExecutableStep> = {
35
- [key: string]: GrafastFieldConfig<GraphQLOutputType, TContext, TParentStep, any, any>;
34
+ export type ObjectTypeFields<TParentStep extends Step> = {
35
+ [key: string]: GrafastFieldConfig<GraphQLOutputType, TParentStep, any, any>;
36
36
  };
37
- export type ObjectTypeSpec<TContext extends Grafast.Context, TParentStep extends ExecutableStep, TFields extends ObjectTypeFields<TContext, TParentStep>> = Omit<GraphQLObjectTypeConfig<any, TContext>, "fields"> & {
37
+ export type ObjectTypeSpec<TParentStep extends Step, TFields extends ObjectTypeFields<TParentStep>> = Omit<GraphQLObjectTypeConfig<any, Grafast.Context>, "fields"> & {
38
38
  fields: TFields | (() => TFields);
39
- assertStep?: TParentStep extends ExecutableStep ? ((step: ExecutableStep) => asserts step is TParentStep) | {
39
+ assertStep?: TParentStep extends Step ? ((step: Step) => asserts step is TParentStep) | {
40
40
  new (...args: any[]): TParentStep;
41
41
  } : null;
42
42
  };
43
43
  /**
44
44
  * Saves us having to write `extensions: {grafast: {...}}` everywhere.
45
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>;
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> & {
46
+ export declare function objectSpec<TParentStep extends Step, TFields extends ObjectTypeFields<TParentStep>>(spec: ObjectTypeSpec<TParentStep, TFields>): GraphQLObjectTypeConfig<any, Grafast.Context>;
47
+ export type GrafastObjectType<TParentStep extends Step, TFields extends ObjectTypeFields<TParentStep>> = graphql.GraphQLObjectType<TParentStep extends Step<infer U> ? U : never> & {
48
48
  TParentStep: TParentStep;
49
49
  TFields: TFields;
50
50
  };
51
51
  /**
52
52
  * @remarks This is a mess because the first two generics need to be specified manually, but the latter one we want inferred.
53
53
  */
54
- export declare function newObjectTypeBuilder<TContext extends Grafast.Context, TParentStep extends ExecutableStep>(assertStep: TParentStep extends ExecutableStep ? ((step: ExecutableStep) => asserts step is TParentStep) | {
54
+ export declare function newObjectTypeBuilder<TParentStep extends Step>(assertStep: TParentStep extends Step ? ((step: Step) => asserts step is TParentStep) | {
55
55
  new (...args: any[]): TParentStep;
56
- } : never): <TFields extends ObjectTypeFields<TContext, TParentStep>>(spec: ObjectTypeSpec<TContext, TParentStep, TFields>) => GrafastObjectType<TContext, TParentStep, TFields>;
56
+ } : never): <TFields extends ObjectTypeFields<TParentStep>>(spec: ObjectTypeSpec<TParentStep, TFields>) => GrafastObjectType<TParentStep, TFields>;
57
57
  /**
58
58
  * Saves us having to write `extensions: {grafast: {...}}` everywhere.
59
59
  */
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>;
60
+ export declare function objectFieldSpec<TSource extends Step, TResult extends Step = Step, TArgs extends BaseGraphQLArguments = BaseGraphQLArguments>(grafastSpec: GrafastFieldConfig<GraphQLOutputType, TSource, TResult, TArgs>, path: string): GraphQLFieldConfig<any, TArgs>;
61
61
  /**
62
62
  * "Constrainted identity function" for field configs.
63
63
  *
64
64
  * @see {@link https://kentcdodds.com/blog/how-to-write-a-constrained-identity-function-in-typescript}
65
65
  */
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;
67
- export type GrafastInputFieldConfigMap<TContext extends Grafast.Context, TParentStep extends ModifierStep<any>> = {
68
- [key: string]: GrafastInputFieldConfig<GraphQLInputType, TContext, TParentStep, any, any>;
66
+ export declare function newGrafastFieldConfigBuilder<TParentStep extends Step>(): <TType extends GraphQLOutputType, TFieldStep extends OutputPlanForType<TType>, TArgs extends BaseGraphQLArguments>(config: GrafastFieldConfig<TType, TParentStep, TFieldStep, TArgs>) => typeof config;
67
+ export type GrafastInputFieldConfigMap<TParent> = {
68
+ [key: string]: GrafastInputFieldConfig<TParent, GraphQLInputType>;
69
69
  };
70
- export type InputObjectTypeSpec<TContext extends Grafast.Context, TParentStep extends ModifierStep<any>, TFields extends GrafastInputFieldConfigMap<TContext, TParentStep>> = Omit<GraphQLInputObjectTypeConfig, "fields"> & {
71
- fields: TFields | (() => TFields);
70
+ export type InputObjectTypeSpec<TParent> = Omit<GraphQLInputObjectTypeConfig, "fields"> & {
71
+ fields: GrafastInputFieldConfigMap<TParent> | (() => GrafastInputFieldConfigMap<TParent>);
72
72
  };
73
- export type GrafastInputObjectType<TContext extends Grafast.Context, TParentStep extends ModifierStep<any>, TFields extends GrafastInputFieldConfigMap<TContext, TParentStep>> = graphql.GraphQLInputObjectType & {
74
- TContext: TContext;
75
- TParentStep: TParentStep;
76
- TFields: TFields;
73
+ export type GrafastInputObjectType<TParent> = graphql.GraphQLInputObjectType & {
74
+ TParent: TParent;
77
75
  };
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>;
76
+ export declare function newInputObjectTypeBuilder<TParent = any>(): (spec: InputObjectTypeSpec<TParent>) => GrafastInputObjectType<TParent>;
79
77
  /**
80
78
  * Saves us having to write `extensions: {grafast: {...}}` everywhere.
81
79
  */
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;
80
+ export declare function inputObjectFieldSpec<TParent>(grafastSpec: GrafastInputFieldConfig<TParent, GraphQLInputType>, path: string): GraphQLInputFieldConfig;
83
81
  declare module "graphql" {
84
82
  interface GraphQLEnumType {
85
83
  [$$valueConfigByValue]?: Record<string, GraphQLEnumValueConfig>;
86
84
  }
87
85
  }
88
86
  declare const $$valueConfigByValue: unique symbol;
87
+ export declare function getEnumValueConfigs(enumType: graphql.GraphQLEnumType): {
88
+ [outputValue: string]: GraphQLEnumValueConfig | undefined;
89
+ };
89
90
  /**
90
91
  * This would be equivalent to `enumType._valueLookup.get(outputValue)` except
91
92
  * that's not a public API so we have to do a bit of heavy lifting here. Since
@@ -97,6 +98,8 @@ export declare function getEnumValueConfig(enumType: graphql.GraphQLEnumType, ou
97
98
  * Ridiculously, this is faster than `new Array(length).fill(fill)`
98
99
  */
99
100
  export declare function arrayOfLength(length: number, fill?: any): any[];
101
+ export declare const valueNodeToStaticValue: typeof graphql.valueFromAST;
102
+ export declare function findVariableNamesUsedInValueNode(valueNode: ValueNode, variableNames: Set<string>): void;
100
103
  /**
101
104
  * Given a FieldNode, recursively walks and finds all the variable references,
102
105
  * returning a list of the (unique) variable names used.
@@ -107,12 +110,12 @@ export declare function isTypePlanned(schema: GraphQLSchema, namedType: GraphQLN
107
110
  * Returns `true` if the first argument depends on the second argument either
108
111
  * directly or indirectly (via a chain of dependencies).
109
112
  */
110
- export declare function stepADependsOnStepB(stepA: ExecutableStep, stepB: ExecutableStep): boolean;
113
+ export declare function stepADependsOnStepB(stepA: Step, stepB: Step): boolean;
111
114
  /**
112
115
  * Returns true if stepA is allowed to depend on stepB, false otherwise. (This
113
116
  * mostly relates to heirarchy.)
114
117
  */
115
- export declare function stepAMayDependOnStepB($a: ExecutableStep, $b: ExecutableStep): boolean;
118
+ export declare function stepAMayDependOnStepB($a: Step, $b: Step): boolean;
116
119
  /**
117
120
  * For a regular GraphQL query with no `@stream`/`@defer`, the entire result is
118
121
  * calculated and then the output is generated and sent to the client at once.
@@ -140,14 +143,14 @@ export declare function stepAMayDependOnStepB($a: ExecutableStep, $b: Executable
140
143
  * approach. Once you have, you can use this function to help you, should you
141
144
  * need it.
142
145
  */
143
- export declare function stepsAreInSamePhase(ancestor: ExecutableStep, descendent: ExecutableStep): boolean;
146
+ export declare function stepsAreInSamePhase(ancestor: Step, descendent: Step): boolean;
144
147
  export declare const canonicalJSONStringify: (o: object) => string;
145
148
  export declare function assertNotAsync(fn: any, name: string): void;
146
149
  export declare function assertNotPromise<TVal>(value: TVal, fn: any, name: string): TVal;
147
- export declare function hasItemPlan(step: ExecutableStep & {
148
- itemPlan?: ($item: ExecutableStep) => ExecutableStep;
149
- }): step is ExecutableStep & {
150
- itemPlan: ($item: ExecutableStep) => ExecutableStep;
150
+ export declare function hasItemPlan(step: Step & {
151
+ itemPlan?: ($item: Step) => Step;
152
+ }): step is Step & {
153
+ itemPlan: ($item: Step) => Step;
151
154
  };
152
155
  export declare function exportNameHint(obj: any, nameHint: string): void;
153
156
  export declare function isTuple<T extends readonly [...(readonly any[])]>(t: any | T): t is T;
@@ -157,5 +160,14 @@ export declare function isTuple<T extends readonly [...(readonly any[])]>(t: any
157
160
  * than JSON.stringify().)
158
161
  */
159
162
  export declare function digestKeys(keys: ReadonlyArray<string | number | symbol>): string;
163
+ /**
164
+ * If the directive has the argument `argName`, return a step representing that
165
+ * arguments value, whether that be a step representing the relevant variable
166
+ * or a constant step representing the hardcoded value in the document.
167
+ *
168
+ * @remarks NOT SUITABLE FOR USAGE WITH LISTS OR OBJECTS! Does not evaluate
169
+ * internal variable usages e.g. `[1, $b, 3]`
170
+ */
171
+ export declare function directiveArgument<T>(operationPlan: OperationPlan, directive: DirectiveNode, argName: string, expectedKind: graphql.Kind.INT | graphql.Kind.FLOAT | graphql.Kind.BOOLEAN | graphql.Kind.STRING): Step<T> | undefined;
160
172
  export {};
161
173
  //# sourceMappingURL=utils.d.ts.map
package/dist/utils.js CHANGED
@@ -1,12 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.digestKeys = exports.isTuple = exports.exportNameHint = exports.hasItemPlan = exports.assertNotPromise = exports.assertNotAsync = exports.canonicalJSONStringify = exports.stepsAreInSamePhase = exports.stepAMayDependOnStepB = exports.stepADependsOnStepB = exports.writeableArray = exports.sudo = exports.isTypePlanned = exports.findVariableNamesUsed = exports.arrayOfLengthCb = exports.arrayOfLength = exports.stack = exports.sharedNull = exports.getEnumValueConfig = exports.inputObjectFieldSpec = exports.newInputObjectTypeBuilder = exports.newGrafastFieldConfigBuilder = exports.objectFieldSpec = exports.newObjectTypeBuilder = exports.objectSpec = exports.arraysMatch = exports.isDeferred = exports.isPromiseLike = exports.isPromise = exports.defaultValueToValueNode = exports.assertNullPrototype = exports.ROOT_VALUE_OBJECT = void 0;
3
+ exports.canonicalJSONStringify = exports.valueNodeToStaticValue = exports.sharedNull = exports.ROOT_VALUE_OBJECT = void 0;
4
+ exports.assertNullPrototype = assertNullPrototype;
5
+ exports.defaultValueToValueNode = defaultValueToValueNode;
6
+ exports.isPromise = isPromise;
7
+ exports.isPromiseLike = isPromiseLike;
8
+ exports.isDeferred = isDeferred;
9
+ exports.arraysMatch = arraysMatch;
10
+ exports.objectSpec = objectSpec;
11
+ exports.newObjectTypeBuilder = newObjectTypeBuilder;
12
+ exports.objectFieldSpec = objectFieldSpec;
13
+ exports.newGrafastFieldConfigBuilder = newGrafastFieldConfigBuilder;
14
+ exports.newInputObjectTypeBuilder = newInputObjectTypeBuilder;
15
+ exports.inputObjectFieldSpec = inputObjectFieldSpec;
16
+ exports.getEnumValueConfigs = getEnumValueConfigs;
17
+ exports.getEnumValueConfig = getEnumValueConfig;
18
+ exports.stack = stack;
19
+ exports.arrayOfLength = arrayOfLength;
20
+ exports.arrayOfLengthCb = arrayOfLengthCb;
21
+ exports.findVariableNamesUsedInValueNode = findVariableNamesUsedInValueNode;
22
+ exports.findVariableNamesUsed = findVariableNamesUsed;
23
+ exports.isTypePlanned = isTypePlanned;
24
+ exports.sudo = sudo;
25
+ exports.writeableArray = writeableArray;
26
+ exports.stepADependsOnStepB = stepADependsOnStepB;
27
+ exports.stepAMayDependOnStepB = stepAMayDependOnStepB;
28
+ exports.stepsAreInSamePhase = stepsAreInSamePhase;
29
+ exports.assertNotAsync = assertNotAsync;
30
+ exports.assertNotPromise = assertNotPromise;
31
+ exports.hasItemPlan = hasItemPlan;
32
+ exports.exportNameHint = exportNameHint;
33
+ exports.isTuple = isTuple;
34
+ exports.digestKeys = digestKeys;
35
+ exports.directiveArgument = directiveArgument;
4
36
  const tslib_1 = require("tslib");
5
37
  const graphql = tslib_1.__importStar(require("graphql"));
6
38
  const assert = tslib_1.__importStar(require("./assert.js"));
7
39
  const dev_js_1 = require("./dev.js");
8
40
  const error_js_1 = require("./error.js");
9
41
  const inspect_js_1 = require("./inspect.js");
42
+ const constant_js_1 = require("./steps/constant.js");
10
43
  const { GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLString, GraphQLUnionType, Kind, } = graphql;
11
44
  /**
12
45
  * The parent object is used as the key in `GetValueStepId()`; for root level
@@ -20,7 +53,6 @@ function assertNullPrototype(object, description) {
20
53
  assert.strictEqual(Object.getPrototypeOf(object), null, `Expected ${description} to have a null prototype`);
21
54
  }
22
55
  }
23
- exports.assertNullPrototype = assertNullPrototype;
24
56
  /**
25
57
  * Converts a JSON value into the equivalent ValueNode _without_ checking that
26
58
  * it's compatible with the expected type. Typically only used with scalars
@@ -181,21 +213,18 @@ function defaultValueToValueNode(type, defaultValue) {
181
213
  }
182
214
  return rawValueToValueNode(type, defaultValue);
183
215
  }
184
- exports.defaultValueToValueNode = defaultValueToValueNode;
185
216
  function isPromise(t) {
186
217
  return (typeof t === "object" &&
187
218
  t !== null &&
188
219
  typeof t.then === "function" &&
189
220
  typeof t.catch === "function");
190
221
  }
191
- exports.isPromise = isPromise;
192
222
  /**
193
223
  * Is "thenable".
194
224
  */
195
225
  function isPromiseLike(t) {
196
226
  return t != null && typeof t.then === "function";
197
227
  }
198
- exports.isPromiseLike = isPromiseLike;
199
228
  /**
200
229
  * Is a promise that can be externally resolved.
201
230
  */
@@ -204,7 +233,6 @@ function isDeferred(t) {
204
233
  typeof t.resolve === "function" &&
205
234
  typeof t.reject === "function");
206
235
  }
207
- exports.isDeferred = isDeferred;
208
236
  /**
209
237
  * Returns true if array1 and array2 have the same length, and every pair of
210
238
  * values within them pass the `comparator` check (which defaults to `===`).
@@ -232,7 +260,6 @@ function arraysMatch(array1, array2, comparator) {
232
260
  }
233
261
  return true;
234
262
  }
235
- exports.arraysMatch = arraysMatch;
236
263
  /**
237
264
  * Saves us having to write `extensions: {grafast: {...}}` everywhere.
238
265
  */
@@ -262,14 +289,12 @@ function objectSpec(spec) {
262
289
  };
263
290
  return modifiedSpec;
264
291
  }
265
- exports.objectSpec = objectSpec;
266
292
  /**
267
293
  * @remarks This is a mess because the first two generics need to be specified manually, but the latter one we want inferred.
268
294
  */
269
295
  function newObjectTypeBuilder(assertStep) {
270
296
  return (spec) => new GraphQLObjectType(objectSpec({ assertStep, ...spec }));
271
297
  }
272
- exports.newObjectTypeBuilder = newObjectTypeBuilder;
273
298
  /**
274
299
  * Saves us having to write `extensions: {grafast: {...}}` everywhere.
275
300
  */
@@ -279,23 +304,26 @@ function objectFieldSpec(grafastSpec, path) {
279
304
  assertNotAsync(subscribePlan, `${path ?? "?"}.subscribePlan`);
280
305
  const argsWithExtensions = args
281
306
  ? Object.keys(args).reduce((memo, argName) => {
282
- const { inputPlan, applyPlan, autoApplyAfterParentPlan, autoApplyAfterParentSubscribePlan, ...argSpec } = args[argName];
283
- assertNotAsync(inputPlan, `${path ?? "?"}(${argName}:).inputPlan`);
307
+ const grafastArgSpec = args[argName];
308
+ // TODO: remove this code
309
+ if (grafastArgSpec.inputPlan ||
310
+ grafastArgSpec.autoApplyAfterParentPlan ||
311
+ grafastArgSpec.autoApplyAfterParentSubscribePlan) {
312
+ throw new Error(`Argument at ${path} has inputPlan or autoApplyAfterParentPlan or autoApplyAfterParentSubscribePlan set; these properties no longer do anything and should be removed.`);
313
+ }
314
+ const { applyPlan, applySubscribePlan, ...argSpec } = grafastArgSpec;
284
315
  assertNotAsync(applyPlan, `${path ?? "?"}(${argName}:).applyPlan`);
316
+ assertNotAsync(applySubscribePlan, `${path ?? "?"}(${argName}:).applySubscribePlan`);
285
317
  memo[argName] = {
286
318
  ...argSpec,
287
- ...(inputPlan || applyPlan
319
+ ...(applyPlan || applySubscribePlan
288
320
  ? {
289
321
  extensions: {
322
+ ...argSpec.extensions,
290
323
  grafast: {
291
- ...(inputPlan ? { inputPlan } : null),
292
- ...(autoApplyAfterParentPlan
293
- ? { autoApplyAfterParentPlan }
294
- : null),
324
+ ...argSpec.extensions?.grafast,
295
325
  ...(applyPlan ? { applyPlan } : null),
296
- ...(autoApplyAfterParentSubscribePlan
297
- ? { autoApplyAfterParentSubscribePlan }
298
- : null),
326
+ ...(applySubscribePlan ? { applySubscribePlan } : null),
299
327
  },
300
328
  },
301
329
  }
@@ -321,7 +349,6 @@ function objectFieldSpec(grafastSpec, path) {
321
349
  : null),
322
350
  };
323
351
  }
324
- exports.objectFieldSpec = objectFieldSpec;
325
352
  /**
326
353
  * "Constrainted identity function" for field configs.
327
354
  *
@@ -330,7 +357,6 @@ exports.objectFieldSpec = objectFieldSpec;
330
357
  function newGrafastFieldConfigBuilder() {
331
358
  return (config) => config;
332
359
  }
333
- exports.newGrafastFieldConfigBuilder = newGrafastFieldConfigBuilder;
334
360
  function inputObjectSpec(spec) {
335
361
  const modifiedSpec = {
336
362
  ...spec,
@@ -348,52 +374,53 @@ function inputObjectSpec(spec) {
348
374
  function newInputObjectTypeBuilder() {
349
375
  return (spec) => new GraphQLInputObjectType(inputObjectSpec(spec));
350
376
  }
351
- exports.newInputObjectTypeBuilder = newInputObjectTypeBuilder;
352
377
  /**
353
378
  * Saves us having to write `extensions: {grafast: {...}}` everywhere.
354
379
  */
355
380
  function inputObjectFieldSpec(grafastSpec, path) {
356
- const { inputPlan, applyPlan, autoApplyAfterParentInputPlan, autoApplyAfterParentApplyPlan, ...spec } = grafastSpec;
357
- assertNotAsync(inputPlan, `${path ?? "?"}.inputPlan`);
358
- assertNotAsync(applyPlan, `${path ?? "?"}.applyPlan`);
359
- return inputPlan || applyPlan
381
+ // TODO: remove this code
382
+ if (grafastSpec.applyPlan ||
383
+ grafastSpec.inputPlan ||
384
+ grafastSpec.autoApplyAfterParentApplyPlan ||
385
+ grafastSpec.autoApplyAfterParentInputPlan) {
386
+ throw new Error(`Input field at ${path} has applyPlan or inputPlan or autoApplyAfterParentApplyPlan or autoApplyAfterParentInputPlan set; these properties no longer do anything and should be removed.`);
387
+ }
388
+ const { apply, ...spec } = grafastSpec;
389
+ assertNotAsync(apply, `${path ?? "?"}.apply`);
390
+ return apply
360
391
  ? {
361
392
  ...spec,
362
393
  extensions: {
394
+ ...spec.extensions,
363
395
  grafast: {
364
- ...(inputPlan ? { inputPlan } : null),
365
- ...(applyPlan ? { applyPlan } : null),
366
- ...(autoApplyAfterParentInputPlan
367
- ? { autoApplyAfterParentInputPlan }
368
- : null),
369
- ...(autoApplyAfterParentApplyPlan
370
- ? { autoApplyAfterParentApplyPlan }
371
- : null),
396
+ ...spec.extensions?.grafast,
397
+ apply,
372
398
  },
373
399
  },
374
400
  }
375
401
  : spec;
376
402
  }
377
- exports.inputObjectFieldSpec = inputObjectFieldSpec;
378
403
  const $$valueConfigByValue = Symbol("valueConfigByValue");
379
- /**
380
- * This would be equivalent to `enumType._valueLookup.get(outputValue)` except
381
- * that's not a public API so we have to do a bit of heavy lifting here. Since
382
- * it is heavy lifting, we cache the result, but we don't know when enumType
383
- * will go away so we use a weakmap.
384
- */
385
- function getEnumValueConfig(enumType, outputValue) {
404
+ function getEnumValueConfigs(enumType) {
386
405
  // We cache onto the enumType directly so that garbage collection can clear up after us easily.
387
- if (!enumType[$$valueConfigByValue]) {
406
+ if (enumType[$$valueConfigByValue] === undefined) {
388
407
  const config = enumType.toConfig();
389
408
  enumType[$$valueConfigByValue] = Object.values(config.values).reduce((memo, value) => {
390
409
  memo[value.value] = value;
391
410
  return memo;
392
411
  }, Object.create(null));
393
412
  }
394
- return enumType[$$valueConfigByValue][outputValue];
413
+ return enumType[$$valueConfigByValue];
414
+ }
415
+ /**
416
+ * This would be equivalent to `enumType._valueLookup.get(outputValue)` except
417
+ * that's not a public API so we have to do a bit of heavy lifting here. Since
418
+ * it is heavy lifting, we cache the result, but we don't know when enumType
419
+ * will go away so we use a weakmap.
420
+ */
421
+ function getEnumValueConfig(enumType, outputValue) {
422
+ return getEnumValueConfigs(enumType)[outputValue];
395
423
  }
396
- exports.getEnumValueConfig = getEnumValueConfig;
397
424
  /**
398
425
  * It's a peculiarity of V8 that `{}` is twice as fast as
399
426
  * `Object.create(null)`, but `Object.create(sharedNull)` is the same speed as
@@ -427,7 +454,6 @@ function stack(message, length = 4) {
427
454
  console.log(mapped.join("\n"));
428
455
  }
429
456
  }
430
- exports.stack = stack;
431
457
  /**
432
458
  * Ridiculously, this is faster than `new Array(length).fill(fill)`
433
459
  */
@@ -438,7 +464,6 @@ function arrayOfLength(length, fill) {
438
464
  }
439
465
  return arr;
440
466
  }
441
- exports.arrayOfLength = arrayOfLength;
442
467
  /**
443
468
  * Builds an array of length `length` calling `fill` for each entry in the
444
469
  * list and storing the result.
@@ -452,7 +477,7 @@ function arrayOfLengthCb(length, fill) {
452
477
  }
453
478
  return arr;
454
479
  }
455
- exports.arrayOfLengthCb = arrayOfLengthCb;
480
+ exports.valueNodeToStaticValue = graphql.valueFromAST;
456
481
  function findVariableNamesUsedInValueNode(valueNode, variableNames) {
457
482
  switch (valueNode.kind) {
458
483
  case Kind.INT:
@@ -555,7 +580,6 @@ function findVariableNamesUsed(operationPlan, field) {
555
580
  findVariableNamesUsedInFieldNode(operationPlan, field, variableNames);
556
581
  return [...variableNames].sort();
557
582
  }
558
- exports.findVariableNamesUsed = findVariableNamesUsed;
559
583
  function isTypePlanned(schema, namedType) {
560
584
  if (namedType instanceof GraphQLObjectType) {
561
585
  return !!namedType.extensions?.grafast?.assertStep;
@@ -584,7 +608,6 @@ function isTypePlanned(schema, namedType) {
584
608
  return false;
585
609
  }
586
610
  }
587
- exports.isTypePlanned = isTypePlanned;
588
611
  /**
589
612
  * Make protected/private methods accessible.
590
613
  *
@@ -593,7 +616,6 @@ exports.isTypePlanned = isTypePlanned;
593
616
  function sudo(obj) {
594
617
  return obj;
595
618
  }
596
- exports.sudo = sudo;
597
619
  /**
598
620
  * We want everything else to treat things like `dependencies` as read only,
599
621
  * however we ourselves want to be able to write to them, so we can use
@@ -604,7 +626,6 @@ exports.sudo = sudo;
604
626
  function writeableArray(a) {
605
627
  return a;
606
628
  }
607
- exports.writeableArray = writeableArray;
608
629
  /**
609
630
  * Returns `true` if the first argument depends on the second argument either
610
631
  * directly or indirectly (via a chain of dependencies).
@@ -627,7 +648,6 @@ function stepADependsOnStepB(stepA, stepB) {
627
648
  }
628
649
  return false;
629
650
  }
630
- exports.stepADependsOnStepB = stepADependsOnStepB;
631
651
  /**
632
652
  * Returns true if stepA is allowed to depend on stepB, false otherwise. (This
633
653
  * mostly relates to heirarchy.)
@@ -644,7 +664,6 @@ function stepAMayDependOnStepB($a, $b) {
644
664
  }
645
665
  return !stepADependsOnStepB($b, $a);
646
666
  }
647
- exports.stepAMayDependOnStepB = stepAMayDependOnStepB;
648
667
  /**
649
668
  * For a regular GraphQL query with no `@stream`/`@defer`, the entire result is
650
669
  * calculated and then the output is generated and sent to the client at once.
@@ -715,7 +734,6 @@ function stepsAreInSamePhase(ancestor, descendent) {
715
734
  } while ((currentLayerPlan = currentLayerPlan.parentLayerPlan));
716
735
  throw new Error(`${descendent} is not dependent on ${ancestor}, perhaps you passed the arguments in the wrong order?`);
717
736
  }
718
- exports.stepsAreInSamePhase = stepsAreInSamePhase;
719
737
  // ENHANCE: implement this!
720
738
  const canonicalJSONStringify = (o) => JSON.stringify(o);
721
739
  exports.canonicalJSONStringify = canonicalJSONStringify;
@@ -725,7 +743,6 @@ function assertNotAsync(fn, name) {
725
743
  throw new Error(`Plans must be synchronous, but this schema has an async function at '${name}': ${fn.toString()}`);
726
744
  }
727
745
  }
728
- exports.assertNotAsync = assertNotAsync;
729
746
  // PERF: only do this if isDev; otherwise replace with NOOP?
730
747
  function assertNotPromise(value, fn, name) {
731
748
  if (isPromiseLike(value)) {
@@ -733,11 +750,9 @@ function assertNotPromise(value, fn, name) {
733
750
  }
734
751
  return value;
735
752
  }
736
- exports.assertNotPromise = assertNotPromise;
737
753
  function hasItemPlan(step) {
738
754
  return "itemPlan" in step && typeof step.itemPlan === "function";
739
755
  }
740
- exports.hasItemPlan = hasItemPlan;
741
756
  function exportNameHint(obj, nameHint) {
742
757
  if ((typeof obj === "object" && obj != null) || typeof obj === "function") {
743
758
  if (!("$exporter$name" in obj)) {
@@ -751,11 +766,9 @@ function exportNameHint(obj, nameHint) {
751
766
  }
752
767
  }
753
768
  }
754
- exports.exportNameHint = exportNameHint;
755
769
  function isTuple(t) {
756
770
  return Array.isArray(t);
757
771
  }
758
- exports.isTuple = isTuple;
759
772
  /**
760
773
  * Turns an array of keys into a digest, avoiding conflicts.
761
774
  * Symbols are treated as equivalent. (Theoretically faster
@@ -778,5 +791,28 @@ function digestKeys(keys) {
778
791
  }
779
792
  return str;
780
793
  }
781
- exports.digestKeys = digestKeys;
794
+ /**
795
+ * If the directive has the argument `argName`, return a step representing that
796
+ * arguments value, whether that be a step representing the relevant variable
797
+ * or a constant step representing the hardcoded value in the document.
798
+ *
799
+ * @remarks NOT SUITABLE FOR USAGE WITH LISTS OR OBJECTS! Does not evaluate
800
+ * internal variable usages e.g. `[1, $b, 3]`
801
+ */
802
+ function directiveArgument(operationPlan, directive, argName, expectedKind) {
803
+ const arg = directive.arguments?.find((n) => n.name.value === argName);
804
+ if (!arg)
805
+ return undefined;
806
+ const val = arg.value;
807
+ return val.kind === graphql.Kind.VARIABLE
808
+ ? operationPlan.variableValuesStep.get(val.name.value)
809
+ : val.kind === expectedKind
810
+ ? (0, constant_js_1.constant)(val.kind === Kind.INT
811
+ ? parseInt(val.value, 10)
812
+ : val.kind === Kind.FLOAT
813
+ ? parseFloat(val.value)
814
+ : // boolean, string
815
+ val.value)
816
+ : undefined;
817
+ }
782
818
  //# sourceMappingURL=utils.js.map
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "0.1.1-beta.20";
1
+ export declare const version = "0.1.1-beta.21";
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.20";
5
+ exports.version = "0.1.1-beta.21";
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.20",
3
+ "version": "0.1.1-beta.21",
4
4
  "description": "Cutting edge GraphQL planning and execution engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -59,7 +59,7 @@
59
59
  "chalk": "^4.1.2",
60
60
  "debug": "^4.3.4",
61
61
  "eventemitter3": "^5.0.1",
62
- "graphile-config": "^0.0.1-beta.14",
62
+ "graphile-config": "^0.0.1-beta.15",
63
63
  "graphql": "^16.1.0-experimental-stream-defer.6",
64
64
  "iterall": "^1.3.0",
65
65
  "tamedevil": "^0.0.0-beta.7",