@pothos/selection-mapper 0.1.0 → 0.2.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 +24 -0
- package/README.md +17 -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 +36 -8
- 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 +36 -8
- package/esm/loader-map.d.ts.map +1 -1
- package/esm/loader-map.js +177 -60
- 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 -0
- package/lib/index.js.map +1 -1
- package/lib/loader-map.js +157 -53
- 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 -0
- package/src/loader-map.ts +261 -71
- 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/esm/deep-equal.js
CHANGED
|
@@ -2,49 +2,81 @@
|
|
|
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
|
*/ export function deepEqual(left, right) {
|
|
6
10
|
if (left === right) {
|
|
7
11
|
return true;
|
|
8
12
|
}
|
|
9
|
-
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (right.length !== length) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
for(let i = 0; i < length; i += 1){
|
|
19
|
-
if (!deepEqual(left[i], right[i])) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
const lValue = left.valueOf?.();
|
|
26
|
-
const rValue = right.valueOf?.();
|
|
27
|
-
// A boxed value (a Date, a boxed primitive) compares by its primitive, whichever side it is
|
|
28
|
-
// on: a plain object's `valueOf` returns the object itself, and a null-prototype object has
|
|
29
|
-
// none at all, so neither is mistaken for one.
|
|
30
|
-
if (lValue != null && typeof lValue !== 'object' || rValue != null && typeof rValue !== 'object') {
|
|
31
|
-
return lValue === rValue;
|
|
13
|
+
if (!(left && right && typeof left === 'object' && typeof right === 'object')) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
17
|
+
if (!Array.isArray(left) || !Array.isArray(right)) {
|
|
18
|
+
return false;
|
|
32
19
|
}
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
20
|
+
const { length } = left;
|
|
21
|
+
if (right.length !== length) {
|
|
35
22
|
return false;
|
|
36
23
|
}
|
|
37
|
-
for
|
|
38
|
-
if (!deepEqual(left[
|
|
24
|
+
for(let i = 0; i < length; i += 1){
|
|
25
|
+
if (!deepEqual(left[i], right[i])) {
|
|
39
26
|
return false;
|
|
40
27
|
}
|
|
41
28
|
}
|
|
42
29
|
return true;
|
|
43
30
|
}
|
|
44
|
-
|
|
31
|
+
// Two objects of `Object.prototype`, the common case, need no further check.
|
|
32
|
+
if (Object.getPrototypeOf(left) !== Object.prototype || Object.getPrototypeOf(right) !== Object.prototype) {
|
|
33
|
+
const leftPlain = isPlain(left);
|
|
34
|
+
if (leftPlain !== isPlain(right)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!leftPlain) {
|
|
38
|
+
return instancesEqual(left, right);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const keys = comparedKeys(left);
|
|
42
|
+
if (keys.length !== definedKeyCount(right)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
for (const key of keys){
|
|
46
|
+
if (!deepEqual(left[key], right[key])) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
function isPlain(value) {
|
|
53
|
+
const proto = Object.getPrototypeOf(value);
|
|
54
|
+
return proto === null || proto === Object.prototype;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The shared prototype keeps the comparison symmetric, since Temporal's `equals` also accepts
|
|
58
|
+
* property bags and strings.
|
|
59
|
+
*/ function instancesEqual(left, right) {
|
|
60
|
+
if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (left instanceof Date) {
|
|
64
|
+
return left.getTime() === right.getTime();
|
|
65
|
+
}
|
|
66
|
+
const { equals } = left;
|
|
67
|
+
return typeof equals === 'function' && equals.call(left, right) === true;
|
|
45
68
|
}
|
|
46
69
|
function comparedKeys(value) {
|
|
47
70
|
return Object.keys(value).filter((key)=>value[key] !== undefined);
|
|
48
71
|
}
|
|
72
|
+
function definedKeyCount(value) {
|
|
73
|
+
let count = 0;
|
|
74
|
+
for (const key of Object.keys(value)){
|
|
75
|
+
if (value[key] !== undefined) {
|
|
76
|
+
count += 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return count;
|
|
80
|
+
}
|
|
49
81
|
|
|
50
82
|
//# sourceMappingURL=deep-equal.js.map
|
package/esm/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,GACD,OAAO,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,IAAIS,cAAcC,QAAQT,QAAQ;YAChC,OAAO;QACT;QAEA,IAAI,CAACQ,WAAW;YACd,OAAOE,eAAeX,MAAMC;QAC9B;IACF;IAEA,MAAMW,OAAOC,aAAab;IAE1B,IAAIY,KAAKR,MAAM,KAAKU,gBAAgBb,QAAmC;QACrE,OAAO;IACT;IAEA,KAAK,MAAMc,OAAOH,KAAM;QACtB,IACE,CAACb,UAAU,AAACC,IAAgC,CAACe,IAAI,EAAE,AAACd,KAAiC,CAACc,IAAI,GAC1F;YACA,OAAO;QACT;IACF;IAEA,OAAO;AACT;AAEA,SAASL,QAAQM,KAAa;IAC5B,MAAMC,QAAQX,OAAOC,cAAc,CAACS;IAEpC,OAAOC,UAAU,QAAQA,UAAUX,OAAOE,SAAS;AACrD;AAEA;;;CAGC,GACD,SAASG,eAAeX,IAAY,EAAEC,KAAa;IACjD,IAAIK,OAAOC,cAAc,CAACP,UAAUM,OAAOC,cAAc,CAACN,QAAQ;QAChE,OAAO;IACT;IAEA,IAAID,gBAAgBkB,MAAM;QACxB,OAAOlB,KAAKmB,OAAO,OAAO,AAAClB,MAAekB,OAAO;IACnD;IAEA,MAAM,EAAEC,MAAM,EAAE,GAAGpB;IAEnB,OAAO,OAAOoB,WAAW,cAAcA,OAAOC,IAAI,CAACrB,MAAMC,WAAW;AACtE;AAEA,SAASY,aAAaG,KAA8B;IAClD,OAAOV,OAAOM,IAAI,CAACI,OAAOM,MAAM,CAAC,CAACP,MAAQC,KAAK,CAACD,IAAI,KAAKQ;AAC3D;AAEA,SAAST,gBAAgBE,KAA8B;IACrD,IAAIQ,QAAQ;IAEZ,KAAK,MAAMT,OAAOT,OAAOM,IAAI,CAACI,OAAQ;QACpC,IAAIA,KAAK,CAACD,IAAI,KAAKQ,WAAW;YAC5BC,SAAS;QACX;IACF;IAEA,OAAOA;AACT"}
|
package/esm/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PothosValidationError } from '@pothos/core';
|
|
2
|
+
/**
|
|
3
|
+
* An error raised while a request runs for a problem in the app's schema or code. Clients see only
|
|
4
|
+
* `Unexpected error.`; `detail` is the message of its `cause`, which responses leave out.
|
|
5
|
+
*/
|
|
6
|
+
export declare function unexpectedError(detail: string): PothosValidationError;
|
|
7
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,yBAK7C"}
|
package/esm/errors.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PothosValidationError } from '@pothos/core';
|
|
2
|
+
/**
|
|
3
|
+
* An error raised while a request runs for a problem in the app's schema or code. Clients see only
|
|
4
|
+
* `Unexpected error.`; `detail` is the message of its `cause`, which responses leave out.
|
|
5
|
+
*/ export function unexpectedError(detail) {
|
|
6
|
+
const error = new PothosValidationError('Unexpected error.');
|
|
7
|
+
error.cause = new PothosValidationError(detail);
|
|
8
|
+
return error;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":["PothosValidationError","unexpectedError","detail","error","cause"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,eAAe;AAErD;;;CAGC,GACD,OAAO,SAASC,gBAAgBC,MAAc;IAC5C,MAAMC,QAAQ,IAAIH,sBAAsB;IACxCG,MAAMC,KAAK,GAAG,IAAIJ,sBAAsBE;IAExC,OAAOC;AACT"}
|
package/esm/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { Adapter } from './adapter.js';
|
|
7
7
|
export { deepEqual } from './deep-equal.js';
|
|
8
|
-
export { cacheKey, getLoaderMapping, type Mappings, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
|
|
8
|
+
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, type Mapping, type Mappings, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
|
|
9
9
|
export { type IndirectInclude, type IndirectPathSegment, type PathSegment, selectedFieldNames, } from './matches.js';
|
|
10
10
|
export { type Node, NodeAdapter, type QueryVisitor } from './node.js';
|
|
11
|
+
export { mappingParentTypes } from './parent-types.js';
|
|
11
12
|
export { Plan, type PlayedPlan } from './plan.js';
|
|
12
|
-
export type { MergeOptions, NestedSelection, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
|
|
13
|
+
export type { MergeOptions, NestedSelection, ParentRowOptions, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,QAAQ,EACb,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,IAAI,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EACV,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,IAAI,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* adapters and loaders call. Everything else is module-private; see the README.
|
|
5
5
|
*/ export { Adapter } from './adapter.js';
|
|
6
6
|
export { deepEqual } from './deep-equal.js';
|
|
7
|
-
export { cacheKey, getLoaderMapping, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
|
|
7
|
+
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
|
|
8
8
|
export { selectedFieldNames } from './matches.js';
|
|
9
9
|
export { NodeAdapter } from './node.js';
|
|
10
|
+
export { mappingParentTypes } from './parent-types.js';
|
|
10
11
|
export { Plan } from './plan.js';
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","getLoaderMapping","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","selectedFieldNames","NodeAdapter","Plan"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACEC,QAAQ,EACRC,gBAAgB,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","fieldKey","forExecution","forOperation","getLoaderMapping","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","selectedFieldNames","NodeAdapter","mappingParentTypes","Plan"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACEC,QAAQ,EACRC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,gBAAgB,EAGhBC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,QACT,kBAAkB;AACzB,SAIEC,kBAAkB,QACb,eAAe;AACtB,SAAoBC,WAAW,QAA2B,YAAY;AACtE,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,IAAI,QAAyB,YAAY"}
|
package/esm/loader-map.d.ts
CHANGED
|
@@ -21,22 +21,48 @@ export declare const EMPTY_MAPPING: Mapping;
|
|
|
21
21
|
/**
|
|
22
22
|
* Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
|
|
23
23
|
* mapping is never changed after the fact (two plays may accept a different subset of the fields).
|
|
24
|
+
*
|
|
25
|
+
* Invocations of one field share what is beneath them (see `Plan.nested`), so a mapping is a DAG
|
|
26
|
+
* whose keys can all lead to one mapping. A pair is unioned once however many keys lead to it, or
|
|
27
|
+
* the union would take as long as the DAG written out as a tree.
|
|
24
28
|
*/
|
|
25
29
|
export declare function unionMappings(into: Mapping | undefined, from: Mapping): Mapping;
|
|
30
|
+
/**
|
|
31
|
+
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
32
|
+
* every executor coerces afresh for each operation, so operations sharing a context never share
|
|
33
|
+
* an entry. The events of a subscription may share them, so a plan cached here runs its `select`
|
|
34
|
+
* and `query` callbacks once for all of them; use `forExecution` where they read per-event state.
|
|
35
|
+
*/
|
|
36
|
+
export declare function forOperation<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
|
|
37
|
+
/**
|
|
38
|
+
* The entries of `cache` for the execution `info` is in, by `executionOf`, as mappings are kept:
|
|
39
|
+
* each event of a subscription gets its own, and @defer and @stream payloads share their
|
|
40
|
+
* execution's.
|
|
41
|
+
*/
|
|
42
|
+
export declare function forExecution<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
|
|
26
43
|
/** The string keys of a response path joined by `.`; list indices are dropped. */
|
|
27
44
|
export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
|
|
28
45
|
export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
|
|
46
|
+
/**
|
|
47
|
+
* `cacheKey(type, info.path)` and the identity of every node in `info.fieldNodes`. The path keeps
|
|
48
|
+
* each place in the response apart, list indices aside, so the root fields of a mutation, which run
|
|
49
|
+
* in turn and whose callbacks may read what an earlier one changed, never share a plan. The nodes
|
|
50
|
+
* decide what a plan loads: fragments on different types can merge different nodes into one
|
|
51
|
+
* response path, so a plan keyed on the path alone would be reused for a field asking for
|
|
52
|
+
* something else.
|
|
53
|
+
*/
|
|
54
|
+
export declare function fieldKey(type: string, info: GraphQLResolveInfo): string;
|
|
29
55
|
/**
|
|
30
56
|
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
31
|
-
* The plan loaded the whole field, so its mappings answer for
|
|
32
|
-
*
|
|
57
|
+
* The plan loaded the whole field, so its mappings answer for everything resolved beneath this
|
|
58
|
+
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
33
59
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
34
60
|
*/
|
|
35
61
|
export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
|
|
36
62
|
/**
|
|
37
63
|
* Records a row's mappings and scopes its descendants to this concrete field execution. A
|
|
38
64
|
* descendant's parent is a different object, so row identity alone cannot carry its plan through
|
|
39
|
-
* a relation, connection wrapper, or list. The
|
|
65
|
+
* a relation, connection wrapper, or list. The place keeps list indices to isolate siblings.
|
|
40
66
|
*/
|
|
41
67
|
export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
|
|
42
68
|
/**
|
|
@@ -48,16 +74,18 @@ export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, ma
|
|
|
48
74
|
export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
|
|
49
75
|
/**
|
|
50
76
|
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
51
|
-
* against `row` rather than claimed for the whole field, so
|
|
52
|
-
*
|
|
77
|
+
* against `row` rather than claimed for the whole field, so the field's lookup on `row` answers
|
|
78
|
+
* from it whatever the field's other rows were loaded with.
|
|
53
79
|
*
|
|
54
80
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
55
81
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
56
82
|
*/
|
|
57
83
|
export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
|
|
58
84
|
/**
|
|
59
|
-
* The mapping recorded for the field
|
|
60
|
-
* over the plan's. `row` is the value whose data the mapping describes — the resolver's
|
|
85
|
+
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
86
|
+
* row over the plan's. `row` is the value whose data the mapping describes — the resolver's
|
|
87
|
+
* parent. The plan's comes from the nearest field execution above that recorded one: with none
|
|
88
|
+
* above, no plan loaded `row`, whatever was recorded for another row at the same path.
|
|
61
89
|
*/
|
|
62
|
-
export declare function getLoaderMapping(ctx: object,
|
|
90
|
+
export declare function getLoaderMapping(ctx: object, info: GraphQLResolveInfo, type: string, row?: unknown): Mapping | null;
|
|
63
91
|
//# sourceMappingURL=loader-map.d.ts.map
|
package/esm/loader-map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-map.d.ts","sourceRoot":"","sources":["../src/loader-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,mFAAmF;AACnF,eAAO,MAAM,aAAa,EAAE,OAAkE,CAAC;
|
|
1
|
+
{"version":3,"file":"loader-map.d.ts","sourceRoot":"","sources":["../src/loader-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,mFAAmF;AACnF,eAAO,MAAM,aAAa,EAAE,OAAkE,CAAC;AAK/F;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAiC/E;AA8GD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACtC,IAAI,EAAE,kBAAkB,GACvB,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAEhB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACtC,IAAI,EAAE,kBAAkB,GACvB,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAEhB;AAoBD,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,CAgBjF;AAoBD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,UAEtE;AAMD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAevE;AAsED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,QAW1F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,QAIvF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,QAOb;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,QAWb;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,OAAO,GACZ,OAAO,GAAG,IAAI,CA+BhB"}
|
package/esm/loader-map.js
CHANGED
|
@@ -2,45 +2,129 @@ import { createContextCache } from '@pothos/core';
|
|
|
2
2
|
/** The mapping of a static selection: nothing can ever be recorded beneath one. */ export const EMPTY_MAPPING = Object.freeze({
|
|
3
3
|
nested: Object.freeze({})
|
|
4
4
|
});
|
|
5
|
+
/** Unions already made. A mapping is not changed once recorded, so one pair has one answer. */ const unions = new WeakMap();
|
|
5
6
|
/**
|
|
6
7
|
* Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
|
|
7
8
|
* mapping is never changed after the fact (two plays may accept a different subset of the fields).
|
|
9
|
+
*
|
|
10
|
+
* Invocations of one field share what is beneath them (see `Plan.nested`), so a mapping is a DAG
|
|
11
|
+
* whose keys can all lead to one mapping. A pair is unioned once however many keys lead to it, or
|
|
12
|
+
* the union would take as long as the DAG written out as a tree.
|
|
8
13
|
*/ export function unionMappings(into, from) {
|
|
9
14
|
if (!into || into === EMPTY_MAPPING) {
|
|
10
15
|
return from;
|
|
11
16
|
}
|
|
17
|
+
if (into === from || from === EMPTY_MAPPING) {
|
|
18
|
+
return into;
|
|
19
|
+
}
|
|
20
|
+
let byFrom = unions.get(into);
|
|
21
|
+
if (!byFrom) {
|
|
22
|
+
byFrom = new WeakMap();
|
|
23
|
+
unions.set(into, byFrom);
|
|
24
|
+
}
|
|
25
|
+
const known = byFrom.get(from);
|
|
26
|
+
if (known) {
|
|
27
|
+
return known;
|
|
28
|
+
}
|
|
12
29
|
const nested = {
|
|
13
30
|
...into.nested
|
|
14
31
|
};
|
|
15
32
|
for (const key of Object.keys(from.nested)){
|
|
16
33
|
nested[key] = unionMappings(nested[key], from.nested[key]);
|
|
17
34
|
}
|
|
18
|
-
|
|
35
|
+
const union = into.position === undefined ? {
|
|
19
36
|
nested
|
|
20
37
|
} : {
|
|
21
38
|
nested,
|
|
22
39
|
position: into.position
|
|
23
40
|
};
|
|
41
|
+
byFrom.set(from, union);
|
|
42
|
+
return union;
|
|
24
43
|
}
|
|
44
|
+
/** Per context: the cache of each execution, by `executionOf`. */ const contextCaches = createContextCache(()=>new WeakMap());
|
|
25
45
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* rebuilds the same key strings; a prefix builds them once.
|
|
46
|
+
* An object the executor builds once per execution, and once per event of a subscription, and
|
|
47
|
+
* hands to every resolver in it, @defer and @stream payloads included:
|
|
29
48
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
49
|
+
* - graphql-js 17: the `getAbortSignal` of the execution.
|
|
50
|
+
* - graphql-js 16 and @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
51
|
+
* path chain per execution or event, linking each field to its parent's, so every resolver
|
|
52
|
+
* beneath a root field shares its link, and the `subscribe` resolver has its own. Their fields'
|
|
53
|
+
* links carry a `typename`. A root field doesn't share its link with the others, so each root
|
|
54
|
+
* field has a cache of its own, which is all it reads.
|
|
55
|
+
* - graphql-jit: the coerced `variableValues`. It builds a new path, without `typename`, for every
|
|
56
|
+
* resolver, but coerces the variables afresh for every execution and event.
|
|
57
|
+
*/ function executionOf(info) {
|
|
58
|
+
const signal = info.getAbortSignal;
|
|
59
|
+
if (signal) {
|
|
60
|
+
return signal;
|
|
61
|
+
}
|
|
62
|
+
let { path } = info;
|
|
63
|
+
if (path.typename === undefined) {
|
|
64
|
+
return info.variableValues;
|
|
65
|
+
}
|
|
66
|
+
while(path.prev){
|
|
67
|
+
path = path.prev;
|
|
68
|
+
}
|
|
69
|
+
return path;
|
|
70
|
+
}
|
|
71
|
+
function cache(ctx, info) {
|
|
72
|
+
const executions = contextCaches(ctx);
|
|
73
|
+
const execution = executionOf(info);
|
|
74
|
+
let cached = executions.get(execution);
|
|
75
|
+
if (!cached) {
|
|
76
|
+
cached = {
|
|
77
|
+
mappings: new Map(),
|
|
78
|
+
places: new Map(),
|
|
79
|
+
rehomed: new Map(),
|
|
80
|
+
rows: new WeakMap(),
|
|
81
|
+
rowScoped: false,
|
|
82
|
+
scopes: new WeakMap()
|
|
83
|
+
};
|
|
84
|
+
executions.set(execution, cached);
|
|
85
|
+
}
|
|
86
|
+
return cached;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Where `path`, a link of `info.path`, sits in its execution: the link itself, where the executor
|
|
90
|
+
* builds one per field execution and shares it with the resolvers beneath, which a field's link
|
|
91
|
+
* carrying a `typename` tells. Where it builds a new path for every resolver (graphql-jit), an
|
|
92
|
+
* object standing for the path's keys, list indices included.
|
|
93
|
+
*/ function placeOf(cached, info, path) {
|
|
94
|
+
if (info.path.typename !== undefined) {
|
|
95
|
+
return path;
|
|
96
|
+
}
|
|
97
|
+
const at = executionPath(path);
|
|
98
|
+
let place = cached.places.get(at);
|
|
99
|
+
if (!place) {
|
|
100
|
+
place = {};
|
|
101
|
+
cached.places.set(at, place);
|
|
102
|
+
}
|
|
103
|
+
return place;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
107
|
+
* every executor coerces afresh for each operation, so operations sharing a context never share
|
|
108
|
+
* an entry. The events of a subscription may share them, so a plan cached here runs its `select`
|
|
109
|
+
* and `query` callbacks once for all of them; use `forExecution` where they read per-event state.
|
|
110
|
+
*/ export function forOperation(cache, info) {
|
|
111
|
+
return entriesFor(cache, info.variableValues);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The entries of `cache` for the execution `info` is in, by `executionOf`, as mappings are kept:
|
|
115
|
+
* each event of a subscription gets its own, and @defer and @stream payloads share their
|
|
116
|
+
* execution's.
|
|
117
|
+
*/ export function forExecution(cache, info) {
|
|
118
|
+
return entriesFor(cache, executionOf(info));
|
|
119
|
+
}
|
|
120
|
+
function entriesFor(cache, key) {
|
|
121
|
+
let entries = cache.get(key);
|
|
122
|
+
if (!entries) {
|
|
123
|
+
entries = new Map();
|
|
124
|
+
cache.set(key, entries);
|
|
125
|
+
}
|
|
126
|
+
return entries;
|
|
127
|
+
}
|
|
44
128
|
/**
|
|
45
129
|
* Memoised per path link, which is created once per field per row and never mutated. graphql-js
|
|
46
130
|
* shares the links above a list between every row of it, so the prefix of a field resolved for
|
|
@@ -59,13 +143,46 @@ import { createContextCache } from '@pothos/core';
|
|
|
59
143
|
}
|
|
60
144
|
return key;
|
|
61
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Memoised per path link, as `pathKeys` is. Built only where paths are rebuilt for every resolver,
|
|
148
|
+
* so it saves the walk over a resolver's ancestors from building each prefix again.
|
|
149
|
+
*/ const executionPaths = new WeakMap();
|
|
150
|
+
/** Every key of a response path, list indices included, joined by `.`. */ function executionPath(path) {
|
|
151
|
+
let key = executionPaths.get(path);
|
|
152
|
+
if (key === undefined) {
|
|
153
|
+
key = path.prev ? `${executionPath(path.prev)}.${path.key}` : String(path.key);
|
|
154
|
+
executionPaths.set(path, key);
|
|
155
|
+
}
|
|
156
|
+
return key;
|
|
157
|
+
}
|
|
62
158
|
export function cacheKey(type, path) {
|
|
63
159
|
return `${type}@${responsePath(path)}`;
|
|
64
160
|
}
|
|
161
|
+
/** A number for each field node seen, by identity. Weak, so the nodes go with their document. */ const fieldNodeIds = new WeakMap();
|
|
162
|
+
let nextFieldNodeId = 0;
|
|
163
|
+
/**
|
|
164
|
+
* `cacheKey(type, info.path)` and the identity of every node in `info.fieldNodes`. The path keeps
|
|
165
|
+
* each place in the response apart, list indices aside, so the root fields of a mutation, which run
|
|
166
|
+
* in turn and whose callbacks may read what an earlier one changed, never share a plan. The nodes
|
|
167
|
+
* decide what a plan loads: fragments on different types can merge different nodes into one
|
|
168
|
+
* response path, so a plan keyed on the path alone would be reused for a field asking for
|
|
169
|
+
* something else.
|
|
170
|
+
*/ export function fieldKey(type, info) {
|
|
171
|
+
let key = cacheKey(type, info.path);
|
|
172
|
+
for (const node of info.fieldNodes){
|
|
173
|
+
let id = fieldNodeIds.get(node);
|
|
174
|
+
if (id === undefined) {
|
|
175
|
+
id = nextFieldNodeId++;
|
|
176
|
+
fieldNodeIds.set(node, id);
|
|
177
|
+
}
|
|
178
|
+
key += `:${id}`;
|
|
179
|
+
}
|
|
180
|
+
return key;
|
|
181
|
+
}
|
|
65
182
|
/**
|
|
66
183
|
* The keys `mappings` is recorded under when it is rehomed beneath `prefix`. Built once per
|
|
67
|
-
* prefix
|
|
68
|
-
*
|
|
184
|
+
* prefix: the strings depend on the path and the plan's own keys, never on which row is being
|
|
185
|
+
* recorded for.
|
|
69
186
|
*/ function rehomedKeys(cached, prefix) {
|
|
70
187
|
let keys = cached.rehomed.get(prefix);
|
|
71
188
|
if (!keys) {
|
|
@@ -89,47 +206,43 @@ export function cacheKey(type, path) {
|
|
|
89
206
|
/**
|
|
90
207
|
* Records `mapping` at `key` for `row`. An unclaimed key takes it, and a key already holding this
|
|
91
208
|
* very mapping needs no write, so the rows after the first write nothing. Only a key two plans
|
|
92
|
-
* disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing
|
|
93
|
-
|
|
94
|
-
*/ function claim(cached, key, mapping, row, path) {
|
|
209
|
+
* disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing.
|
|
210
|
+
*/ function claim(cached, key, mapping, row, place) {
|
|
95
211
|
const held = cached.mappings.get(key);
|
|
96
212
|
if (held === undefined) {
|
|
97
213
|
cached.mappings.set(key, mapping);
|
|
98
214
|
} else if (held !== mapping && row) {
|
|
99
|
-
claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row,
|
|
215
|
+
claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, place);
|
|
100
216
|
}
|
|
101
217
|
}
|
|
102
218
|
/**
|
|
103
|
-
* Records `mapping` for this field execution against `row` alone
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
let byPath = cached.rows.get(row);
|
|
110
|
-
if (!byPath) {
|
|
111
|
-
byPath = new WeakMap();
|
|
112
|
-
cached.rows.set(row, byPath);
|
|
219
|
+
* Records `mapping` for this field execution against `row` alone.
|
|
220
|
+
*/ function claimForRow(cached, type, mapping, row, place) {
|
|
221
|
+
let byPlace = cached.rows.get(row);
|
|
222
|
+
if (!byPlace) {
|
|
223
|
+
byPlace = new WeakMap();
|
|
224
|
+
cached.rows.set(row, byPlace);
|
|
113
225
|
cached.rowScoped = true;
|
|
114
226
|
}
|
|
115
|
-
let own =
|
|
227
|
+
let own = byPlace.get(place);
|
|
116
228
|
if (!own) {
|
|
117
229
|
own = new Map();
|
|
118
|
-
|
|
230
|
+
byPlace.set(place, own);
|
|
119
231
|
}
|
|
120
232
|
own.set(type, mapping);
|
|
121
233
|
}
|
|
122
234
|
/**
|
|
123
235
|
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
124
|
-
* The plan loaded the whole field, so its mappings answer for
|
|
125
|
-
*
|
|
236
|
+
* The plan loaded the whole field, so its mappings answer for everything resolved beneath this
|
|
237
|
+
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
126
238
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
127
239
|
*/ export function setLoaderMappings(ctx, info, mappings) {
|
|
128
|
-
const cached = cache(ctx);
|
|
240
|
+
const cached = cache(ctx, info);
|
|
129
241
|
const prefix = responsePath(info.path);
|
|
130
242
|
const keys = rehomedKeys(cached, prefix);
|
|
131
|
-
const
|
|
132
|
-
cached.scopes.
|
|
243
|
+
const place = placeOf(cached, info, info.path);
|
|
244
|
+
const previous = cached.scopes.get(place);
|
|
245
|
+
cached.scopes.set(place, previous ? {
|
|
133
246
|
...previous,
|
|
134
247
|
...mappings
|
|
135
248
|
} : mappings);
|
|
@@ -140,9 +253,10 @@ export function cacheKey(type, path) {
|
|
|
140
253
|
/**
|
|
141
254
|
* Records a row's mappings and scopes its descendants to this concrete field execution. A
|
|
142
255
|
* descendant's parent is a different object, so row identity alone cannot carry its plan through
|
|
143
|
-
* a relation, connection wrapper, or list. The
|
|
256
|
+
* a relation, connection wrapper, or list. The place keeps list indices to isolate siblings.
|
|
144
257
|
*/ export function setRowMappings(ctx, info, mappings) {
|
|
145
|
-
cache(ctx
|
|
258
|
+
const cached = cache(ctx, info);
|
|
259
|
+
cached.scopes.set(placeOf(cached, info, info.path), mappings);
|
|
146
260
|
}
|
|
147
261
|
/**
|
|
148
262
|
* Records the mapping of the field `info` resolves (under its own parent type) along with the
|
|
@@ -150,48 +264,51 @@ export function cacheKey(type, path) {
|
|
|
150
264
|
* themselves up. `row` is the value the field is about to resolve with: the parent row when it
|
|
151
265
|
* was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
|
|
152
266
|
*/ export function setFieldMapping(ctx, info, mapping, row) {
|
|
153
|
-
const cached = cache(ctx);
|
|
154
|
-
const
|
|
155
|
-
claim(cached, cacheKey(info.parentType.name, info.path), mapping,
|
|
156
|
-
cached.scopes.set(
|
|
267
|
+
const cached = cache(ctx, info);
|
|
268
|
+
const place = placeOf(cached, info, info.path);
|
|
269
|
+
claim(cached, cacheKey(info.parentType.name, info.path), mapping, ownerOf(row), place);
|
|
270
|
+
cached.scopes.set(place, mapping.nested);
|
|
157
271
|
}
|
|
158
272
|
/**
|
|
159
273
|
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
160
|
-
* against `row` rather than claimed for the whole field, so
|
|
161
|
-
*
|
|
274
|
+
* against `row` rather than claimed for the whole field, so the field's lookup on `row` answers
|
|
275
|
+
* from it whatever the field's other rows were loaded with.
|
|
162
276
|
*
|
|
163
277
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
164
278
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
165
279
|
*/ export function setRowFieldMapping(ctx, info, mapping, row) {
|
|
166
|
-
const cached = cache(ctx);
|
|
280
|
+
const cached = cache(ctx, info);
|
|
167
281
|
const owner = ownerOf(row);
|
|
282
|
+
const place = placeOf(cached, info, info.path);
|
|
168
283
|
if (owner) {
|
|
169
|
-
claimForRow(cached, info.parentType.name, mapping, owner,
|
|
284
|
+
claimForRow(cached, info.parentType.name, mapping, owner, place);
|
|
170
285
|
}
|
|
171
|
-
cached.scopes.set(
|
|
286
|
+
cached.scopes.set(place, mapping.nested);
|
|
172
287
|
}
|
|
173
288
|
/**
|
|
174
|
-
* The mapping recorded for the field
|
|
175
|
-
* over the plan's. `row` is the value whose data the mapping describes — the resolver's
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
289
|
+
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
290
|
+
* row over the plan's. `row` is the value whose data the mapping describes — the resolver's
|
|
291
|
+
* parent. The plan's comes from the nearest field execution above that recorded one: with none
|
|
292
|
+
* above, no plan loaded `row`, whatever was recorded for another row at the same path.
|
|
293
|
+
*/ export function getLoaderMapping(ctx, info, type, row) {
|
|
294
|
+
const { path } = info;
|
|
295
|
+
const cached = cache(ctx, info);
|
|
179
296
|
if (cached.rowScoped) {
|
|
180
297
|
const owner = ownerOf(row);
|
|
181
|
-
const own = owner && cached.rows.get(owner)?.get(path)?.get(type);
|
|
298
|
+
const own = owner && cached.rows.get(owner)?.get(placeOf(cached, info, path))?.get(type);
|
|
182
299
|
if (own) {
|
|
183
300
|
return own;
|
|
184
301
|
}
|
|
185
302
|
}
|
|
186
303
|
for(let ancestor = path.prev; ancestor; ancestor = ancestor.prev){
|
|
187
|
-
const scope = cached.scopes.get(ancestor);
|
|
304
|
+
const scope = cached.scopes.get(placeOf(cached, info, ancestor));
|
|
188
305
|
if (scope) {
|
|
189
306
|
// A different plan may have omitted this field. Do not treat a sibling's shared mapping
|
|
190
307
|
// as proof that this execution loaded it.
|
|
191
308
|
return scope[`${type}@${responsePath(path).slice(responsePath(ancestor).length + 1)}`] ?? null;
|
|
192
309
|
}
|
|
193
310
|
}
|
|
194
|
-
return
|
|
311
|
+
return null;
|
|
195
312
|
}
|
|
196
313
|
|
|
197
314
|
//# sourceMappingURL=loader-map.js.map
|