@pothos/selection-mapper 0.1.0 → 0.3.0
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/CHANGELOG.md +30 -0
- package/README.md +16 -6
- package/dts/deep-equal.d.ts +4 -0
- package/dts/deep-equal.d.ts.map +1 -1
- package/dts/errors.d.ts +7 -0
- package/dts/errors.d.ts.map +1 -0
- package/dts/index.d.ts +3 -2
- package/dts/index.d.ts.map +1 -1
- package/dts/loader-map.d.ts +37 -16
- package/dts/loader-map.d.ts.map +1 -1
- package/dts/matches.d.ts +5 -0
- package/dts/matches.d.ts.map +1 -1
- package/dts/parent-types.d.ts +9 -0
- package/dts/parent-types.d.ts.map +1 -0
- package/dts/plan.d.ts +36 -20
- package/dts/plan.d.ts.map +1 -1
- package/dts/shape.d.ts +8 -0
- package/dts/shape.d.ts.map +1 -0
- package/dts/types.d.ts +21 -1
- package/dts/types.d.ts.map +1 -1
- package/dts/walk.d.ts +20 -2
- package/dts/walk.d.ts.map +1 -1
- package/esm/deep-equal.d.ts +4 -0
- package/esm/deep-equal.d.ts.map +1 -1
- package/esm/deep-equal.js +60 -28
- package/esm/deep-equal.js.map +1 -1
- package/esm/errors.d.ts +7 -0
- package/esm/errors.d.ts.map +1 -0
- package/esm/errors.js +11 -0
- package/esm/errors.js.map +1 -0
- package/esm/index.d.ts +3 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/loader-map.d.ts +37 -16
- package/esm/loader-map.d.ts.map +1 -1
- package/esm/loader-map.js +165 -99
- package/esm/loader-map.js.map +1 -1
- package/esm/matches.d.ts +5 -0
- package/esm/matches.d.ts.map +1 -1
- package/esm/matches.js +11 -3
- package/esm/matches.js.map +1 -1
- package/esm/parent-types.d.ts +9 -0
- package/esm/parent-types.d.ts.map +1 -0
- package/esm/parent-types.js +24 -0
- package/esm/parent-types.js.map +1 -0
- package/esm/plan.d.ts +36 -20
- package/esm/plan.d.ts.map +1 -1
- package/esm/plan.js +107 -71
- package/esm/plan.js.map +1 -1
- package/esm/shape.d.ts +8 -0
- package/esm/shape.d.ts.map +1 -0
- package/esm/shape.js +94 -0
- package/esm/shape.js.map +1 -0
- package/esm/types.d.ts +21 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/walk.d.ts +20 -2
- package/esm/walk.d.ts.map +1 -1
- package/esm/walk.js +199 -71
- package/esm/walk.js.map +1 -1
- package/lib/deep-equal.js +60 -28
- package/lib/deep-equal.js.map +1 -1
- package/lib/errors.js +18 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.js +13 -3
- package/lib/index.js.map +1 -1
- package/lib/loader-map.js +145 -90
- package/lib/loader-map.js.map +1 -1
- package/lib/matches.js +14 -3
- package/lib/matches.js.map +1 -1
- package/lib/parent-types.js +29 -0
- package/lib/parent-types.js.map +1 -0
- package/lib/plan.js +107 -71
- package/lib/plan.js.map +1 -1
- package/lib/shape.js +109 -0
- package/lib/shape.js.map +1 -0
- package/lib/walk.js +186 -68
- package/lib/walk.js.map +1 -1
- package/package.json +4 -3
- package/src/deep-equal.ts +77 -34
- package/src/errors.ts +12 -0
- package/src/index.ts +6 -1
- package/src/loader-map.ts +235 -125
- package/src/matches.ts +15 -3
- package/src/parent-types.ts +33 -0
- package/src/plan.ts +145 -78
- package/src/shape.ts +126 -0
- package/src/types.ts +25 -1
- package/src/walk.ts +250 -83
package/lib/deep-equal.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Structural equality for query arguments (`where`, `orderBy`, `take`, ...). Keys holding
|
|
3
3
|
* `undefined` are treated as absent, so `{ where: cond ? filter : undefined }` compares equal to
|
|
4
4
|
* `{}` when the condition is false.
|
|
5
|
+
*
|
|
6
|
+
* Plain objects and arrays compare by value, and Dates by their time. Any other object (a Temporal
|
|
7
|
+
* value, a `Decimal`, a `Buffer`, a typed array) equals only an object of the same prototype that
|
|
8
|
+
* its `equals` method accepts, or itself when it has none.
|
|
5
9
|
*/ "use strict";
|
|
6
10
|
Object.defineProperty(exports, "__esModule", {
|
|
7
11
|
value: true
|
|
@@ -16,45 +20,73 @@ function deepEqual(left, right) {
|
|
|
16
20
|
if (left === right) {
|
|
17
21
|
return true;
|
|
18
22
|
}
|
|
19
|
-
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (right.length !== length) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
for(let i = 0; i < length; i += 1){
|
|
29
|
-
if (!deepEqual(left[i], right[i])) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
const lValue = left.valueOf?.();
|
|
36
|
-
const rValue = right.valueOf?.();
|
|
37
|
-
// A boxed value (a Date, a boxed primitive) compares by its primitive, whichever side it is
|
|
38
|
-
// on: a plain object's `valueOf` returns the object itself, and a null-prototype object has
|
|
39
|
-
// none at all, so neither is mistaken for one.
|
|
40
|
-
if (lValue != null && typeof lValue !== 'object' || rValue != null && typeof rValue !== 'object') {
|
|
41
|
-
return lValue === rValue;
|
|
23
|
+
if (!(left && right && typeof left === 'object' && typeof right === 'object')) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
27
|
+
if (!Array.isArray(left) || !Array.isArray(right)) {
|
|
28
|
+
return false;
|
|
42
29
|
}
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
30
|
+
const { length } = left;
|
|
31
|
+
if (right.length !== length) {
|
|
45
32
|
return false;
|
|
46
33
|
}
|
|
47
|
-
for
|
|
48
|
-
if (!deepEqual(left[
|
|
34
|
+
for(let i = 0; i < length; i += 1){
|
|
35
|
+
if (!deepEqual(left[i], right[i])) {
|
|
49
36
|
return false;
|
|
50
37
|
}
|
|
51
38
|
}
|
|
52
39
|
return true;
|
|
53
40
|
}
|
|
54
|
-
|
|
41
|
+
// Two objects of `Object.prototype`, the common case, need no further check.
|
|
42
|
+
if (Object.getPrototypeOf(left) !== Object.prototype || Object.getPrototypeOf(right) !== Object.prototype) {
|
|
43
|
+
const leftPlain = isPlain(left);
|
|
44
|
+
if (leftPlain !== isPlain(right)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (!leftPlain) {
|
|
48
|
+
return instancesEqual(left, right);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const keys = comparedKeys(left);
|
|
52
|
+
if (keys.length !== definedKeyCount(right)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
for (const key of keys){
|
|
56
|
+
if (!deepEqual(left[key], right[key])) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function isPlain(value) {
|
|
63
|
+
const proto = Object.getPrototypeOf(value);
|
|
64
|
+
return proto === null || proto === Object.prototype;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The shared prototype keeps the comparison symmetric, since Temporal's `equals` also accepts
|
|
68
|
+
* property bags and strings.
|
|
69
|
+
*/ function instancesEqual(left, right) {
|
|
70
|
+
if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (left instanceof Date) {
|
|
74
|
+
return left.getTime() === right.getTime();
|
|
75
|
+
}
|
|
76
|
+
const { equals } = left;
|
|
77
|
+
return typeof equals === 'function' && equals.call(left, right) === true;
|
|
55
78
|
}
|
|
56
79
|
function comparedKeys(value) {
|
|
57
80
|
return Object.keys(value).filter((key)=>value[key] !== undefined);
|
|
58
81
|
}
|
|
82
|
+
function definedKeyCount(value) {
|
|
83
|
+
let count = 0;
|
|
84
|
+
for (const key of Object.keys(value)){
|
|
85
|
+
if (value[key] !== undefined) {
|
|
86
|
+
count += 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return count;
|
|
90
|
+
}
|
|
59
91
|
|
|
60
92
|
//# sourceMappingURL=deep-equal.js.map
|
package/lib/deep-equal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deep-equal.ts"],"names":["deepEqual","left","right","Array","isArray","length","i","
|
|
1
|
+
{"version":3,"sources":["../src/deep-equal.ts"],"names":["deepEqual","left","right","Array","isArray","length","i","Object","getPrototypeOf","prototype","leftPlain","isPlain","instancesEqual","keys","comparedKeys","definedKeyCount","key","value","proto","Date","getTime","equals","call","filter","undefined","count"],"mappings":"AAAA;;;;;;;;CAQC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,UAAUC,IAAa,EAAEC,KAAc;IACrD,IAAID,SAASC,OAAO;QAClB,OAAO;IACT;IAEA,IAAI,CAAED,CAAAA,QAAQC,SAAS,OAAOD,SAAS,YAAY,OAAOC,UAAU,QAAO,GAAI;QAC7E,OAAO;IACT;IAEA,IAAIC,MAAMC,OAAO,CAACH,SAASE,MAAMC,OAAO,CAACF,QAAQ;QAC/C,IAAI,CAACC,MAAMC,OAAO,CAACH,SAAS,CAACE,MAAMC,OAAO,CAACF,QAAQ;YACjD,OAAO;QACT;QAEA,MAAM,EAAEG,MAAM,EAAE,GAAGJ;QAEnB,IAAIC,MAAMG,MAAM,KAAKA,QAAQ;YAC3B,OAAO;QACT;QAEA,IAAK,IAAIC,IAAI,GAAGA,IAAID,QAAQC,KAAK,EAAG;YAClC,IAAI,CAACN,UAAUC,IAAI,CAACK,EAAE,EAAEJ,KAAK,CAACI,EAAE,GAAG;gBACjC,OAAO;YACT;QACF;QAEA,OAAO;IACT;IAEA,6EAA6E;IAC7E,IACEC,OAAOC,cAAc,CAACP,UAAUM,OAAOE,SAAS,IAChDF,OAAOC,cAAc,CAACN,WAAWK,OAAOE,SAAS,EACjD;QACA,MAAMC,YAAYC,QAAQV;QAE1B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"__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "unexpectedError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return unexpectedError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@pothos/core");
|
|
12
|
+
function unexpectedError(detail) {
|
|
13
|
+
const error = new _core.PothosValidationError('Unexpected error.');
|
|
14
|
+
error.cause = new _core.PothosValidationError(detail);
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":["unexpectedError","detail","error","PothosValidationError","cause"],"mappings":";;;;+BAMgBA;;;eAAAA;;;sBANsB;AAM/B,SAASA,gBAAgBC,MAAc;IAC5C,MAAMC,QAAQ,IAAIC,2BAAqB,CAAC;IACxCD,MAAME,KAAK,GAAG,IAAID,2BAAqB,CAACF;IAExC,OAAOC;AACT"}
|
package/lib/index.js
CHANGED
|
@@ -28,15 +28,24 @@ _export(exports, {
|
|
|
28
28
|
get deepEqual () {
|
|
29
29
|
return _deepequal.deepEqual;
|
|
30
30
|
},
|
|
31
|
+
get fieldKey () {
|
|
32
|
+
return _loadermap.fieldKey;
|
|
33
|
+
},
|
|
34
|
+
get forExecution () {
|
|
35
|
+
return _loadermap.forExecution;
|
|
36
|
+
},
|
|
37
|
+
get forOperation () {
|
|
38
|
+
return _loadermap.forOperation;
|
|
39
|
+
},
|
|
31
40
|
get getLoaderMapping () {
|
|
32
41
|
return _loadermap.getLoaderMapping;
|
|
33
42
|
},
|
|
43
|
+
get mappingParentTypes () {
|
|
44
|
+
return _parenttypes.mappingParentTypes;
|
|
45
|
+
},
|
|
34
46
|
get selectedFieldNames () {
|
|
35
47
|
return _matches.selectedFieldNames;
|
|
36
48
|
},
|
|
37
|
-
get setFieldMapping () {
|
|
38
|
-
return _loadermap.setFieldMapping;
|
|
39
|
-
},
|
|
40
49
|
get setLoaderMappings () {
|
|
41
50
|
return _loadermap.setLoaderMappings;
|
|
42
51
|
},
|
|
@@ -52,6 +61,7 @@ const _deepequal = require("./deep-equal.js");
|
|
|
52
61
|
const _loadermap = require("./loader-map.js");
|
|
53
62
|
const _matches = require("./matches.js");
|
|
54
63
|
const _node = require("./node.js");
|
|
64
|
+
const _parenttypes = require("./parent-types.js");
|
|
55
65
|
const _plan = require("./plan.js");
|
|
56
66
|
|
|
57
67
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","NodeAdapter","Plan","cacheKey","deepEqual","getLoaderMapping","
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","NodeAdapter","Plan","cacheKey","deepEqual","fieldKey","forExecution","forOperation","getLoaderMapping","mappingParentTypes","selectedFieldNames","setLoaderMappings","setRowFieldMapping","setRowMappings"],"mappings":"AAAA;;;;CAIC;;;;;;;;;;;QACQA;eAAAA,gBAAO;;QAoBIC;eAAAA,iBAAW;;QAEtBC;eAAAA,UAAI;;QAnBXC;eAAAA,mBAAQ;;QAFDC;eAAAA,oBAAS;;QAGhBC;eAAAA,mBAAQ;;QACRC;eAAAA,uBAAY;;QACZC;eAAAA,uBAAY;;QACZC;eAAAA,2BAAgB;;QAcTC;eAAAA,+BAAkB;;QAHzBC;eAAAA,2BAAkB;;QARlBC;eAAAA,4BAAiB;;QACjBC;eAAAA,6BAAkB;;QAClBC;eAAAA,yBAAc;;;yBAZQ;2BACE;2BAYnB;yBAMA;sBACmD;6BACvB;sBACG"}
|
package/lib/loader-map.js
CHANGED
|
@@ -15,15 +15,21 @@ _export(exports, {
|
|
|
15
15
|
get cacheKey () {
|
|
16
16
|
return cacheKey;
|
|
17
17
|
},
|
|
18
|
+
get fieldKey () {
|
|
19
|
+
return fieldKey;
|
|
20
|
+
},
|
|
21
|
+
get forExecution () {
|
|
22
|
+
return forExecution;
|
|
23
|
+
},
|
|
24
|
+
get forOperation () {
|
|
25
|
+
return forOperation;
|
|
26
|
+
},
|
|
18
27
|
get getLoaderMapping () {
|
|
19
28
|
return getLoaderMapping;
|
|
20
29
|
},
|
|
21
30
|
get responsePath () {
|
|
22
31
|
return responsePath;
|
|
23
32
|
},
|
|
24
|
-
get setFieldMapping () {
|
|
25
|
-
return setFieldMapping;
|
|
26
|
-
},
|
|
27
33
|
get setLoaderMappings () {
|
|
28
34
|
return setLoaderMappings;
|
|
29
35
|
},
|
|
@@ -41,42 +47,111 @@ const _core = require("@pothos/core");
|
|
|
41
47
|
const EMPTY_MAPPING = Object.freeze({
|
|
42
48
|
nested: Object.freeze({})
|
|
43
49
|
});
|
|
50
|
+
/** Unions already made. A mapping is not changed once recorded, so one pair has one answer. */ const unions = new WeakMap();
|
|
44
51
|
function unionMappings(into, from) {
|
|
45
52
|
if (!into || into === EMPTY_MAPPING) {
|
|
46
53
|
return from;
|
|
47
54
|
}
|
|
55
|
+
if (into === from || from === EMPTY_MAPPING) {
|
|
56
|
+
return into;
|
|
57
|
+
}
|
|
58
|
+
let byFrom = unions.get(into);
|
|
59
|
+
if (!byFrom) {
|
|
60
|
+
byFrom = new WeakMap();
|
|
61
|
+
unions.set(into, byFrom);
|
|
62
|
+
}
|
|
63
|
+
const known = byFrom.get(from);
|
|
64
|
+
if (known) {
|
|
65
|
+
return known;
|
|
66
|
+
}
|
|
48
67
|
const nested = {
|
|
49
68
|
...into.nested
|
|
50
69
|
};
|
|
51
70
|
for (const key of Object.keys(from.nested)){
|
|
52
71
|
nested[key] = unionMappings(nested[key], from.nested[key]);
|
|
53
72
|
}
|
|
54
|
-
|
|
73
|
+
const union = into.position === undefined ? {
|
|
55
74
|
nested
|
|
56
75
|
} : {
|
|
57
76
|
nested,
|
|
58
77
|
position: into.position
|
|
59
78
|
};
|
|
79
|
+
byFrom.set(from, union);
|
|
80
|
+
return union;
|
|
60
81
|
}
|
|
82
|
+
/** Per context: the cache of each execution, by `executionOf`. */ const contextCaches = (0, _core.createContextCache)(()=>new WeakMap());
|
|
61
83
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* rebuilds the same key strings; a prefix builds them once.
|
|
84
|
+
* An object the executor builds once per execution, and once per event of a subscription, and
|
|
85
|
+
* hands to every resolver in it, @defer and @stream payloads included:
|
|
65
86
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
87
|
+
* - graphql-js 17: the `getAbortSignal` of the execution.
|
|
88
|
+
* - graphql-js 16 and @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
89
|
+
* path chain per execution or event, linking each field to its parent's, so every resolver
|
|
90
|
+
* beneath a root field shares its link, and the `subscribe` resolver has its own. Their fields'
|
|
91
|
+
* links carry a `typename`. A root field doesn't share its link with the others, so each root
|
|
92
|
+
* field has a cache of its own, which is all it reads.
|
|
93
|
+
* - graphql-jit: the coerced `variableValues`. It builds a new path, without `typename`, for every
|
|
94
|
+
* resolver, but coerces the variables afresh for every execution and event.
|
|
95
|
+
*/ function executionOf(info) {
|
|
96
|
+
const signal = info.getAbortSignal;
|
|
97
|
+
if (signal) {
|
|
98
|
+
return signal;
|
|
99
|
+
}
|
|
100
|
+
let { path } = info;
|
|
101
|
+
if (path.typename === undefined) {
|
|
102
|
+
return info.variableValues;
|
|
103
|
+
}
|
|
104
|
+
while(path.prev){
|
|
105
|
+
path = path.prev;
|
|
106
|
+
}
|
|
107
|
+
return path;
|
|
108
|
+
}
|
|
109
|
+
function cache(ctx, info) {
|
|
110
|
+
const executions = contextCaches(ctx);
|
|
111
|
+
const execution = executionOf(info);
|
|
112
|
+
let cached = executions.get(execution);
|
|
113
|
+
if (!cached) {
|
|
114
|
+
cached = {
|
|
115
|
+
places: new Map(),
|
|
116
|
+
rows: new WeakMap(),
|
|
117
|
+
rowScoped: false,
|
|
118
|
+
scopes: new WeakMap()
|
|
119
|
+
};
|
|
120
|
+
executions.set(execution, cached);
|
|
121
|
+
}
|
|
122
|
+
return cached;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Where `path`, a link of `info.path`, sits in its execution: the link itself, where the executor
|
|
126
|
+
* builds one per field execution and shares it with the resolvers beneath, which a field's link
|
|
127
|
+
* carrying a `typename` tells. Where it builds a new path for every resolver (graphql-jit), an
|
|
128
|
+
* object standing for the path's keys, list indices included.
|
|
129
|
+
*/ function placeOf(cached, info, path) {
|
|
130
|
+
if (info.path.typename !== undefined) {
|
|
131
|
+
return path;
|
|
132
|
+
}
|
|
133
|
+
const at = executionPath(path);
|
|
134
|
+
let place = cached.places.get(at);
|
|
135
|
+
if (!place) {
|
|
136
|
+
place = {};
|
|
137
|
+
cached.places.set(at, place);
|
|
138
|
+
}
|
|
139
|
+
return place;
|
|
140
|
+
}
|
|
141
|
+
function forOperation(cache, info) {
|
|
142
|
+
return entriesFor(cache, info.variableValues);
|
|
143
|
+
}
|
|
144
|
+
function forExecution(cache, info) {
|
|
145
|
+
return entriesFor(cache, executionOf(info));
|
|
146
|
+
}
|
|
147
|
+
function entriesFor(cache, key) {
|
|
148
|
+
let entries = cache.get(key);
|
|
149
|
+
if (!entries) {
|
|
150
|
+
entries = new Map();
|
|
151
|
+
cache.set(key, entries);
|
|
152
|
+
}
|
|
153
|
+
return entries;
|
|
154
|
+
}
|
|
80
155
|
/**
|
|
81
156
|
* Memoised per path link, which is created once per field per row and never mutated. graphql-js
|
|
82
157
|
* shares the links above a list between every row of it, so the prefix of a field resolved for
|
|
@@ -95,115 +170,95 @@ function responsePath(path) {
|
|
|
95
170
|
}
|
|
96
171
|
return key;
|
|
97
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Memoised per path link, as `pathKeys` is. Built only where paths are rebuilt for every resolver,
|
|
175
|
+
* so it saves the walk over a resolver's ancestors from building each prefix again.
|
|
176
|
+
*/ const executionPaths = new WeakMap();
|
|
177
|
+
/** Every key of a response path, list indices included, joined by `.`. */ function executionPath(path) {
|
|
178
|
+
let key = executionPaths.get(path);
|
|
179
|
+
if (key === undefined) {
|
|
180
|
+
key = path.prev ? `${executionPath(path.prev)}.${path.key}` : String(path.key);
|
|
181
|
+
executionPaths.set(path, key);
|
|
182
|
+
}
|
|
183
|
+
return key;
|
|
184
|
+
}
|
|
98
185
|
function cacheKey(type, path) {
|
|
99
186
|
return `${type}@${responsePath(path)}`;
|
|
100
187
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let under = keys.get(key);
|
|
115
|
-
if (under === undefined) {
|
|
116
|
-
const at = key.indexOf('@');
|
|
117
|
-
under = `${key.slice(0, at)}@${prefix}.${key.slice(at + 1)}`;
|
|
118
|
-
keys.set(key, under);
|
|
119
|
-
}
|
|
120
|
-
return under;
|
|
188
|
+
/** A number for each field node seen, by identity. Weak, so the nodes go with their document. */ const fieldNodeIds = new WeakMap();
|
|
189
|
+
let nextFieldNodeId = 0;
|
|
190
|
+
function fieldKey(type, info) {
|
|
191
|
+
let key = cacheKey(type, info.path);
|
|
192
|
+
for (const node of info.fieldNodes){
|
|
193
|
+
let id = fieldNodeIds.get(node);
|
|
194
|
+
if (id === undefined) {
|
|
195
|
+
id = nextFieldNodeId++;
|
|
196
|
+
fieldNodeIds.set(node, id);
|
|
197
|
+
}
|
|
198
|
+
key += `:${id}`;
|
|
199
|
+
}
|
|
200
|
+
return key;
|
|
121
201
|
}
|
|
122
202
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */ function ownerOf(row) {
|
|
123
203
|
return typeof row === 'object' && row !== null ? row : null;
|
|
124
204
|
}
|
|
125
205
|
/**
|
|
126
|
-
* Records `mapping`
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (held === undefined) {
|
|
133
|
-
cached.mappings.set(key, mapping);
|
|
134
|
-
} else if (held !== mapping && row) {
|
|
135
|
-
claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, path);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Records `mapping` for this field execution against `row` alone, never in the shared tier. The caller loaded
|
|
140
|
-
* `row` by itself, so an unclaimed key is not the caller's to take: the shared tier answers for
|
|
141
|
-
* every row of a field, and a sibling that was never loaded would read the entry as proof that
|
|
142
|
-
* it had been. With no row to hang it off there is nothing to record, and the resolvers beneath
|
|
143
|
-
* fall back and load their own data.
|
|
144
|
-
*/ function claimForRow(cached, type, mapping, row, path) {
|
|
145
|
-
let byPath = cached.rows.get(row);
|
|
146
|
-
if (!byPath) {
|
|
147
|
-
byPath = new WeakMap();
|
|
148
|
-
cached.rows.set(row, byPath);
|
|
206
|
+
* Records `mapping` for this field execution against `row` alone.
|
|
207
|
+
*/ function claimForRow(cached, type, mapping, row, place) {
|
|
208
|
+
let byPlace = cached.rows.get(row);
|
|
209
|
+
if (!byPlace) {
|
|
210
|
+
byPlace = new WeakMap();
|
|
211
|
+
cached.rows.set(row, byPlace);
|
|
149
212
|
cached.rowScoped = true;
|
|
150
213
|
}
|
|
151
|
-
let own =
|
|
214
|
+
let own = byPlace.get(place);
|
|
152
215
|
if (!own) {
|
|
153
216
|
own = new Map();
|
|
154
|
-
|
|
217
|
+
byPlace.set(place, own);
|
|
155
218
|
}
|
|
156
219
|
own.set(type, mapping);
|
|
157
220
|
}
|
|
158
221
|
function setLoaderMappings(ctx, info, mappings) {
|
|
159
|
-
const cached = cache(ctx);
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
cached.scopes.set(info.path, previous ? {
|
|
222
|
+
const cached = cache(ctx, info);
|
|
223
|
+
const place = placeOf(cached, info, info.path);
|
|
224
|
+
const previous = cached.scopes.get(place);
|
|
225
|
+
cached.scopes.set(place, previous ? {
|
|
164
226
|
...previous,
|
|
165
227
|
...mappings
|
|
166
228
|
} : mappings);
|
|
167
|
-
for (const key of Object.keys(mappings)){
|
|
168
|
-
cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
|
|
169
|
-
}
|
|
170
229
|
}
|
|
171
230
|
function setRowMappings(ctx, info, mappings) {
|
|
172
|
-
cache(ctx
|
|
173
|
-
|
|
174
|
-
function setFieldMapping(ctx, info, mapping, row) {
|
|
175
|
-
const cached = cache(ctx);
|
|
176
|
-
const owner = ownerOf(row);
|
|
177
|
-
claim(cached, cacheKey(info.parentType.name, info.path), mapping, owner, info.path);
|
|
178
|
-
cached.scopes.set(info.path, mapping.nested);
|
|
231
|
+
const cached = cache(ctx, info);
|
|
232
|
+
cached.scopes.set(placeOf(cached, info, info.path), mappings);
|
|
179
233
|
}
|
|
180
234
|
function setRowFieldMapping(ctx, info, mapping, row) {
|
|
181
|
-
const cached = cache(ctx);
|
|
235
|
+
const cached = cache(ctx, info);
|
|
182
236
|
const owner = ownerOf(row);
|
|
237
|
+
const place = placeOf(cached, info, info.path);
|
|
183
238
|
if (owner) {
|
|
184
|
-
claimForRow(cached, info.parentType.name, mapping, owner,
|
|
239
|
+
claimForRow(cached, info.parentType.name, mapping, owner, place);
|
|
185
240
|
}
|
|
186
|
-
cached.scopes.set(
|
|
241
|
+
cached.scopes.set(place, mapping.nested);
|
|
187
242
|
}
|
|
188
|
-
function getLoaderMapping(ctx,
|
|
189
|
-
const
|
|
190
|
-
const
|
|
243
|
+
function getLoaderMapping(ctx, info, type, row) {
|
|
244
|
+
const { path } = info;
|
|
245
|
+
const cached = cache(ctx, info);
|
|
191
246
|
if (cached.rowScoped) {
|
|
192
247
|
const owner = ownerOf(row);
|
|
193
|
-
const own = owner && cached.rows.get(owner)?.get(path)?.get(type);
|
|
248
|
+
const own = owner && cached.rows.get(owner)?.get(placeOf(cached, info, path))?.get(type);
|
|
194
249
|
if (own) {
|
|
195
250
|
return own;
|
|
196
251
|
}
|
|
197
252
|
}
|
|
198
253
|
for(let ancestor = path.prev; ancestor; ancestor = ancestor.prev){
|
|
199
|
-
const scope = cached.scopes.get(ancestor);
|
|
254
|
+
const scope = cached.scopes.get(placeOf(cached, info, ancestor));
|
|
200
255
|
if (scope) {
|
|
201
256
|
// A different plan may have omitted this field. Do not treat a sibling's shared mapping
|
|
202
257
|
// as proof that this execution loaded it.
|
|
203
258
|
return scope[`${type}@${responsePath(path).slice(responsePath(ancestor).length + 1)}`] ?? null;
|
|
204
259
|
}
|
|
205
260
|
}
|
|
206
|
-
return
|
|
261
|
+
return null;
|
|
207
262
|
}
|
|
208
263
|
|
|
209
264
|
//# sourceMappingURL=loader-map.js.map
|
package/lib/loader-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loader-map.ts"],"names":["EMPTY_MAPPING","cacheKey","
|
|
1
|
+
{"version":3,"sources":["../src/loader-map.ts"],"names":["EMPTY_MAPPING","cacheKey","fieldKey","forExecution","forOperation","getLoaderMapping","responsePath","setLoaderMappings","setRowFieldMapping","setRowMappings","unionMappings","Object","freeze","nested","unions","WeakMap","into","from","byFrom","get","set","known","key","keys","union","position","undefined","contextCaches","createContextCache","executionOf","info","signal","getAbortSignal","path","typename","variableValues","prev","cache","ctx","executions","execution","cached","places","Map","rows","rowScoped","scopes","placeOf","at","executionPath","place","entriesFor","entries","pathKeys","prefix","executionPaths","String","type","fieldNodeIds","nextFieldNodeId","node","fieldNodes","id","ownerOf","row","claimForRow","mapping","byPlace","own","mappings","previous","owner","parentType","name","ancestor","scope","slice","length"],"mappings":";;;;;;;;;;;QAuBaA;eAAAA;;QAkOGC;eAAAA;;QAgBAC;eAAAA;;QA9EAC;eAAAA;;Q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QH,QAAQN,QAAQX,MAAMA,KAAKG,IAAI;IAE7C,IAAIsC,OAAO;QACTN,YAAYxB,QAAQX,KAAK0C,UAAU,CAACC,IAAI,EAAEP,SAASK,OAAOrB;IAC5D;IAEAT,OAAOK,MAAM,CAAC1B,GAAG,CAAC8B,OAAOgB,QAAQrD,MAAM;AACzC;AASO,SAASR,iBACdiC,GAAW,EACXR,IAAwB,EACxB2B,IAAY,EACZO,GAAa;IAEb,MAAM,EAAE/B,IAAI,EAAE,GAAGH;IACjB,MAAMW,SAASJ,MAAMC,KAAKR;IAE1B,IAAIW,OAAOI,SAAS,EAAE;QACpB,MAAM0B,QAAQR,QAAQC;QACtB,MAAMI,MACJG,SACA9B,OAAOG,IAAI,CACRzB,GAAG,CAACoD,QACHpD,IAAI4B,QAAQN,QAAQX,MAAMG,QAC1Bd,IAAIsC;QAEV,IAAIW,KAAK;YACP,OAAOA;QACT;IACF;IAEA,IAAK,IAAIM,WAAWzC,KAAKG,IAAI,EAAEsC,UAAUA,WAAWA,SAAStC,IAAI,CAAE;QACjE,MAAMuC,QAAQlC,OAAOK,MAAM,CAAC3B,GAAG,CAAC4B,QAAQN,QAAQX,MAAM4C;QAEtD,IAAIC,OAAO;YACT,wFAAwF;YACxF,0CAA0C;YAC1C,OACEA,KAAK,CAAC,GAAGlB,KAAK,CAAC,EAAEnD,aAAa2B,MAAM2C,KAAK,CAACtE,aAAaoE,UAAUG,MAAM,GAAG,IAAI,CAAC,IAAI;QAEvF;IACF;IAEA,OAAO;AACT"}
|
package/lib/matches.js
CHANGED
|
@@ -21,6 +21,9 @@ _export(exports, {
|
|
|
21
21
|
get includeOf () {
|
|
22
22
|
return includeOf;
|
|
23
23
|
},
|
|
24
|
+
get includePaths () {
|
|
25
|
+
return includePaths;
|
|
26
|
+
},
|
|
24
27
|
get isDeferred () {
|
|
25
28
|
return isDeferred;
|
|
26
29
|
},
|
|
@@ -45,6 +48,14 @@ _export(exports, {
|
|
|
45
48
|
});
|
|
46
49
|
const _core = require("@pothos/core");
|
|
47
50
|
const _graphql = require("graphql");
|
|
51
|
+
function includePaths(include) {
|
|
52
|
+
if (include.paths?.length) {
|
|
53
|
+
return include.paths;
|
|
54
|
+
}
|
|
55
|
+
return include.path?.length ? [
|
|
56
|
+
include.path
|
|
57
|
+
] : undefined;
|
|
58
|
+
}
|
|
48
59
|
function includeOf(type) {
|
|
49
60
|
return type.extensions?.pothosIndirectInclude;
|
|
50
61
|
}
|
|
@@ -83,10 +94,10 @@ function matchesForModel(adapter, schema, matches, targetType) {
|
|
|
83
94
|
* `segment` is the indirect-include path segment the caller is looking for, when it has one; only
|
|
84
95
|
* its `type` is read, to pin the type a fragment is expected on.
|
|
85
96
|
*
|
|
86
|
-
* `memo` records the named fragments already
|
|
97
|
+
* `memo` records the named fragments already visited, keyed on the fragment, the two types, the
|
|
87
98
|
* deferred flag, and `memoKey` — whatever else the caller varies as it descends (`matchPath`
|
|
88
99
|
* passes its remaining path length and its alias path). A fragment spread more than once at one
|
|
89
|
-
* point of the traversal is
|
|
100
|
+
* point of the traversal is visited once: a valid fragment DAG can spread the same fragment at
|
|
90
101
|
* every level, which makes expanding every spread exponential in its depth. A caller that varies
|
|
91
102
|
* nothing passes no `memoKey`, leaving its memo finer than it needs to be by the deferred flag —
|
|
92
103
|
* a little time, never correctness, for a caller that accumulates.
|
|
@@ -207,7 +218,7 @@ function matchesForModel(adapter, schema, matches, targetType) {
|
|
|
207
218
|
* Follows each of `paths`, prefixed by any type-level `prefix`, from `selection` (which is expected
|
|
208
219
|
* to be a selection on `type`), reporting the fields at their ends to `onMatch` in path order then
|
|
209
220
|
* document order, and stopping when `onMatch` says to. Paths are followed through fragments; see
|
|
210
|
-
* `resolveFragmentTypes` for the rules. Each path gets its own memo: what one path
|
|
221
|
+
* `resolveFragmentTypes` for the rules. Each path gets its own memo: what one path visited says
|
|
211
222
|
* nothing about the next.
|
|
212
223
|
*/ function eachMatch(info, type, selection, paths, { prefix, path = [], deferred = false }, onMatch) {
|
|
213
224
|
for (const includePath of paths){
|