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.
- package/README.md +2 -3
- package/dist/args.d.ts +4 -7
- package/dist/args.js +53 -38
- package/dist/assert.js +2 -3
- package/dist/bucket.d.ts +1 -89
- package/dist/config.d.ts +0 -17
- package/dist/config.js +1 -95
- package/dist/constraints.d.ts +15 -1
- package/dist/constraints.js +41 -3
- package/dist/deferred.js +1 -2
- package/dist/dev.d.ts +1 -4
- package/dist/dev.js +18 -3
- package/dist/engine/LayerPlan.d.ts +21 -111
- package/dist/engine/LayerPlan.js +196 -78
- package/dist/engine/OperationPlan.d.ts +30 -104
- package/dist/engine/OperationPlan.js +763 -471
- package/dist/engine/OutputPlan.d.ts +9 -20
- package/dist/engine/OutputPlan.js +432 -444
- package/dist/engine/StepTracker.d.ts +1 -95
- package/dist/engine/StepTracker.js +94 -20
- package/dist/engine/executeBucket.d.ts +5 -7
- package/dist/engine/executeBucket.js +646 -244
- package/dist/engine/executeOutputPlan.d.ts +0 -53
- package/dist/engine/executeOutputPlan.js +7 -2
- package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
- package/dist/engine/lib/defaultPlanResolver.js +11 -0
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
- package/dist/engine/lock.d.ts +4 -0
- package/dist/engine/lock.js +82 -0
- package/dist/envelop.js +5 -4
- package/dist/error.d.ts +18 -49
- package/dist/error.js +50 -39
- package/dist/establishOperationPlan.js +57 -42
- package/dist/execute.d.ts +5 -4
- package/dist/execute.js +31 -15
- package/dist/exportAs.d.ts +1 -18
- package/dist/exportAs.js +2 -3
- package/dist/global.js +2 -3
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +35 -16
- package/dist/grafastPrint.d.ts +3 -0
- package/dist/grafastPrint.js +67 -6
- package/dist/graphqlCollectFields.d.ts +7 -34
- package/dist/graphqlCollectFields.js +24 -13
- package/dist/graphqlMergeSelectionSets.js +1 -2
- package/dist/index.d.ts +44 -29
- package/dist/index.js +91 -18
- package/dist/input.d.ts +1 -9
- package/dist/input.js +75 -28
- package/dist/inspect.d.ts +9 -3
- package/dist/inspect.js +3 -3
- package/dist/interfaces.d.ts +238 -93
- package/dist/interfaces.js +20 -3
- package/dist/makeGrafastSchema.d.ts +21 -9
- package/dist/makeGrafastSchema.js +353 -133
- package/dist/mermaid.d.ts +0 -17
- package/dist/mermaid.js +131 -19
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +24 -0
- package/dist/multistep.d.ts +19 -0
- package/dist/multistep.js +54 -0
- package/dist/operationPlan-input.d.ts +5 -4
- package/dist/operationPlan-input.js +140 -368
- package/dist/planJSONInterfaces.d.ts +12 -2
- package/dist/polymorphic.js +4 -5
- package/dist/prepare.d.ts +1 -7
- package/dist/prepare.js +100 -74
- package/dist/step.d.ts +118 -172
- package/dist/step.js +262 -183
- package/dist/steps/__flag.d.ts +65 -0
- package/dist/steps/__flag.js +261 -0
- package/dist/steps/__inputDefault.d.ts +14 -0
- package/dist/steps/__inputDefault.js +48 -0
- package/dist/steps/__inputDynamicScalar.d.ts +4 -6
- package/dist/steps/__inputDynamicScalar.js +4 -2
- package/dist/steps/__inputList.d.ts +5 -9
- package/dist/steps/__inputList.js +4 -1
- package/dist/steps/__inputObject.d.ts +7 -11
- package/dist/steps/__inputObject.js +49 -3
- package/dist/steps/__inputStaticLeaf.d.ts +2 -4
- package/dist/steps/__inputStaticLeaf.js +3 -1
- package/dist/steps/__item.d.ts +10 -12
- package/dist/steps/__item.js +8 -2
- package/dist/steps/__trackedValue.d.ts +7 -55
- package/dist/steps/__trackedValue.js +69 -8
- package/dist/steps/__value.d.ts +5 -4
- package/dist/steps/__value.js +5 -4
- package/dist/steps/access.d.ts +10 -10
- package/dist/steps/access.js +50 -17
- package/dist/steps/applyInput.d.ts +44 -0
- package/dist/steps/applyInput.js +206 -0
- package/dist/steps/applyTransforms.d.ts +2 -25
- package/dist/steps/applyTransforms.js +53 -31
- package/dist/steps/bakedInput.d.ts +23 -0
- package/dist/steps/bakedInput.js +90 -0
- package/dist/steps/condition.d.ts +31 -0
- package/dist/steps/condition.js +94 -0
- package/dist/steps/connection.d.ts +56 -42
- package/dist/steps/connection.js +97 -44
- package/dist/steps/constant.d.ts +7 -7
- package/dist/steps/constant.js +86 -7
- package/dist/steps/each.d.ts +3 -3
- package/dist/steps/each.js +2 -3
- package/dist/steps/error.d.ts +4 -4
- package/dist/steps/error.js +7 -6
- package/dist/steps/filter.d.ts +3 -2
- package/dist/steps/filter.js +1 -2
- package/dist/steps/first.d.ts +10 -9
- package/dist/steps/first.js +9 -13
- package/dist/steps/graphqlResolver.d.ts +3 -76
- package/dist/steps/graphqlResolver.js +89 -72
- package/dist/steps/groupBy.d.ts +3 -2
- package/dist/steps/groupBy.js +1 -2
- package/dist/steps/index.d.ts +12 -3
- package/dist/steps/index.js +48 -6
- package/dist/steps/lambda.d.ts +9 -9
- package/dist/steps/lambda.js +18 -9
- package/dist/steps/last.d.ts +9 -8
- package/dist/steps/last.js +7 -6
- package/dist/steps/list.d.ts +20 -9
- package/dist/steps/list.js +56 -13
- package/dist/steps/listTransform.d.ts +18 -22
- package/dist/steps/listTransform.js +58 -27
- package/dist/steps/listen.d.ts +6 -11
- package/dist/steps/listen.js +14 -16
- package/dist/steps/load.d.ts +42 -33
- package/dist/steps/load.js +60 -27
- package/dist/steps/node.d.ts +17 -10
- package/dist/steps/node.js +18 -6
- package/dist/steps/object.d.ts +33 -27
- package/dist/steps/object.js +53 -32
- package/dist/steps/partitionByIndex.d.ts +3 -2
- package/dist/steps/partitionByIndex.js +1 -2
- package/dist/steps/polymorphicBranch.d.ts +27 -0
- package/dist/steps/polymorphicBranch.js +62 -0
- package/dist/steps/proxy.d.ts +11 -12
- package/dist/steps/proxy.js +8 -5
- package/dist/steps/remapKeys.d.ts +10 -10
- package/dist/steps/remapKeys.js +14 -7
- package/dist/steps/reverse.d.ts +8 -8
- package/dist/steps/reverse.js +10 -7
- package/dist/steps/setter.d.ts +9 -18
- package/dist/steps/setter.js +24 -14
- package/dist/steps/sideEffect.d.ts +28 -0
- package/dist/steps/sideEffect.js +44 -0
- package/dist/stringifyPayload.js +1 -2
- package/dist/stripAnsi.js +2 -2
- package/dist/subscribe.d.ts +7 -1
- package/dist/subscribe.js +24 -9
- package/dist/thereCanBeOnlyOne.js +1 -1
- package/dist/timeSource.d.ts +0 -1
- package/dist/utils.d.ts +56 -55
- package/dist/utils.js +179 -59
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -8
package/dist/utils.js
CHANGED
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
|
283
|
-
|
|
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
|
-
...(
|
|
319
|
+
...(applyPlan || applySubscribePlan
|
|
288
320
|
? {
|
|
289
321
|
extensions: {
|
|
322
|
+
...argSpec.extensions,
|
|
290
323
|
grafast: {
|
|
291
|
-
...
|
|
292
|
-
...(autoApplyAfterParentPlan
|
|
293
|
-
? { autoApplyAfterParentPlan }
|
|
294
|
-
: null),
|
|
324
|
+
...argSpec.extensions?.grafast,
|
|
295
325
|
...(applyPlan ? { applyPlan } : null),
|
|
296
|
-
...(
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
...
|
|
365
|
-
|
|
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 (
|
|
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]
|
|
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,11 +454,8 @@ 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
|
-
*
|
|
434
|
-
* @internal
|
|
435
459
|
*/
|
|
436
460
|
function arrayOfLength(length, fill) {
|
|
437
461
|
const arr = [];
|
|
@@ -440,7 +464,6 @@ function arrayOfLength(length, fill) {
|
|
|
440
464
|
}
|
|
441
465
|
return arr;
|
|
442
466
|
}
|
|
443
|
-
exports.arrayOfLength = arrayOfLength;
|
|
444
467
|
/**
|
|
445
468
|
* Builds an array of length `length` calling `fill` for each entry in the
|
|
446
469
|
* list and storing the result.
|
|
@@ -454,7 +477,7 @@ function arrayOfLengthCb(length, fill) {
|
|
|
454
477
|
}
|
|
455
478
|
return arr;
|
|
456
479
|
}
|
|
457
|
-
exports.
|
|
480
|
+
exports.valueNodeToStaticValue = graphql.valueFromAST;
|
|
458
481
|
function findVariableNamesUsedInValueNode(valueNode, variableNames) {
|
|
459
482
|
switch (valueNode.kind) {
|
|
460
483
|
case Kind.INT:
|
|
@@ -557,7 +580,6 @@ function findVariableNamesUsed(operationPlan, field) {
|
|
|
557
580
|
findVariableNamesUsedInFieldNode(operationPlan, field, variableNames);
|
|
558
581
|
return [...variableNames].sort();
|
|
559
582
|
}
|
|
560
|
-
exports.findVariableNamesUsed = findVariableNamesUsed;
|
|
561
583
|
function isTypePlanned(schema, namedType) {
|
|
562
584
|
if (namedType instanceof GraphQLObjectType) {
|
|
563
585
|
return !!namedType.extensions?.grafast?.assertStep;
|
|
@@ -586,13 +608,37 @@ function isTypePlanned(schema, namedType) {
|
|
|
586
608
|
return false;
|
|
587
609
|
}
|
|
588
610
|
}
|
|
589
|
-
|
|
611
|
+
/**
|
|
612
|
+
* Make protected/private methods accessible.
|
|
613
|
+
*
|
|
614
|
+
* @internal
|
|
615
|
+
*/
|
|
616
|
+
function sudo(obj) {
|
|
617
|
+
return obj;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* We want everything else to treat things like `dependencies` as read only,
|
|
621
|
+
* however we ourselves want to be able to write to them, so we can use
|
|
622
|
+
* writeable for this.
|
|
623
|
+
*
|
|
624
|
+
* @internal
|
|
625
|
+
*/
|
|
626
|
+
function writeableArray(a) {
|
|
627
|
+
return a;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Returns `true` if the first argument depends on the second argument either
|
|
631
|
+
* directly or indirectly (via a chain of dependencies).
|
|
632
|
+
*/
|
|
590
633
|
function stepADependsOnStepB(stepA, stepB) {
|
|
591
634
|
if (stepA === stepB) {
|
|
592
635
|
throw new Error("Invalid call to stepADependsOnStepB");
|
|
593
636
|
}
|
|
637
|
+
// PERF: bredth-first might be better.
|
|
638
|
+
// PERF: we can stop looking once we pass a certain layerPlan boundary.
|
|
639
|
+
// PERF: maybe some form of caching here would be sensible?
|
|
594
640
|
// Depth-first search for match
|
|
595
|
-
for (const dep of stepA.dependencies) {
|
|
641
|
+
for (const dep of sudo(stepA).dependencies) {
|
|
596
642
|
if (dep === stepB) {
|
|
597
643
|
return true;
|
|
598
644
|
}
|
|
@@ -602,15 +648,22 @@ function stepADependsOnStepB(stepA, stepB) {
|
|
|
602
648
|
}
|
|
603
649
|
return false;
|
|
604
650
|
}
|
|
605
|
-
exports.stepADependsOnStepB = stepADependsOnStepB;
|
|
606
651
|
/**
|
|
607
652
|
* Returns true if stepA is allowed to depend on stepB, false otherwise. (This
|
|
608
653
|
* mostly relates to heirarchy.)
|
|
609
654
|
*/
|
|
610
655
|
function stepAMayDependOnStepB($a, $b) {
|
|
611
|
-
|
|
656
|
+
if ($a.isFinalized) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
if ($a._isUnaryLocked && $a._isUnary && !$b._isUnary) {
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
if (!$a.layerPlan.ancestry.includes($b.layerPlan)) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
return !stepADependsOnStepB($b, $a);
|
|
612
666
|
}
|
|
613
|
-
exports.stepAMayDependOnStepB = stepAMayDependOnStepB;
|
|
614
667
|
/**
|
|
615
668
|
* For a regular GraphQL query with no `@stream`/`@defer`, the entire result is
|
|
616
669
|
* calculated and then the output is generated and sent to the client at once.
|
|
@@ -681,18 +734,85 @@ function stepsAreInSamePhase(ancestor, descendent) {
|
|
|
681
734
|
} while ((currentLayerPlan = currentLayerPlan.parentLayerPlan));
|
|
682
735
|
throw new Error(`${descendent} is not dependent on ${ancestor}, perhaps you passed the arguments in the wrong order?`);
|
|
683
736
|
}
|
|
684
|
-
exports.stepsAreInSamePhase = stepsAreInSamePhase;
|
|
685
737
|
// ENHANCE: implement this!
|
|
686
738
|
const canonicalJSONStringify = (o) => JSON.stringify(o);
|
|
687
739
|
exports.canonicalJSONStringify = canonicalJSONStringify;
|
|
740
|
+
// PERF: only do this if isDev; otherwise replace with NOOP?
|
|
688
741
|
function assertNotAsync(fn, name) {
|
|
689
742
|
if (fn?.constructor?.name === "AsyncFunction") {
|
|
690
743
|
throw new Error(`Plans must be synchronous, but this schema has an async function at '${name}': ${fn.toString()}`);
|
|
691
744
|
}
|
|
692
745
|
}
|
|
693
|
-
|
|
746
|
+
// PERF: only do this if isDev; otherwise replace with NOOP?
|
|
747
|
+
function assertNotPromise(value, fn, name) {
|
|
748
|
+
if (isPromiseLike(value)) {
|
|
749
|
+
throw new Error(`Plans must be synchronous, but this schema has an function at '${name}' that returned a promise-like object: ${fn.toString()}`);
|
|
750
|
+
}
|
|
751
|
+
return value;
|
|
752
|
+
}
|
|
694
753
|
function hasItemPlan(step) {
|
|
695
754
|
return "itemPlan" in step && typeof step.itemPlan === "function";
|
|
696
755
|
}
|
|
697
|
-
|
|
756
|
+
function exportNameHint(obj, nameHint) {
|
|
757
|
+
if ((typeof obj === "object" && obj != null) || typeof obj === "function") {
|
|
758
|
+
if (!("$exporter$name" in obj)) {
|
|
759
|
+
Object.defineProperty(obj, "$exporter$name", {
|
|
760
|
+
writable: true,
|
|
761
|
+
value: nameHint,
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
else if (!obj.$exporter$name) {
|
|
765
|
+
obj.$exporter$name = nameHint;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
function isTuple(t) {
|
|
770
|
+
return Array.isArray(t);
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Turns an array of keys into a digest, avoiding conflicts.
|
|
774
|
+
* Symbols are treated as equivalent. (Theoretically faster
|
|
775
|
+
* than JSON.stringify().)
|
|
776
|
+
*/
|
|
777
|
+
function digestKeys(keys) {
|
|
778
|
+
let str = "";
|
|
779
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
780
|
+
const item = keys[i];
|
|
781
|
+
if (typeof item === "string") {
|
|
782
|
+
// str += `|§${item.replace(/§/g, "§§")}§`;
|
|
783
|
+
str += `§${item.length}:${item}`;
|
|
784
|
+
}
|
|
785
|
+
else if (typeof item === "number") {
|
|
786
|
+
str += `N${item}`;
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
str += "!";
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return str;
|
|
793
|
+
}
|
|
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
|
+
}
|
|
698
818
|
//# sourceMappingURL=utils.js.map
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.1.1-beta.
|
|
1
|
+
export declare const version = "0.1.1-beta.21";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grafast",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
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,23 +59,20 @@
|
|
|
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.15",
|
|
62
63
|
"graphql": "^16.1.0-experimental-stream-defer.6",
|
|
63
64
|
"iterall": "^1.3.0",
|
|
64
|
-
"tamedevil": "^0.0.0-beta.
|
|
65
|
+
"tamedevil": "^0.0.0-beta.7",
|
|
65
66
|
"tslib": "^2.6.2"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
|
-
"@envelop/core": "^
|
|
69
|
-
"graphile-config": "^0.0.1-beta.5",
|
|
69
|
+
"@envelop/core": "^5.0.0",
|
|
70
70
|
"graphql": "^16.1.0-experimental-stream-defer.6",
|
|
71
|
-
"tamedevil": "^0.0.0-beta.
|
|
71
|
+
"tamedevil": "^0.0.0-beta.7"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
|
74
74
|
"@envelop/core": {
|
|
75
75
|
"optional": true
|
|
76
|
-
},
|
|
77
|
-
"graphile-config": {
|
|
78
|
-
"optional": true
|
|
79
76
|
}
|
|
80
77
|
},
|
|
81
78
|
"files": [
|