grafast 0.1.1-beta.2 → 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 (157) hide show
  1. package/README.md +2 -3
  2. package/dist/args.d.ts +4 -7
  3. package/dist/args.js +53 -38
  4. package/dist/assert.js +2 -3
  5. package/dist/bucket.d.ts +1 -89
  6. package/dist/config.d.ts +0 -17
  7. package/dist/config.js +1 -95
  8. package/dist/constraints.d.ts +15 -1
  9. package/dist/constraints.js +41 -3
  10. package/dist/deferred.js +1 -2
  11. package/dist/dev.d.ts +1 -4
  12. package/dist/dev.js +18 -3
  13. package/dist/engine/LayerPlan.d.ts +21 -111
  14. package/dist/engine/LayerPlan.js +196 -78
  15. package/dist/engine/OperationPlan.d.ts +30 -104
  16. package/dist/engine/OperationPlan.js +763 -471
  17. package/dist/engine/OutputPlan.d.ts +9 -20
  18. package/dist/engine/OutputPlan.js +432 -444
  19. package/dist/engine/StepTracker.d.ts +1 -95
  20. package/dist/engine/StepTracker.js +94 -20
  21. package/dist/engine/executeBucket.d.ts +5 -7
  22. package/dist/engine/executeBucket.js +646 -244
  23. package/dist/engine/executeOutputPlan.d.ts +0 -53
  24. package/dist/engine/executeOutputPlan.js +7 -2
  25. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  26. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  27. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
  28. package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
  29. package/dist/engine/lock.d.ts +4 -0
  30. package/dist/engine/lock.js +82 -0
  31. package/dist/envelop.js +5 -4
  32. package/dist/error.d.ts +18 -49
  33. package/dist/error.js +50 -39
  34. package/dist/establishOperationPlan.js +57 -42
  35. package/dist/execute.d.ts +5 -4
  36. package/dist/execute.js +31 -15
  37. package/dist/exportAs.d.ts +1 -18
  38. package/dist/exportAs.js +2 -3
  39. package/dist/global.js +2 -3
  40. package/dist/grafastGraphql.d.ts +6 -1
  41. package/dist/grafastGraphql.js +35 -16
  42. package/dist/grafastPrint.d.ts +3 -0
  43. package/dist/grafastPrint.js +67 -6
  44. package/dist/graphqlCollectFields.d.ts +7 -34
  45. package/dist/graphqlCollectFields.js +24 -13
  46. package/dist/graphqlMergeSelectionSets.js +1 -2
  47. package/dist/index.d.ts +44 -29
  48. package/dist/index.js +91 -18
  49. package/dist/input.d.ts +1 -9
  50. package/dist/input.js +75 -28
  51. package/dist/inspect.d.ts +9 -3
  52. package/dist/inspect.js +3 -3
  53. package/dist/interfaces.d.ts +238 -93
  54. package/dist/interfaces.js +20 -3
  55. package/dist/makeGrafastSchema.d.ts +21 -9
  56. package/dist/makeGrafastSchema.js +353 -133
  57. package/dist/mermaid.d.ts +0 -17
  58. package/dist/mermaid.js +131 -19
  59. package/dist/middleware.d.ts +7 -0
  60. package/dist/middleware.js +24 -0
  61. package/dist/multistep.d.ts +19 -0
  62. package/dist/multistep.js +54 -0
  63. package/dist/operationPlan-input.d.ts +5 -4
  64. package/dist/operationPlan-input.js +140 -368
  65. package/dist/planJSONInterfaces.d.ts +12 -2
  66. package/dist/polymorphic.js +4 -5
  67. package/dist/prepare.d.ts +1 -7
  68. package/dist/prepare.js +100 -74
  69. package/dist/step.d.ts +118 -172
  70. package/dist/step.js +262 -183
  71. package/dist/steps/__flag.d.ts +65 -0
  72. package/dist/steps/__flag.js +261 -0
  73. package/dist/steps/__inputDefault.d.ts +14 -0
  74. package/dist/steps/__inputDefault.js +48 -0
  75. package/dist/steps/__inputDynamicScalar.d.ts +4 -6
  76. package/dist/steps/__inputDynamicScalar.js +4 -2
  77. package/dist/steps/__inputList.d.ts +5 -9
  78. package/dist/steps/__inputList.js +4 -1
  79. package/dist/steps/__inputObject.d.ts +7 -11
  80. package/dist/steps/__inputObject.js +49 -3
  81. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  82. package/dist/steps/__inputStaticLeaf.js +3 -1
  83. package/dist/steps/__item.d.ts +10 -12
  84. package/dist/steps/__item.js +8 -2
  85. package/dist/steps/__trackedValue.d.ts +7 -55
  86. package/dist/steps/__trackedValue.js +69 -8
  87. package/dist/steps/__value.d.ts +5 -4
  88. package/dist/steps/__value.js +5 -4
  89. package/dist/steps/access.d.ts +10 -10
  90. package/dist/steps/access.js +50 -17
  91. package/dist/steps/applyInput.d.ts +44 -0
  92. package/dist/steps/applyInput.js +206 -0
  93. package/dist/steps/applyTransforms.d.ts +2 -25
  94. package/dist/steps/applyTransforms.js +53 -31
  95. package/dist/steps/bakedInput.d.ts +23 -0
  96. package/dist/steps/bakedInput.js +90 -0
  97. package/dist/steps/condition.d.ts +31 -0
  98. package/dist/steps/condition.js +94 -0
  99. package/dist/steps/connection.d.ts +56 -42
  100. package/dist/steps/connection.js +97 -44
  101. package/dist/steps/constant.d.ts +7 -7
  102. package/dist/steps/constant.js +86 -7
  103. package/dist/steps/each.d.ts +3 -3
  104. package/dist/steps/each.js +2 -3
  105. package/dist/steps/error.d.ts +4 -4
  106. package/dist/steps/error.js +7 -6
  107. package/dist/steps/filter.d.ts +3 -2
  108. package/dist/steps/filter.js +1 -2
  109. package/dist/steps/first.d.ts +10 -9
  110. package/dist/steps/first.js +9 -13
  111. package/dist/steps/graphqlResolver.d.ts +3 -76
  112. package/dist/steps/graphqlResolver.js +89 -72
  113. package/dist/steps/groupBy.d.ts +3 -2
  114. package/dist/steps/groupBy.js +1 -2
  115. package/dist/steps/index.d.ts +12 -3
  116. package/dist/steps/index.js +48 -6
  117. package/dist/steps/lambda.d.ts +9 -9
  118. package/dist/steps/lambda.js +18 -9
  119. package/dist/steps/last.d.ts +9 -8
  120. package/dist/steps/last.js +7 -6
  121. package/dist/steps/list.d.ts +20 -9
  122. package/dist/steps/list.js +56 -13
  123. package/dist/steps/listTransform.d.ts +18 -22
  124. package/dist/steps/listTransform.js +58 -27
  125. package/dist/steps/listen.d.ts +6 -11
  126. package/dist/steps/listen.js +14 -16
  127. package/dist/steps/load.d.ts +42 -33
  128. package/dist/steps/load.js +60 -27
  129. package/dist/steps/node.d.ts +17 -10
  130. package/dist/steps/node.js +18 -6
  131. package/dist/steps/object.d.ts +33 -27
  132. package/dist/steps/object.js +53 -32
  133. package/dist/steps/partitionByIndex.d.ts +3 -2
  134. package/dist/steps/partitionByIndex.js +1 -2
  135. package/dist/steps/polymorphicBranch.d.ts +27 -0
  136. package/dist/steps/polymorphicBranch.js +62 -0
  137. package/dist/steps/proxy.d.ts +11 -12
  138. package/dist/steps/proxy.js +8 -5
  139. package/dist/steps/remapKeys.d.ts +10 -10
  140. package/dist/steps/remapKeys.js +14 -7
  141. package/dist/steps/reverse.d.ts +8 -8
  142. package/dist/steps/reverse.js +10 -7
  143. package/dist/steps/setter.d.ts +9 -18
  144. package/dist/steps/setter.js +24 -14
  145. package/dist/steps/sideEffect.d.ts +28 -0
  146. package/dist/steps/sideEffect.js +44 -0
  147. package/dist/stringifyPayload.js +1 -2
  148. package/dist/stripAnsi.js +2 -2
  149. package/dist/subscribe.d.ts +7 -1
  150. package/dist/subscribe.js +24 -9
  151. package/dist/thereCanBeOnlyOne.js +1 -1
  152. package/dist/timeSource.d.ts +0 -1
  153. package/dist/utils.d.ts +56 -55
  154. package/dist/utils.js +179 -59
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +5 -8
package/dist/input.js CHANGED
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inputStep = exports.graphqlGetTypeForNode = exports.assertInputStep = void 0;
3
+ exports.assertInputStep = assertInputStep;
4
+ exports.graphqlGetTypeForNode = graphqlGetTypeForNode;
5
+ exports.inputStep = inputStep;
4
6
  const tslib_1 = require("tslib");
5
7
  const graphql = tslib_1.__importStar(require("graphql"));
6
8
  const inspect_js_1 = require("./inspect.js");
9
+ const __inputDefault_js_1 = require("./steps/__inputDefault.js");
7
10
  const __inputDynamicScalar_js_1 = require("./steps/__inputDynamicScalar.js");
8
11
  const __inputObject_js_1 = require("./steps/__inputObject.js");
9
12
  const index_js_1 = require("./steps/index.js");
13
+ const utils_js_1 = require("./utils.js");
10
14
  const { assertScalarType, GraphQLError, GraphQLList, GraphQLNonNull, isInputType, isLeafType, isInputObjectType, Kind, } = graphql;
11
15
  function assertInputStep(itemPlan) {
12
16
  if (itemPlan instanceof index_js_1.__TrackedValueStep)
@@ -19,7 +23,6 @@ function assertInputStep(itemPlan) {
19
23
  return;
20
24
  throw new Error(`Expected an InputStep, but found ${itemPlan}`);
21
25
  }
22
- exports.assertInputStep = assertInputStep;
23
26
  function graphqlGetTypeForNode(operationPlan, node) {
24
27
  switch (node.kind) {
25
28
  case Kind.NAMED_TYPE: {
@@ -41,7 +44,6 @@ function graphqlGetTypeForNode(operationPlan, node) {
41
44
  }
42
45
  }
43
46
  }
44
- exports.graphqlGetTypeForNode = graphqlGetTypeForNode;
45
47
  /**
46
48
  * Returns a plan for the given `rawInputValue` AST node which could be a
47
49
  * variable or a literal, and could be nested so that a variable (or more than
@@ -49,14 +51,21 @@ exports.graphqlGetTypeForNode = graphqlGetTypeForNode;
49
51
  *
50
52
  * @internal
51
53
  */
52
- function inputStep(operationPlan, inputType, rawInputValue, defaultValue = undefined) {
53
- // This prevents recursion
54
- if (rawInputValue === undefined && defaultValue === undefined) {
55
- return (0, index_js_1.constant)(undefined);
54
+ function inputStep(operationPlan, inputType, inputValue, defaultValue = undefined) {
55
+ const { valueNodeToStaticValueCache } = operationPlan;
56
+ if (inputValue === undefined) {
57
+ // Definitely can't be or contain a variable!
58
+ if (defaultValue === undefined) {
59
+ return (0, index_js_1.constant)(undefined);
60
+ }
61
+ else {
62
+ return valueNodeToCachedStaticValueConstantStep(valueNodeToStaticValueCache, defaultValue, inputType);
63
+ }
56
64
  }
57
65
  const isObj = isInputObjectType(inputType);
58
- let inputValue = rawInputValue;
59
- if (inputValue?.kind === "Variable") {
66
+ if (inputValue.kind === "Variable") {
67
+ // Note: this is the only other place where `defaultValue` might be used
68
+ // we know `inputValue` is not a variable.
60
69
  const variableName = inputValue.name.value;
61
70
  const variableDefinition = operationPlan.operation.variableDefinitions?.find((def) => def.variable.name.value === variableName);
62
71
  if (!variableDefinition) {
@@ -68,17 +77,27 @@ function inputStep(operationPlan, inputType, rawInputValue, defaultValue = undef
68
77
  if (!isInputType(variableType)) {
69
78
  throw new Error(`Expected varible type to be an input type`);
70
79
  }
71
- return inputVariablePlan(operationPlan, variableName, variableType, inputType, defaultValue);
80
+ const variableWillDefinitelyBeSet = variableType instanceof GraphQLNonNull ||
81
+ variableDefinition.defaultValue != null;
82
+ return inputVariablePlan(operationPlan, variableName, variableType, inputType, defaultValue, variableWillDefinitelyBeSet);
72
83
  }
73
- // Note: past here we know whether `defaultValue` will be used or not because
74
- // we know `inputValue` is not a variable.
75
- inputValue = inputValue ?? defaultValue;
76
- if (inputType instanceof GraphQLNonNull) {
84
+ else if (inputType instanceof GraphQLNonNull) {
77
85
  const innerType = inputType.ofType;
86
+ if (inputValue.kind === Kind.NULL) {
87
+ throw new Error(`Null found in non-null position; this should have been prevented by validation.`);
88
+ }
78
89
  const valuePlan = inputStep(operationPlan, innerType, inputValue, undefined);
79
90
  return inputNonNullPlan(operationPlan, valuePlan);
80
91
  }
92
+ else if (inputValue.kind === Kind.NULL) {
93
+ return (0, index_js_1.constant)(null);
94
+ }
81
95
  else if (inputType instanceof GraphQLList) {
96
+ const variableNames = new Set();
97
+ (0, utils_js_1.findVariableNamesUsedInValueNode)(inputValue, variableNames);
98
+ if (variableNames.size === 0) {
99
+ return valueNodeToCachedStaticValueConstantStep(valueNodeToStaticValueCache, inputValue, inputType);
100
+ }
82
101
  return new index_js_1.__InputListStep(inputType, inputValue);
83
102
  }
84
103
  else if (isLeafType(inputType)) {
@@ -100,7 +119,6 @@ function inputStep(operationPlan, inputType, rawInputValue, defaultValue = undef
100
119
  throw new Error(`Unsupported type in inputPlan: '${(0, inspect_js_1.inspect)(never)}'`);
101
120
  }
102
121
  }
103
- exports.inputStep = inputStep;
104
122
  function doTypesMatch(variableType, expectedType) {
105
123
  if (variableType instanceof GraphQLNonNull &&
106
124
  expectedType instanceof GraphQLNonNull) {
@@ -118,36 +136,57 @@ function doTypesMatch(variableType, expectedType) {
118
136
  return variableType === expectedType;
119
137
  }
120
138
  }
121
- function inputVariablePlan(operationPlan, variableName, variableType, inputType, defaultValue = undefined) {
139
+ /**
140
+ * Returns a step representing a variable's value.
141
+ *
142
+ * @param operationPlan -
143
+ * @param variableName -
144
+ * @param variableType -
145
+ * @param inputType -
146
+ * @param defaultValue -
147
+ * @param variableWillDefinitelyBeSet - If `true` the variable is either
148
+ * non-null _or_ it has a default value (including null). In this case, the
149
+ * variable will never be `undefined` and thus an input position's defaultValue
150
+ * will never be invoked where it is used.
151
+ */
152
+ function inputVariablePlan(operationPlan, variableName, variableType, inputType, defaultValue, variableWillDefinitelyBeSet) {
122
153
  if (variableType instanceof GraphQLNonNull &&
123
154
  !(inputType instanceof GraphQLNonNull)) {
124
155
  const unwrappedVariableType = variableType.ofType;
125
- return inputVariablePlan(operationPlan, variableName, unwrappedVariableType, inputType, defaultValue);
156
+ return inputVariablePlan(operationPlan, variableName, unwrappedVariableType, inputType, defaultValue, variableWillDefinitelyBeSet);
126
157
  }
127
158
  const typesMatch = doTypesMatch(variableType, inputType);
128
159
  if (!typesMatch) {
129
160
  // REF: https://spec.graphql.org/draft/#IsVariableUsageAllowed()
130
161
  if (inputType instanceof GraphQLNonNull &&
131
162
  !(variableType instanceof GraphQLNonNull)) {
132
- const variablePlan = inputVariablePlan(operationPlan, variableName, variableType, inputType.ofType, defaultValue);
133
- if (variablePlan.evalIs(null) || variablePlan.evalIs(undefined)) {
163
+ const variablePlan = inputVariablePlan(operationPlan, variableName, variableType, inputType.ofType, defaultValue, variableWillDefinitelyBeSet);
164
+ // TODO: find a way to do this without doing eval. For example: track list of variables that may not be nullish.
165
+ if (variablePlan.evalIs(null) ||
166
+ (!variableWillDefinitelyBeSet && variablePlan.evalIs(undefined))) {
134
167
  throw new GraphQLError(`Expected non-null value of type ${inputType.ofType.toString()}`);
135
168
  }
136
169
  return variablePlan;
137
170
  }
138
171
  throw new Error("Expected variable and input types to match");
139
172
  }
140
- const variableValuePlan = operationPlan.trackedVariableValuesStep.get(variableName);
141
- if (defaultValue === undefined || !variableValuePlan.evalIs(undefined)) {
142
- // There's no default value, or we know for sure that our variable will be
143
- // set (even if null) and thus the default will not be used; use the variable.
144
- return variableValuePlan;
173
+ const $variableValue = operationPlan.trackedVariableValuesStep.get(variableName);
174
+ if (defaultValue === undefined) {
175
+ // There's no default value and thus the default will not be used; use the variable.
176
+ return $variableValue;
177
+ }
178
+ else if (variableWillDefinitelyBeSet) {
179
+ // The variable will DEFINITELY be set (even if it is set to null, possibly
180
+ // by a default), so the input position's default value will never apply.
181
+ return $variableValue;
145
182
  }
146
183
  else {
147
- // `defaultValue` is NOT undefined, and we know variableValue is
148
- // `undefined` (and always will be); we're going to loop back and pretend
149
- // that no value was passed in the first place (instead of the variable):
150
- return inputStep(operationPlan, inputType, undefined, defaultValue);
184
+ // Here:
185
+ // - the variable is nullable, optional, and has no default value
186
+ // - the input position has a default value
187
+ // We thus need a step that results in `variableValue === undefined ? defaultValue : variableValue`
188
+ const runtimeDefaultValue = (0, utils_js_1.valueNodeToStaticValue)(defaultValue, inputType);
189
+ return new __inputDefault_js_1.__InputDefaultStep($variableValue, runtimeDefaultValue);
151
190
  }
152
191
  }
153
192
  /**
@@ -156,4 +195,12 @@ function inputVariablePlan(operationPlan, variableName, variableType, inputType,
156
195
  function inputNonNullPlan(_operationPlan, innerPlan) {
157
196
  return innerPlan;
158
197
  }
198
+ function valueNodeToCachedStaticValueConstantStep(cache, valueNode, inputType) {
199
+ let step = cache.get(valueNode);
200
+ if (!step) {
201
+ step = (0, index_js_1.constant)((0, utils_js_1.valueNodeToStaticValue)(valueNode, inputType), false);
202
+ cache.set(valueNode, step);
203
+ }
204
+ return step;
205
+ }
159
206
  //# sourceMappingURL=input.js.map
package/dist/inspect.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- export declare let inspect: (obj: any, options?: {
2
- colors: boolean;
3
- }) => string;
1
+ export declare let inspect: {
2
+ (obj: any, options?: {
3
+ colors?: boolean;
4
+ depth?: number;
5
+ compact?: boolean | number;
6
+ breakLength?: number;
7
+ }): string;
8
+ custom: symbol;
9
+ };
4
10
  //# sourceMappingURL=inspect.d.ts.map
package/dist/inspect.js CHANGED
@@ -8,13 +8,13 @@ try {
8
8
  }
9
9
  }
10
10
  catch {
11
- exports.inspect = (obj) => {
11
+ exports.inspect = Object.assign((obj) => {
12
12
  return Array.isArray(obj) ||
13
13
  !obj ||
14
14
  Object.getPrototypeOf(obj) === null ||
15
15
  Object.getPrototypeOf(obj) === Object.prototype
16
- ? JSON.stringify(obj)
16
+ ? String(JSON.stringify(obj))
17
17
  : String(obj);
18
- };
18
+ }, { custom: Symbol.for("nodejs.util.inspect.custom") });
19
19
  }
20
20
  //# sourceMappingURL=inspect.js.map