grafast 0.1.1-beta.21 → 0.1.1-beta.22
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 +0 -4
- package/dist/args.js +3 -3
- package/dist/constants.d.ts +79 -0
- package/dist/constants.js +79 -0
- package/dist/engine/LayerPlan.d.ts +71 -8
- package/dist/engine/LayerPlan.js +375 -265
- package/dist/engine/OperationPlan.d.ts +77 -14
- package/dist/engine/OperationPlan.js +1508 -382
- package/dist/engine/OperationPlanTypes.d.ts +66 -0
- package/dist/engine/OperationPlanTypes.js +3 -0
- package/dist/engine/OutputPlan.d.ts +6 -0
- package/dist/engine/OutputPlan.js +138 -82
- package/dist/engine/StepTracker.js +76 -17
- package/dist/engine/executeBucket.js +327 -166
- package/dist/engine/lib/defaultPlanResolver.d.ts +1 -4
- package/dist/engine/lib/defaultPlanResolver.js +1 -5
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +3 -1
- package/dist/engine/lib/withGlobalLayerPlan.js +19 -1
- package/dist/envelop.js +14 -3
- package/dist/error.d.ts +1 -1
- package/dist/error.js +9 -9
- package/dist/establishOperationPlan.d.ts +2 -1
- package/dist/establishOperationPlan.js +10 -10
- package/dist/execute.js +7 -5
- package/dist/global.d.ts +10 -0
- package/dist/global.js +25 -0
- package/dist/grafastGraphql.js +4 -3
- package/dist/grafastPrint.js +36 -4
- package/dist/index.d.ts +76 -8
- package/dist/index.js +37 -33
- package/dist/input.js +20 -1
- package/dist/inspect.js +1 -0
- package/dist/interfaces.d.ts +80 -122
- package/dist/interfaces.js +0 -77
- package/dist/makeGrafastSchema.d.ts +118 -35
- package/dist/makeGrafastSchema.js +197 -29
- package/dist/mermaid.js +198 -97
- package/dist/operationPlan-input.d.ts +1 -1
- package/dist/operationPlan-input.js +15 -5
- package/dist/planJSONInterfaces.d.ts +24 -5
- package/dist/prepare.d.ts +16 -9
- package/dist/prepare.js +54 -51
- package/dist/step.d.ts +45 -9
- package/dist/step.js +139 -22
- package/dist/steps/__flag.d.ts +3 -2
- package/dist/steps/__flag.js +31 -29
- package/dist/steps/__inputObject.d.ts +1 -1
- package/dist/steps/__inputStaticLeaf.d.ts +3 -2
- package/dist/steps/__inputStaticLeaf.js +13 -7
- package/dist/steps/__item.d.ts +1 -1
- package/dist/steps/__item.js +3 -3
- package/dist/steps/__trackedValue.d.ts +6 -3
- package/dist/steps/__trackedValue.js +25 -9
- package/dist/steps/__value.d.ts +2 -1
- package/dist/steps/__value.js +5 -0
- package/dist/steps/access.d.ts +17 -1
- package/dist/steps/access.js +14 -1
- package/dist/steps/applyInput.d.ts +1 -1
- package/dist/steps/applyInput.js +7 -6
- package/dist/steps/applyTransforms.js +9 -7
- package/dist/steps/bakedInput.js +2 -2
- package/dist/steps/coalesce.d.ts +15 -0
- package/dist/steps/coalesce.js +36 -0
- package/dist/steps/constant.js +16 -14
- package/dist/steps/each.d.ts +2 -2
- package/dist/steps/first.d.ts +2 -0
- package/dist/steps/first.js +5 -1
- package/dist/steps/graphqlResolver.d.ts +2 -2
- package/dist/steps/graphqlResolver.js +63 -161
- package/dist/steps/index.d.ts +3 -15
- package/dist/steps/index.js +6 -41
- package/dist/steps/lambda.js +1 -1
- package/dist/steps/last.d.ts +2 -0
- package/dist/steps/last.js +4 -0
- package/dist/steps/listTransform.d.ts +2 -2
- package/dist/steps/listTransform.js +11 -13
- package/dist/steps/load.d.ts +28 -22
- package/dist/steps/load.js +47 -1
- package/dist/steps/node.d.ts +10 -7
- package/dist/steps/node.js +5 -19
- package/dist/steps/object.js +6 -1
- package/dist/steps/proxy.d.ts +0 -6
- package/dist/steps/proxy.js +3 -3
- package/dist/steps/remapKeys.d.ts +1 -1
- package/dist/steps/remapKeys.js +0 -1
- package/dist/utils.d.ts +27 -5
- package/dist/utils.js +235 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -6
- package/dist/polymorphic.d.ts +0 -14
- package/dist/polymorphic.js +0 -72
- package/dist/steps/polymorphicBranch.d.ts +0 -27
- package/dist/steps/polymorphicBranch.js +0 -62
package/dist/utils.js
CHANGED
|
@@ -7,6 +7,9 @@ exports.isPromise = isPromise;
|
|
|
7
7
|
exports.isPromiseLike = isPromiseLike;
|
|
8
8
|
exports.isDeferred = isDeferred;
|
|
9
9
|
exports.arraysMatch = arraysMatch;
|
|
10
|
+
exports.mapsMatch = mapsMatch;
|
|
11
|
+
exports.recordsMatch = recordsMatch;
|
|
12
|
+
exports.setsMatch = setsMatch;
|
|
10
13
|
exports.objectSpec = objectSpec;
|
|
11
14
|
exports.newObjectTypeBuilder = newObjectTypeBuilder;
|
|
12
15
|
exports.objectFieldSpec = objectFieldSpec;
|
|
@@ -25,7 +28,11 @@ exports.sudo = sudo;
|
|
|
25
28
|
exports.writeableArray = writeableArray;
|
|
26
29
|
exports.stepADependsOnStepB = stepADependsOnStepB;
|
|
27
30
|
exports.stepAMayDependOnStepB = stepAMayDependOnStepB;
|
|
31
|
+
exports.stepAShouldTryAndInlineIntoStepB = stepAShouldTryAndInlineIntoStepB;
|
|
32
|
+
exports.pathsFromAncestorToTargetLayerPlan = pathsFromAncestorToTargetLayerPlan;
|
|
33
|
+
exports.layerPlanHeirarchyContains = layerPlanHeirarchyContains;
|
|
28
34
|
exports.stepsAreInSamePhase = stepsAreInSamePhase;
|
|
35
|
+
exports.isPhaseTransitionLayerPlan = isPhaseTransitionLayerPlan;
|
|
29
36
|
exports.assertNotAsync = assertNotAsync;
|
|
30
37
|
exports.assertNotPromise = assertNotPromise;
|
|
31
38
|
exports.hasItemPlan = hasItemPlan;
|
|
@@ -246,7 +253,9 @@ function arraysMatch(array1, array2, comparator) {
|
|
|
246
253
|
}
|
|
247
254
|
if (comparator !== undefined) {
|
|
248
255
|
for (let i = 0; i < l; i++) {
|
|
249
|
-
|
|
256
|
+
const a = array1[i];
|
|
257
|
+
const b = array2[i];
|
|
258
|
+
if (a !== b && !comparator(a, b)) {
|
|
250
259
|
return false;
|
|
251
260
|
}
|
|
252
261
|
}
|
|
@@ -260,19 +269,99 @@ function arraysMatch(array1, array2, comparator) {
|
|
|
260
269
|
}
|
|
261
270
|
return true;
|
|
262
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns true if map1 and map2 have the same keys, and every matching entry
|
|
274
|
+
* value within them pass the `comparator` check (which defaults to `===`).
|
|
275
|
+
*/
|
|
276
|
+
function mapsMatch(map1, map2, comparator) {
|
|
277
|
+
if (map1 === map2)
|
|
278
|
+
return true;
|
|
279
|
+
const l = map1.size;
|
|
280
|
+
if (l !== map2.size) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
const allKeys = new Set([...map1.keys(), ...map2.keys()]);
|
|
284
|
+
if (allKeys.size !== l) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
if (comparator !== undefined) {
|
|
288
|
+
for (const k of allKeys) {
|
|
289
|
+
const a = map1.get(k);
|
|
290
|
+
const b = map2.get(k);
|
|
291
|
+
if (a !== b && !comparator(k, a, b)) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
for (const k of allKeys) {
|
|
298
|
+
if (map1.get(k) !== map2.get(k)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Returns true if record1 and record2 are equivalent, i.e. every value within
|
|
307
|
+
* them pass the `comparator` check (which defaults to `===`).
|
|
308
|
+
*
|
|
309
|
+
* Currently keys are ignored (`record[key] = undefined` is treated the same as
|
|
310
|
+
* `record[key]` being unset), but this may not always be the case.
|
|
311
|
+
*/
|
|
312
|
+
function recordsMatch(record1, record2, comparator) {
|
|
313
|
+
if (record1 === record2)
|
|
314
|
+
return true;
|
|
315
|
+
const k1 = Object.keys(record1);
|
|
316
|
+
const k2 = Object.keys(record2);
|
|
317
|
+
const allKeys = new Set([...k1, ...k2]);
|
|
318
|
+
if (comparator !== undefined) {
|
|
319
|
+
for (const k of allKeys) {
|
|
320
|
+
const a = record1[k];
|
|
321
|
+
const b = record2[k];
|
|
322
|
+
if (a !== b && !comparator(k, a, b)) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
for (const k of allKeys) {
|
|
329
|
+
if (record1[k] !== record2[k]) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
function setsMatch(s1, s2) {
|
|
337
|
+
if (s1 === s2)
|
|
338
|
+
return true;
|
|
339
|
+
if (s1 == null)
|
|
340
|
+
return false;
|
|
341
|
+
if (s2 == null)
|
|
342
|
+
return false;
|
|
343
|
+
if (s1.size !== s2.size)
|
|
344
|
+
return false;
|
|
345
|
+
for (const p of s1) {
|
|
346
|
+
if (!s2.has(p))
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
263
351
|
/**
|
|
264
352
|
* Saves us having to write `extensions: {grafast: {...}}` everywhere.
|
|
265
353
|
*/
|
|
266
354
|
function objectSpec(spec) {
|
|
267
|
-
const { assertStep, ...rest } = spec;
|
|
355
|
+
const { assertStep, planType, ...rest } = spec;
|
|
268
356
|
const modifiedSpec = {
|
|
269
357
|
...rest,
|
|
270
|
-
...(assertStep
|
|
358
|
+
...(assertStep || planType
|
|
271
359
|
? {
|
|
272
360
|
extensions: {
|
|
273
361
|
...spec.extensions,
|
|
274
362
|
grafast: {
|
|
275
|
-
assertStep,
|
|
363
|
+
...(assertStep ? { assertStep } : null),
|
|
364
|
+
...(planType ? { planType } : null),
|
|
276
365
|
...spec.extensions?.grafast,
|
|
277
366
|
},
|
|
278
367
|
},
|
|
@@ -648,6 +737,9 @@ function stepADependsOnStepB(stepA, stepB) {
|
|
|
648
737
|
}
|
|
649
738
|
return false;
|
|
650
739
|
}
|
|
740
|
+
function stepAIsOrDependsOnStepB(stepA, stepB) {
|
|
741
|
+
return stepA === stepB || stepADependsOnStepB(stepA, stepB);
|
|
742
|
+
}
|
|
651
743
|
/**
|
|
652
744
|
* Returns true if stepA is allowed to depend on stepB, false otherwise. (This
|
|
653
745
|
* mostly relates to heirarchy.)
|
|
@@ -664,6 +756,80 @@ function stepAMayDependOnStepB($a, $b) {
|
|
|
664
756
|
}
|
|
665
757
|
return !stepADependsOnStepB($b, $a);
|
|
666
758
|
}
|
|
759
|
+
function stepAShouldTryAndInlineIntoStepB($a, $b) {
|
|
760
|
+
if (dev_js_1.isDev && !stepADependsOnStepB($a, $b)) {
|
|
761
|
+
throw new Error(`Shouldn't try and inline into something you're not dependent on!`);
|
|
762
|
+
}
|
|
763
|
+
if (!stepsAreInSamePhase($b, $a))
|
|
764
|
+
return false;
|
|
765
|
+
// TODO: review the rules about polymorphism here; e.g. "only if most of the
|
|
766
|
+
// polymorphic paths are covered" or something. We don't want the parent to
|
|
767
|
+
// do lots of work for lots of polymorphic paths that won't be covered, but
|
|
768
|
+
// equally we don't want to necessarily require 100% of the polymorphic
|
|
769
|
+
// branches to be matched.
|
|
770
|
+
const paths = pathsFromAncestorToTargetLayerPlan($b.layerPlan, $a.layerPlan);
|
|
771
|
+
let path;
|
|
772
|
+
if (paths.length === 0) {
|
|
773
|
+
throw new Error(`No path from ${$a} back to ${$b}?`);
|
|
774
|
+
}
|
|
775
|
+
else if (paths.length > 1) {
|
|
776
|
+
const commonPath = [];
|
|
777
|
+
const firstPath = paths[0];
|
|
778
|
+
for (const lp of firstPath) {
|
|
779
|
+
if (paths.every((p) => p.includes(lp))) {
|
|
780
|
+
commonPath.push(lp);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
path = commonPath;
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
path = paths[0];
|
|
787
|
+
}
|
|
788
|
+
for (const lp of path) {
|
|
789
|
+
if (lp.reason.type === "polymorphicPartition") {
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
function pathsFromAncestorToTargetLayerPlan(ancestor, lp) {
|
|
796
|
+
if (lp === ancestor) {
|
|
797
|
+
// One path, and it's the null path - stay where you are.
|
|
798
|
+
return [[]];
|
|
799
|
+
}
|
|
800
|
+
if (lp.reason.type === "root") {
|
|
801
|
+
// No paths found - lp doesn't inherit from ancestor.
|
|
802
|
+
return [];
|
|
803
|
+
}
|
|
804
|
+
else if (lp.reason.type === "combined") {
|
|
805
|
+
const childPaths = lp.reason.parentLayerPlans.flatMap((plp) => pathsFromAncestorToTargetLayerPlan(ancestor, plp));
|
|
806
|
+
for (const path of childPaths) {
|
|
807
|
+
path.push(lp);
|
|
808
|
+
}
|
|
809
|
+
return childPaths;
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
const childPaths = pathsFromAncestorToTargetLayerPlan(ancestor, lp.reason.parentLayerPlan);
|
|
813
|
+
for (const path of childPaths) {
|
|
814
|
+
path.push(lp);
|
|
815
|
+
}
|
|
816
|
+
return childPaths;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
function layerPlanHeirarchyContains(lp, targetLp) {
|
|
820
|
+
if (lp === targetLp)
|
|
821
|
+
return true;
|
|
822
|
+
if (lp.reason.type === "root") {
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
else if (lp.reason.type === "combined") {
|
|
826
|
+
return lp.reason.parentLayerPlans.some((plp) => layerPlanHeirarchyContains(plp, targetLp));
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
// PERF: loop would be faster than recursion
|
|
830
|
+
return layerPlanHeirarchyContains(lp.reason.parentLayerPlan, targetLp);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
667
833
|
/**
|
|
668
834
|
* For a regular GraphQL query with no `@stream`/`@defer`, the entire result is
|
|
669
835
|
* calculated and then the output is generated and sent to the client at once.
|
|
@@ -692,24 +858,46 @@ function stepAMayDependOnStepB($a, $b) {
|
|
|
692
858
|
* need it.
|
|
693
859
|
*/
|
|
694
860
|
function stepsAreInSamePhase(ancestor, descendent) {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
861
|
+
if (dev_js_1.isDev && !stepADependsOnStepB(descendent, ancestor)) {
|
|
862
|
+
throw new Error(`Shouldn't try and inline into something you're not dependent on!`);
|
|
863
|
+
}
|
|
864
|
+
const ancestorDepth = ancestor.layerPlan.depth;
|
|
865
|
+
const descendentDepth = descendent.layerPlan.depth;
|
|
866
|
+
if (descendentDepth < ancestorDepth) {
|
|
867
|
+
throw new Error(`descendent is deeper than ancestor; did you pass ancestor/descendent the wrong way around?`);
|
|
868
|
+
}
|
|
869
|
+
const descDeferBoundary = descendent.layerPlan.ancestry[descendent.layerPlan.deferBoundaryDepth];
|
|
870
|
+
if (ancestor.layerPlan.ancestry[ancestor.layerPlan.deferBoundaryDepth] !==
|
|
871
|
+
descDeferBoundary) {
|
|
872
|
+
// Still possible to be okay if ancestor is the source of a streamed list item or deferred step
|
|
873
|
+
if (descDeferBoundary.reason.type === "listItem" &&
|
|
874
|
+
descDeferBoundary.reason.stream != null &&
|
|
875
|
+
descendent.layerPlan.ancestry[descendent.layerPlan.deferBoundaryDepth - 1] === ancestor.layerPlan) {
|
|
876
|
+
if (stepAIsOrDependsOnStepB(descDeferBoundary.reason.parentStep, ancestor)) {
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
// Nope, don't allow
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
for (let i = 0; i < ancestorDepth; i++) {
|
|
884
|
+
if (ancestor.layerPlan.ancestry[i] !== descendent.layerPlan.ancestry[i]) {
|
|
885
|
+
return false;
|
|
699
886
|
}
|
|
887
|
+
}
|
|
888
|
+
for (let i = ancestorDepth + 1; i < descendentDepth; i++) {
|
|
889
|
+
const currentLayerPlan = descendent.layerPlan.ancestry[i];
|
|
700
890
|
const t = currentLayerPlan.reason.type;
|
|
701
891
|
switch (t) {
|
|
892
|
+
case "combined": {
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
702
895
|
case "subscription":
|
|
703
896
|
case "defer": {
|
|
704
897
|
// These indicate boundaries over which plans shouldn't be optimized
|
|
705
898
|
// together (generally).
|
|
706
899
|
return false;
|
|
707
900
|
}
|
|
708
|
-
case "polymorphic": {
|
|
709
|
-
// OPTIMIZE: can optimize this so that if all polymorphicPaths match then it
|
|
710
|
-
// passes
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
901
|
case "listItem": {
|
|
714
902
|
if (currentLayerPlan.reason.stream) {
|
|
715
903
|
// It's streamed, but we can still inline the step into its parent since its the parent that is being streamed (so it should not add to the initial execution overhead).
|
|
@@ -723,6 +911,8 @@ function stepsAreInSamePhase(ancestor, descendent) {
|
|
|
723
911
|
case "root":
|
|
724
912
|
case "nullableBoundary":
|
|
725
913
|
case "subroutine":
|
|
914
|
+
case "polymorphic":
|
|
915
|
+
case "polymorphicPartition":
|
|
726
916
|
case "mutationField": {
|
|
727
917
|
continue;
|
|
728
918
|
}
|
|
@@ -731,8 +921,38 @@ function stepsAreInSamePhase(ancestor, descendent) {
|
|
|
731
921
|
throw new Error(`Unhandled layer plan type '${never}'`);
|
|
732
922
|
}
|
|
733
923
|
}
|
|
734
|
-
}
|
|
735
|
-
|
|
924
|
+
}
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
function isPhaseTransitionLayerPlan(layerPlan) {
|
|
928
|
+
const t = layerPlan.reason.type;
|
|
929
|
+
switch (t) {
|
|
930
|
+
case "subscription":
|
|
931
|
+
case "defer": {
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
case "listItem": {
|
|
935
|
+
if (layerPlan.reason.stream) {
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
else {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
case "polymorphic":
|
|
943
|
+
case "polymorphicPartition":
|
|
944
|
+
case "root":
|
|
945
|
+
case "nullableBoundary":
|
|
946
|
+
case "subroutine":
|
|
947
|
+
case "combined": // TODO: CHECK ME!
|
|
948
|
+
case "mutationField": {
|
|
949
|
+
return false;
|
|
950
|
+
}
|
|
951
|
+
default: {
|
|
952
|
+
const never = t;
|
|
953
|
+
throw new Error(`Unhandled layer plan type '${never}'`);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
736
956
|
}
|
|
737
957
|
// ENHANCE: implement this!
|
|
738
958
|
const canonicalJSONStringify = (o) => JSON.stringify(o);
|
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.22";
|
|
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.22",
|
|
4
4
|
"description": "Cutting edge GraphQL planning and execution engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -55,20 +55,20 @@
|
|
|
55
55
|
"node": ">=14.17"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@graphile/lru": "^5.0.0-beta.
|
|
58
|
+
"@graphile/lru": "^5.0.0-beta.4",
|
|
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.
|
|
62
|
+
"graphile-config": "^0.0.1-beta.16",
|
|
63
63
|
"graphql": "^16.1.0-experimental-stream-defer.6",
|
|
64
64
|
"iterall": "^1.3.0",
|
|
65
|
-
"tamedevil": "^0.0.0-beta.
|
|
66
|
-
"tslib": "^2.
|
|
65
|
+
"tamedevil": "^0.0.0-beta.8",
|
|
66
|
+
"tslib": "^2.8.1"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
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.8"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
|
74
74
|
"@envelop/core": {
|
package/dist/polymorphic.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { PolymorphicData } from "./interfaces.js";
|
|
2
|
-
export declare function isPolymorphicData(data: unknown): data is PolymorphicData;
|
|
3
|
-
export declare function assertPolymorphicData(data: unknown): asserts data is PolymorphicData;
|
|
4
|
-
/**
|
|
5
|
-
* Returns an object with the given concrete type (and, optionally, associated
|
|
6
|
-
* data)
|
|
7
|
-
*/
|
|
8
|
-
export declare function polymorphicWrap<TType extends string, TData>(type: TType, data?: TData): PolymorphicData<TType, TData>;
|
|
9
|
-
/**
|
|
10
|
-
* All polymorphic objects in Grafast have a $$concreteType property which
|
|
11
|
-
* contains the GraphQL object's type name; we simply return that.
|
|
12
|
-
*/
|
|
13
|
-
export declare function resolveType(o: unknown): string;
|
|
14
|
-
//# sourceMappingURL=polymorphic.d.ts.map
|
package/dist/polymorphic.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPolymorphicData = isPolymorphicData;
|
|
4
|
-
exports.assertPolymorphicData = assertPolymorphicData;
|
|
5
|
-
exports.polymorphicWrap = polymorphicWrap;
|
|
6
|
-
exports.resolveType = resolveType;
|
|
7
|
-
const inspect_js_1 = require("./inspect.js");
|
|
8
|
-
const interfaces_js_1 = require("./interfaces.js");
|
|
9
|
-
function isPolymorphicData(data) {
|
|
10
|
-
if (typeof data !== "object" || data === null) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
if (typeof data[interfaces_js_1.$$concreteType] !== "string") {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
function assertPolymorphicData(data) {
|
|
19
|
-
if (!isPolymorphicData(data)) {
|
|
20
|
-
throw new Error(`Expected a polymorphic object, received ${(0, inspect_js_1.inspect)(data)}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// const EMPTY_OBJECT = Object.freeze(Object.create(null));
|
|
24
|
-
/**
|
|
25
|
-
* Returns an object with the given concrete type (and, optionally, associated
|
|
26
|
-
* data)
|
|
27
|
-
*/
|
|
28
|
-
function polymorphicWrap(type,
|
|
29
|
-
// TODO: when we stop mutating `data` we can replace this with `EMPTY_OBJECT`
|
|
30
|
-
data = Object.create(null)) {
|
|
31
|
-
// ENHANCE: validate type further, e.g. that it's a valid object type
|
|
32
|
-
if (typeof type !== "string") {
|
|
33
|
-
throw new Error(`Expected a GraphQLObjectType name, but received ${(0, inspect_js_1.inspect)(type)}`);
|
|
34
|
-
}
|
|
35
|
-
if (data == null) {
|
|
36
|
-
throw new Error(`polymorphicWrap mustn't receive null-like data`);
|
|
37
|
-
}
|
|
38
|
-
Object.defineProperty(data, interfaces_js_1.$$concreteType, {
|
|
39
|
-
value: type,
|
|
40
|
-
enumerable: false,
|
|
41
|
-
writable: false,
|
|
42
|
-
configurable: false,
|
|
43
|
-
});
|
|
44
|
-
// TODO: should NOT mutate `data`, instead use a wrapper object and rewire
|
|
45
|
-
// through the pipeline.
|
|
46
|
-
return data;
|
|
47
|
-
/*
|
|
48
|
-
return Object.assign(Object.create(null), {
|
|
49
|
-
[$$concreteType]: type,
|
|
50
|
-
[$$data]: data,
|
|
51
|
-
});
|
|
52
|
-
*/
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* All polymorphic objects in Grafast have a $$concreteType property which
|
|
56
|
-
* contains the GraphQL object's type name; we simply return that.
|
|
57
|
-
*/
|
|
58
|
-
function resolveType(o) {
|
|
59
|
-
assertPolymorphicData(o);
|
|
60
|
-
return o[interfaces_js_1.$$concreteType];
|
|
61
|
-
}
|
|
62
|
-
/* TODO: we should be extracting data from a subproperty when we rewrite how polymorphism works.
|
|
63
|
-
/* *
|
|
64
|
-
* All polymorphic objects in Grafast have a $$concreteType property which
|
|
65
|
-
* contains the GraphQL object's type name; we simply return that.
|
|
66
|
-
* /
|
|
67
|
-
export function resolveData(o: unknown): string {
|
|
68
|
-
assertPolymorphicData(o);
|
|
69
|
-
return o[$$data];
|
|
70
|
-
}
|
|
71
|
-
*/
|
|
72
|
-
//# sourceMappingURL=polymorphic.js.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { GraphQLObjectType } from "graphql";
|
|
2
|
-
import type { ExecutionDetails, GrafastResultsList, PromiseOrDirect } from "../index.js";
|
|
3
|
-
import type { PolymorphicStep } from "../step.js";
|
|
4
|
-
import { Step } from "../step.js";
|
|
5
|
-
type StepData<TStep extends Step> = TStep extends Step<infer U> ? U : any;
|
|
6
|
-
export interface PolymorphicBranchMatchers<TStep extends Step> {
|
|
7
|
-
[typeName: string]: PolymorphicBranchMatcher<TStep>;
|
|
8
|
-
}
|
|
9
|
-
export interface PolymorphicBranchMatcher<TStep extends Step> {
|
|
10
|
-
match?: (obj: StepData<TStep>) => boolean;
|
|
11
|
-
plan?: ($obj: TStep) => Step;
|
|
12
|
-
}
|
|
13
|
-
export declare class PolymorphicBranchStep<TStep extends Step> extends Step implements PolymorphicStep {
|
|
14
|
-
static $$export: {
|
|
15
|
-
moduleName: string;
|
|
16
|
-
exportName: string;
|
|
17
|
-
};
|
|
18
|
-
isSyncAndSafe: boolean;
|
|
19
|
-
private typeNames;
|
|
20
|
-
private matchers;
|
|
21
|
-
constructor($step: TStep, matchers: PolymorphicBranchMatchers<TStep>);
|
|
22
|
-
planForType(objectType: GraphQLObjectType): Step;
|
|
23
|
-
execute({ indexMap, values: [values0], }: ExecutionDetails): PromiseOrDirect<GrafastResultsList<any>>;
|
|
24
|
-
}
|
|
25
|
-
export declare function polymorphicBranch<TStep extends Step>($step: TStep, matchers: PolymorphicBranchMatchers<TStep>): PolymorphicBranchStep<TStep>;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=polymorphicBranch.d.ts.map
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PolymorphicBranchStep = void 0;
|
|
4
|
-
exports.polymorphicBranch = polymorphicBranch;
|
|
5
|
-
const index_js_1 = require("../index.js");
|
|
6
|
-
const step_js_1 = require("../step.js");
|
|
7
|
-
const constant_js_1 = require("./constant.js");
|
|
8
|
-
class PolymorphicBranchStep extends step_js_1.Step {
|
|
9
|
-
static { this.$$export = {
|
|
10
|
-
moduleName: "grafast",
|
|
11
|
-
exportName: "PolymorphicBranchStep",
|
|
12
|
-
}; }
|
|
13
|
-
constructor($step, matchers) {
|
|
14
|
-
super();
|
|
15
|
-
this.isSyncAndSafe = true;
|
|
16
|
-
this.addDependency($step);
|
|
17
|
-
this.typeNames = Object.keys(matchers);
|
|
18
|
-
this.matchers = Object.fromEntries(Object.entries(matchers).map(([typeName, matcher]) => {
|
|
19
|
-
const fixedMatcher = {
|
|
20
|
-
match: matcher.match ?? ((obj) => obj.__typename === typeName),
|
|
21
|
-
plan: matcher.plan ?? (($obj) => $obj),
|
|
22
|
-
};
|
|
23
|
-
return [typeName, fixedMatcher];
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
|
-
planForType(objectType) {
|
|
27
|
-
const matcher = this.matchers[objectType.name];
|
|
28
|
-
const $step = this.getDep(0, true);
|
|
29
|
-
if (matcher) {
|
|
30
|
-
if (typeof matcher.plan === "function") {
|
|
31
|
-
return matcher.plan($step);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return $step;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
// TODO: should this be an error?
|
|
39
|
-
return (0, constant_js_1.constant)(null);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
execute({ indexMap, values: [values0], }) {
|
|
43
|
-
return indexMap((i) => {
|
|
44
|
-
const obj = values0.at(i);
|
|
45
|
-
let match = null;
|
|
46
|
-
if (obj != null) {
|
|
47
|
-
for (const typeName of this.typeNames) {
|
|
48
|
-
if (this.matchers[typeName].match(obj)) {
|
|
49
|
-
match = typeName;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return match !== null ? (0, index_js_1.polymorphicWrap)(match, obj) : null;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.PolymorphicBranchStep = PolymorphicBranchStep;
|
|
59
|
-
function polymorphicBranch($step, matchers) {
|
|
60
|
-
return new PolymorphicBranchStep($step, matchers);
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=polymorphicBranch.js.map
|