@pothos/selection-mapper 0.2.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 +6 -0
- package/README.md +3 -4
- package/dts/index.d.ts +1 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/loader-map.d.ts +17 -24
- package/dts/loader-map.d.ts.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/loader-map.d.ts +17 -24
- package/esm/loader-map.d.ts.map +1 -1
- package/esm/loader-map.js +17 -68
- package/esm/loader-map.js.map +1 -1
- package/lib/index.js +0 -3
- package/lib/index.js.map +1 -1
- package/lib/loader-map.js +0 -49
- package/lib/loader-map.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/loader-map.ts +25 -105
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -11,10 +11,9 @@ their own. Use the plugins.
|
|
|
11
11
|
|
|
12
12
|
The surface is what those plugins import and nothing more: `Plan` (with the statics `Plan.fromInfo`
|
|
13
13
|
and `Plan.forParentRow`), `Adapter` and `NodeAdapter`, the loader-map helpers (`cacheKey`,
|
|
14
|
-
`forOperation`, `getLoaderMapping`, `
|
|
15
|
-
`
|
|
16
|
-
|
|
17
|
-
drizzle's differ — so neither of them is here.
|
|
14
|
+
`forOperation`, `getLoaderMapping`, `setLoaderMappings`, `setRowFieldMapping`, `setRowMappings`),
|
|
15
|
+
`mappingParentTypes`, `selectedFieldNames` and `deepEqual`. Each plugin builds the query it passes
|
|
16
|
+
to a resolver itself. Prisma's `queryFromInfo` and drizzle's differ, so neither is here.
|
|
18
17
|
|
|
19
18
|
## Vocabulary
|
|
20
19
|
|
package/dts/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { Adapter } from './adapter.js';
|
|
7
7
|
export { deepEqual } from './deep-equal.js';
|
|
8
|
-
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, type Mapping, type Mappings,
|
|
8
|
+
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, type Mapping, type Mappings, 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
11
|
export { mappingParentTypes } from './parent-types.js';
|
package/dts/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,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,
|
|
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,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/dts/loader-map.d.ts
CHANGED
|
@@ -30,31 +30,31 @@ export declare function unionMappings(into: Mapping | undefined, from: Mapping):
|
|
|
30
30
|
/**
|
|
31
31
|
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
32
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
|
|
34
|
-
* and `query` callbacks once for all of them
|
|
33
|
+
* an entry. The events of a subscription may share one, so a plan cached here runs its `select`
|
|
34
|
+
* and `query` callbacks once for all of them. Use `forExecution` if the callbacks read per-event
|
|
35
|
+
* state.
|
|
35
36
|
*/
|
|
36
37
|
export declare function forOperation<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
|
|
37
38
|
/**
|
|
38
|
-
* The entries of `cache` for the execution `info` is in
|
|
39
|
-
*
|
|
40
|
-
* execution's.
|
|
39
|
+
* The entries of `cache` for the execution `info` is in. Each event of a subscription gets its own
|
|
40
|
+
* entries, and `@defer` and `@stream` payloads share the entries of their execution.
|
|
41
41
|
*/
|
|
42
42
|
export declare function forExecution<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
|
|
43
43
|
/** The string keys of a response path joined by `.`; list indices are dropped. */
|
|
44
44
|
export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
|
|
45
45
|
export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
|
|
46
46
|
/**
|
|
47
|
-
* `cacheKey(type, info.path)`
|
|
48
|
-
*
|
|
49
|
-
* in turn and
|
|
50
|
-
*
|
|
51
|
-
* response path,
|
|
52
|
-
* something else.
|
|
47
|
+
* The key to cache a field's plan under: `cacheKey(type, info.path)` plus an id for each node in
|
|
48
|
+
* `info.fieldNodes`. The path leaves out list indices, so the items of a list share a plan. The
|
|
49
|
+
* root fields of a mutation run in turn, and a callback may read what an earlier field changed.
|
|
50
|
+
* Their paths differ, so each gets its own plan. The nodes are part of the key because fragments on
|
|
51
|
+
* different types can merge different nodes into one response path, and a plan keyed on the path
|
|
52
|
+
* alone would be reused for a field that selects something else.
|
|
53
53
|
*/
|
|
54
54
|
export declare function fieldKey(type: string, info: GraphQLResolveInfo): string;
|
|
55
55
|
/**
|
|
56
56
|
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
57
|
-
* The plan loaded the whole field, so its mappings
|
|
57
|
+
* The plan loaded the whole field, so its mappings are used for everything resolved beneath this
|
|
58
58
|
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
59
59
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
60
60
|
*/
|
|
@@ -66,16 +66,8 @@ export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo,
|
|
|
66
66
|
*/
|
|
67
67
|
export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
|
|
68
68
|
/**
|
|
69
|
-
* Records
|
|
70
|
-
*
|
|
71
|
-
* themselves up. `row` is the value the field is about to resolve with: the parent row when it
|
|
72
|
-
* was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
|
|
73
|
-
*/
|
|
74
|
-
export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
|
|
75
|
-
/**
|
|
76
|
-
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
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.
|
|
69
|
+
* Records a mapping for `row` only, for the field `info` resolves. Use it when the plan loaded
|
|
70
|
+
* `row` alone. The field's other rows don't use this mapping.
|
|
79
71
|
*
|
|
80
72
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
81
73
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
@@ -84,8 +76,9 @@ export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo
|
|
|
84
76
|
/**
|
|
85
77
|
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
86
78
|
* 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
|
|
88
|
-
*
|
|
79
|
+
* parent. The plan's mapping comes from the nearest field execution above this one that recorded
|
|
80
|
+
* mappings. Returns `null` if there is none or it has no mapping for this field, even if a mapping
|
|
81
|
+
* was recorded for another row at the same path.
|
|
89
82
|
*/
|
|
90
83
|
export declare function getLoaderMapping(ctx: object, info: GraphQLResolveInfo, type: string, row?: unknown): Mapping | null;
|
|
91
84
|
//# sourceMappingURL=loader-map.d.ts.map
|
package/dts/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;AAK/F;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,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tE;AAMD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAevE;AAyBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,QAK1F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,QAIvF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,QAWb;AAED;;;;;;GAMG;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/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { Adapter } from './adapter.js';
|
|
7
7
|
export { deepEqual } from './deep-equal.js';
|
|
8
|
-
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, type Mapping, type Mappings,
|
|
8
|
+
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, type Mapping, type Mappings, 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
11
|
export { mappingParentTypes } from './parent-types.js';
|
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,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,
|
|
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,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,7 +4,7 @@
|
|
|
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, fieldKey, forExecution, forOperation, getLoaderMapping,
|
|
7
|
+
export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
|
|
8
8
|
export { selectedFieldNames } from './matches.js';
|
|
9
9
|
export { NodeAdapter } from './node.js';
|
|
10
10
|
export { mappingParentTypes } from './parent-types.js';
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","fieldKey","forExecution","forOperation","getLoaderMapping","
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","fieldKey","forExecution","forOperation","getLoaderMapping","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,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
|
@@ -30,31 +30,31 @@ export declare function unionMappings(into: Mapping | undefined, from: Mapping):
|
|
|
30
30
|
/**
|
|
31
31
|
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
32
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
|
|
34
|
-
* and `query` callbacks once for all of them
|
|
33
|
+
* an entry. The events of a subscription may share one, so a plan cached here runs its `select`
|
|
34
|
+
* and `query` callbacks once for all of them. Use `forExecution` if the callbacks read per-event
|
|
35
|
+
* state.
|
|
35
36
|
*/
|
|
36
37
|
export declare function forOperation<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
|
|
37
38
|
/**
|
|
38
|
-
* The entries of `cache` for the execution `info` is in
|
|
39
|
-
*
|
|
40
|
-
* execution's.
|
|
39
|
+
* The entries of `cache` for the execution `info` is in. Each event of a subscription gets its own
|
|
40
|
+
* entries, and `@defer` and `@stream` payloads share the entries of their execution.
|
|
41
41
|
*/
|
|
42
42
|
export declare function forExecution<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
|
|
43
43
|
/** The string keys of a response path joined by `.`; list indices are dropped. */
|
|
44
44
|
export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
|
|
45
45
|
export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
|
|
46
46
|
/**
|
|
47
|
-
* `cacheKey(type, info.path)`
|
|
48
|
-
*
|
|
49
|
-
* in turn and
|
|
50
|
-
*
|
|
51
|
-
* response path,
|
|
52
|
-
* something else.
|
|
47
|
+
* The key to cache a field's plan under: `cacheKey(type, info.path)` plus an id for each node in
|
|
48
|
+
* `info.fieldNodes`. The path leaves out list indices, so the items of a list share a plan. The
|
|
49
|
+
* root fields of a mutation run in turn, and a callback may read what an earlier field changed.
|
|
50
|
+
* Their paths differ, so each gets its own plan. The nodes are part of the key because fragments on
|
|
51
|
+
* different types can merge different nodes into one response path, and a plan keyed on the path
|
|
52
|
+
* alone would be reused for a field that selects something else.
|
|
53
53
|
*/
|
|
54
54
|
export declare function fieldKey(type: string, info: GraphQLResolveInfo): string;
|
|
55
55
|
/**
|
|
56
56
|
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
57
|
-
* The plan loaded the whole field, so its mappings
|
|
57
|
+
* The plan loaded the whole field, so its mappings are used for everything resolved beneath this
|
|
58
58
|
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
59
59
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
60
60
|
*/
|
|
@@ -66,16 +66,8 @@ export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo,
|
|
|
66
66
|
*/
|
|
67
67
|
export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
|
|
68
68
|
/**
|
|
69
|
-
* Records
|
|
70
|
-
*
|
|
71
|
-
* themselves up. `row` is the value the field is about to resolve with: the parent row when it
|
|
72
|
-
* was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
|
|
73
|
-
*/
|
|
74
|
-
export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
|
|
75
|
-
/**
|
|
76
|
-
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
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.
|
|
69
|
+
* Records a mapping for `row` only, for the field `info` resolves. Use it when the plan loaded
|
|
70
|
+
* `row` alone. The field's other rows don't use this mapping.
|
|
79
71
|
*
|
|
80
72
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
81
73
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
@@ -84,8 +76,9 @@ export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo
|
|
|
84
76
|
/**
|
|
85
77
|
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
86
78
|
* 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
|
|
88
|
-
*
|
|
79
|
+
* parent. The plan's mapping comes from the nearest field execution above this one that recorded
|
|
80
|
+
* mappings. Returns `null` if there is none or it has no mapping for this field, even if a mapping
|
|
81
|
+
* was recorded for another row at the same path.
|
|
89
82
|
*/
|
|
90
83
|
export declare function getLoaderMapping(ctx: object, info: GraphQLResolveInfo, type: string, row?: unknown): Mapping | null;
|
|
91
84
|
//# 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;AAK/F;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAiC/E;
|
|
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;AAoGD;;;;;;G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CAAC,EAAE,OAAO,GACZ,OAAO,GAAG,IAAI,CA+BhB"}
|
package/esm/loader-map.js
CHANGED
|
@@ -74,9 +74,7 @@ function cache(ctx, info) {
|
|
|
74
74
|
let cached = executions.get(execution);
|
|
75
75
|
if (!cached) {
|
|
76
76
|
cached = {
|
|
77
|
-
mappings: new Map(),
|
|
78
77
|
places: new Map(),
|
|
79
|
-
rehomed: new Map(),
|
|
80
78
|
rows: new WeakMap(),
|
|
81
79
|
rowScoped: false,
|
|
82
80
|
scopes: new WeakMap()
|
|
@@ -105,15 +103,15 @@ function cache(ctx, info) {
|
|
|
105
103
|
/**
|
|
106
104
|
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
107
105
|
* every executor coerces afresh for each operation, so operations sharing a context never share
|
|
108
|
-
* an entry. The events of a subscription may share
|
|
109
|
-
* and `query` callbacks once for all of them
|
|
106
|
+
* an entry. The events of a subscription may share one, so a plan cached here runs its `select`
|
|
107
|
+
* and `query` callbacks once for all of them. Use `forExecution` if the callbacks read per-event
|
|
108
|
+
* state.
|
|
110
109
|
*/ export function forOperation(cache, info) {
|
|
111
110
|
return entriesFor(cache, info.variableValues);
|
|
112
111
|
}
|
|
113
112
|
/**
|
|
114
|
-
* The entries of `cache` for the execution `info` is in
|
|
115
|
-
*
|
|
116
|
-
* execution's.
|
|
113
|
+
* The entries of `cache` for the execution `info` is in. Each event of a subscription gets its own
|
|
114
|
+
* entries, and `@defer` and `@stream` payloads share the entries of their execution.
|
|
117
115
|
*/ export function forExecution(cache, info) {
|
|
118
116
|
return entriesFor(cache, executionOf(info));
|
|
119
117
|
}
|
|
@@ -161,12 +159,12 @@ export function cacheKey(type, path) {
|
|
|
161
159
|
/** A number for each field node seen, by identity. Weak, so the nodes go with their document. */ const fieldNodeIds = new WeakMap();
|
|
162
160
|
let nextFieldNodeId = 0;
|
|
163
161
|
/**
|
|
164
|
-
* `cacheKey(type, info.path)`
|
|
165
|
-
*
|
|
166
|
-
* in turn and
|
|
167
|
-
*
|
|
168
|
-
* response path,
|
|
169
|
-
* something else.
|
|
162
|
+
* The key to cache a field's plan under: `cacheKey(type, info.path)` plus an id for each node in
|
|
163
|
+
* `info.fieldNodes`. The path leaves out list indices, so the items of a list share a plan. The
|
|
164
|
+
* root fields of a mutation run in turn, and a callback may read what an earlier field changed.
|
|
165
|
+
* Their paths differ, so each gets its own plan. The nodes are part of the key because fragments on
|
|
166
|
+
* different types can merge different nodes into one response path, and a plan keyed on the path
|
|
167
|
+
* alone would be reused for a field that selects something else.
|
|
170
168
|
*/ export function fieldKey(type, info) {
|
|
171
169
|
let key = cacheKey(type, info.path);
|
|
172
170
|
for (const node of info.fieldNodes){
|
|
@@ -179,42 +177,9 @@ let nextFieldNodeId = 0;
|
|
|
179
177
|
}
|
|
180
178
|
return key;
|
|
181
179
|
}
|
|
182
|
-
/**
|
|
183
|
-
* The keys `mappings` is recorded under when it is rehomed beneath `prefix`. Built once per
|
|
184
|
-
* prefix: the strings depend on the path and the plan's own keys, never on which row is being
|
|
185
|
-
* recorded for.
|
|
186
|
-
*/ function rehomedKeys(cached, prefix) {
|
|
187
|
-
let keys = cached.rehomed.get(prefix);
|
|
188
|
-
if (!keys) {
|
|
189
|
-
keys = new Map();
|
|
190
|
-
cached.rehomed.set(prefix, keys);
|
|
191
|
-
}
|
|
192
|
-
return keys;
|
|
193
|
-
}
|
|
194
|
-
/** `key`, a plan's own `Type@relative.path`, moved beneath `prefix`. Built once per prefix. */ function rehome(keys, key, prefix) {
|
|
195
|
-
let under = keys.get(key);
|
|
196
|
-
if (under === undefined) {
|
|
197
|
-
const at = key.indexOf('@');
|
|
198
|
-
under = `${key.slice(0, at)}@${prefix}.${key.slice(at + 1)}`;
|
|
199
|
-
keys.set(key, under);
|
|
200
|
-
}
|
|
201
|
-
return under;
|
|
202
|
-
}
|
|
203
180
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */ function ownerOf(row) {
|
|
204
181
|
return typeof row === 'object' && row !== null ? row : null;
|
|
205
182
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Records `mapping` at `key` for `row`. An unclaimed key takes it, and a key already holding this
|
|
208
|
-
* very mapping needs no write, so the rows after the first write nothing. Only a key two plans
|
|
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) {
|
|
211
|
-
const held = cached.mappings.get(key);
|
|
212
|
-
if (held === undefined) {
|
|
213
|
-
cached.mappings.set(key, mapping);
|
|
214
|
-
} else if (held !== mapping && row) {
|
|
215
|
-
claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, place);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
183
|
/**
|
|
219
184
|
* Records `mapping` for this field execution against `row` alone.
|
|
220
185
|
*/ function claimForRow(cached, type, mapping, row, place) {
|
|
@@ -233,22 +198,17 @@ let nextFieldNodeId = 0;
|
|
|
233
198
|
}
|
|
234
199
|
/**
|
|
235
200
|
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
236
|
-
* The plan loaded the whole field, so its mappings
|
|
201
|
+
* The plan loaded the whole field, so its mappings are used for everything resolved beneath this
|
|
237
202
|
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
238
203
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
239
204
|
*/ export function setLoaderMappings(ctx, info, mappings) {
|
|
240
205
|
const cached = cache(ctx, info);
|
|
241
|
-
const prefix = responsePath(info.path);
|
|
242
|
-
const keys = rehomedKeys(cached, prefix);
|
|
243
206
|
const place = placeOf(cached, info, info.path);
|
|
244
207
|
const previous = cached.scopes.get(place);
|
|
245
208
|
cached.scopes.set(place, previous ? {
|
|
246
209
|
...previous,
|
|
247
210
|
...mappings
|
|
248
211
|
} : mappings);
|
|
249
|
-
for (const key of Object.keys(mappings)){
|
|
250
|
-
cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
|
|
251
|
-
}
|
|
252
212
|
}
|
|
253
213
|
/**
|
|
254
214
|
* Records a row's mappings and scopes its descendants to this concrete field execution. A
|
|
@@ -259,20 +219,8 @@ let nextFieldNodeId = 0;
|
|
|
259
219
|
cached.scopes.set(placeOf(cached, info, info.path), mappings);
|
|
260
220
|
}
|
|
261
221
|
/**
|
|
262
|
-
* Records
|
|
263
|
-
*
|
|
264
|
-
* themselves up. `row` is the value the field is about to resolve with: the parent row when it
|
|
265
|
-
* was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
|
|
266
|
-
*/ export function setFieldMapping(ctx, info, mapping, row) {
|
|
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);
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
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.
|
|
222
|
+
* Records a mapping for `row` only, for the field `info` resolves. Use it when the plan loaded
|
|
223
|
+
* `row` alone. The field's other rows don't use this mapping.
|
|
276
224
|
*
|
|
277
225
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
278
226
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
@@ -288,8 +236,9 @@ let nextFieldNodeId = 0;
|
|
|
288
236
|
/**
|
|
289
237
|
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
290
238
|
* 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
|
|
292
|
-
*
|
|
239
|
+
* parent. The plan's mapping comes from the nearest field execution above this one that recorded
|
|
240
|
+
* mappings. Returns `null` if there is none or it has no mapping for this field, even if a mapping
|
|
241
|
+
* was recorded for another row at the same path.
|
|
293
242
|
*/ export function getLoaderMapping(ctx, info, type, row) {
|
|
294
243
|
const { path } = info;
|
|
295
244
|
const cached = cache(ctx, info);
|
package/esm/loader-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loader-map.ts"],"names":["createContextCache","EMPTY_MAPPING","Object","freeze","nested","unions","WeakMap","unionMappings","into","from","byFrom","get","set","known","key","keys","union","position","undefined","contextCaches","executionOf","info","signal","getAbortSignal","path","typename","variableValues","prev","cache","ctx","executions","execution","cached","
|
|
1
|
+
{"version":3,"sources":["../src/loader-map.ts"],"names":["createContextCache","EMPTY_MAPPING","Object","freeze","nested","unions","WeakMap","unionMappings","into","from","byFrom","get","set","known","key","keys","union","position","undefined","contextCaches","executionOf","info","signal","getAbortSignal","path","typename","variableValues","prev","cache","ctx","executions","execution","cached","places","Map","rows","rowScoped","scopes","placeOf","at","executionPath","place","forOperation","entriesFor","forExecution","entries","pathKeys","responsePath","prefix","executionPaths","String","cacheKey","type","fieldNodeIds","nextFieldNodeId","fieldKey","node","fieldNodes","id","ownerOf","row","claimForRow","mapping","byPlace","own","setLoaderMappings","mappings","previous","setRowMappings","setRowFieldMapping","owner","parentType","name","getLoaderMapping","ancestor","scope","slice","length"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,eAAe;AAsBlD,iFAAiF,GACjF,OAAO,MAAMC,gBAAyBC,OAAOC,MAAM,CAAC;IAAEC,QAAQF,OAAOC,MAAM,CAAC,CAAC;AAAe,GAAG;AAE/F,6FAA6F,GAC7F,MAAME,SAAS,IAAIC;AAEnB;;;;;;;CAOC,GACD,OAAO,SAASC,cAAcC,IAAyB,EAAEC,IAAa;IACpE,IAAI,CAACD,QAAQA,SAASP,eAAe;QACnC,OAAOQ;IACT;IAEA,IAAID,SAASC,QAAQA,SAASR,eAAe;QAC3C,OAAOO;IACT;IAEA,IAAIE,SAASL,OAAOM,GAAG,CAACH;IAExB,IAAI,CAACE,QAAQ;QACXA,SAAS,IAAIJ;QACbD,OAAOO,GAAG,CAACJ,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I,SAAS,EAAE;QACpB,MAAMkC,QAAQX,QAAQC;QACtB,MAAMI,MACJM,SACAtC,OAAOG,IAAI,CACRxB,GAAG,CAAC2D,QACH3D,IAAI2B,QAAQN,QAAQX,MAAMG,QAC1Bb,IAAIyC;QAEV,IAAIY,KAAK;YACP,OAAOA;QACT;IACF;IAEA,IAAK,IAAIU,WAAWlD,KAAKG,IAAI,EAAE+C,UAAUA,WAAWA,SAAS/C,IAAI,CAAE;QACjE,MAAMgD,QAAQ3C,OAAOK,MAAM,CAAC1B,GAAG,CAAC2B,QAAQN,QAAQX,MAAMqD;QAEtD,IAAIC,OAAO;YACT,wFAAwF;YACxF,0CAA0C;YAC1C,OACEA,KAAK,CAAC,GAAGvB,KAAK,CAAC,EAAEL,aAAavB,MAAMoD,KAAK,CAAC7B,aAAa2B,UAAUG,MAAM,GAAG,IAAI,CAAC,IAAI;QAEvF;IACF;IAEA,OAAO;AACT"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","NodeAdapter","Plan","cacheKey","deepEqual","fieldKey","forExecution","forOperation","getLoaderMapping","mappingParentTypes","selectedFieldNames","
|
|
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
|
@@ -30,9 +30,6 @@ _export(exports, {
|
|
|
30
30
|
get responsePath () {
|
|
31
31
|
return responsePath;
|
|
32
32
|
},
|
|
33
|
-
get setFieldMapping () {
|
|
34
|
-
return setFieldMapping;
|
|
35
|
-
},
|
|
36
33
|
get setLoaderMappings () {
|
|
37
34
|
return setLoaderMappings;
|
|
38
35
|
},
|
|
@@ -115,9 +112,7 @@ function cache(ctx, info) {
|
|
|
115
112
|
let cached = executions.get(execution);
|
|
116
113
|
if (!cached) {
|
|
117
114
|
cached = {
|
|
118
|
-
mappings: new Map(),
|
|
119
115
|
places: new Map(),
|
|
120
|
-
rehomed: new Map(),
|
|
121
116
|
rows: new WeakMap(),
|
|
122
117
|
rowScoped: false,
|
|
123
118
|
scopes: new WeakMap()
|
|
@@ -204,42 +199,9 @@ function fieldKey(type, info) {
|
|
|
204
199
|
}
|
|
205
200
|
return key;
|
|
206
201
|
}
|
|
207
|
-
/**
|
|
208
|
-
* The keys `mappings` is recorded under when it is rehomed beneath `prefix`. Built once per
|
|
209
|
-
* prefix: the strings depend on the path and the plan's own keys, never on which row is being
|
|
210
|
-
* recorded for.
|
|
211
|
-
*/ function rehomedKeys(cached, prefix) {
|
|
212
|
-
let keys = cached.rehomed.get(prefix);
|
|
213
|
-
if (!keys) {
|
|
214
|
-
keys = new Map();
|
|
215
|
-
cached.rehomed.set(prefix, keys);
|
|
216
|
-
}
|
|
217
|
-
return keys;
|
|
218
|
-
}
|
|
219
|
-
/** `key`, a plan's own `Type@relative.path`, moved beneath `prefix`. Built once per prefix. */ function rehome(keys, key, prefix) {
|
|
220
|
-
let under = keys.get(key);
|
|
221
|
-
if (under === undefined) {
|
|
222
|
-
const at = key.indexOf('@');
|
|
223
|
-
under = `${key.slice(0, at)}@${prefix}.${key.slice(at + 1)}`;
|
|
224
|
-
keys.set(key, under);
|
|
225
|
-
}
|
|
226
|
-
return under;
|
|
227
|
-
}
|
|
228
202
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */ function ownerOf(row) {
|
|
229
203
|
return typeof row === 'object' && row !== null ? row : null;
|
|
230
204
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Records `mapping` at `key` for `row`. An unclaimed key takes it, and a key already holding this
|
|
233
|
-
* very mapping needs no write, so the rows after the first write nothing. Only a key two plans
|
|
234
|
-
* disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing.
|
|
235
|
-
*/ function claim(cached, key, mapping, row, place) {
|
|
236
|
-
const held = cached.mappings.get(key);
|
|
237
|
-
if (held === undefined) {
|
|
238
|
-
cached.mappings.set(key, mapping);
|
|
239
|
-
} else if (held !== mapping && row) {
|
|
240
|
-
claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, place);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
205
|
/**
|
|
244
206
|
* Records `mapping` for this field execution against `row` alone.
|
|
245
207
|
*/ function claimForRow(cached, type, mapping, row, place) {
|
|
@@ -258,28 +220,17 @@ function fieldKey(type, info) {
|
|
|
258
220
|
}
|
|
259
221
|
function setLoaderMappings(ctx, info, mappings) {
|
|
260
222
|
const cached = cache(ctx, info);
|
|
261
|
-
const prefix = responsePath(info.path);
|
|
262
|
-
const keys = rehomedKeys(cached, prefix);
|
|
263
223
|
const place = placeOf(cached, info, info.path);
|
|
264
224
|
const previous = cached.scopes.get(place);
|
|
265
225
|
cached.scopes.set(place, previous ? {
|
|
266
226
|
...previous,
|
|
267
227
|
...mappings
|
|
268
228
|
} : mappings);
|
|
269
|
-
for (const key of Object.keys(mappings)){
|
|
270
|
-
cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
|
|
271
|
-
}
|
|
272
229
|
}
|
|
273
230
|
function setRowMappings(ctx, info, mappings) {
|
|
274
231
|
const cached = cache(ctx, info);
|
|
275
232
|
cached.scopes.set(placeOf(cached, info, info.path), mappings);
|
|
276
233
|
}
|
|
277
|
-
function setFieldMapping(ctx, info, mapping, row) {
|
|
278
|
-
const cached = cache(ctx, info);
|
|
279
|
-
const place = placeOf(cached, info, info.path);
|
|
280
|
-
claim(cached, cacheKey(info.parentType.name, info.path), mapping, ownerOf(row), place);
|
|
281
|
-
cached.scopes.set(place, mapping.nested);
|
|
282
|
-
}
|
|
283
234
|
function setRowFieldMapping(ctx, info, mapping, row) {
|
|
284
235
|
const cached = cache(ctx, info);
|
|
285
236
|
const owner = ownerOf(row);
|
package/lib/loader-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loader-map.ts"],"names":["EMPTY_MAPPING","cacheKey","fieldKey","forExecution","forOperation","getLoaderMapping","responsePath","
|
|
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;;QAXAC;eAAAA;;QAwLAC;eAAAA;;QAnJAC;eAAAA;;QAkGAC;eAAAA;;QAyBAC;eAAAA;;QAbAC;eAAAA;;QA/RAC;eAAAA;;;sBApCmB;AAuB5B,MAAMV,gBAAyBW,OAAOC,MAAM,CAAC;IAAEC,QAAQF,OAAOC,M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AQrD,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/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/loader-map.ts
CHANGED
|
@@ -70,30 +70,22 @@ export function unionMappings(into: Mapping | undefined, from: Mapping): Mapping
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Per execution: the mappings recorded so far
|
|
74
|
-
* the path prefix that rehomed them. `responsePath` drops list indices, so every row of a list
|
|
75
|
-
* rebuilds the same key strings; a prefix builds them once.
|
|
73
|
+
* Per execution: the mappings recorded so far.
|
|
76
74
|
*
|
|
77
|
-
* `scopes` holds what a plan recorded beneath a field execution: everything resolved beneath it
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* `mappings` holds a mapping recorded for each path, list indices dropped. It tells whether
|
|
86
|
-
* the plans of a path's rows agree (see `claim`), and never answers a lookup: a row at the same
|
|
87
|
-
* path that no plan loaded would read it as proof that one had.
|
|
75
|
+
* `scopes` holds what a plan recorded beneath a field execution: everything resolved beneath it was
|
|
76
|
+
* loaded by that plan, so it answers for all of it, and for nothing else. `rows` holds a mapping
|
|
77
|
+
* from a plan that loaded one row alone, and answers for that row only. A mapping carries the
|
|
78
|
+
* position a connection pages with, so a row answering from another row's mapping would page with
|
|
79
|
+
* arguments its own data was never fetched with. `rowScoped` stays false while nothing has been
|
|
80
|
+
* recorded there, so a request whose rows were all loaded the same way pays nothing for the row
|
|
81
|
+
* tier.
|
|
88
82
|
*
|
|
89
83
|
* `scopes` and `rows` are keyed by a field execution's place (see `placeOf`), which tells sibling
|
|
90
84
|
* rows apart, in weak maps: a `Map` holding every path link of a request tripled the time spent
|
|
91
85
|
* collecting garbage.
|
|
92
86
|
*/
|
|
93
87
|
interface Cache {
|
|
94
|
-
mappings: Map<string, Mapping>;
|
|
95
88
|
places: Map<string, object>;
|
|
96
|
-
rehomed: Map<string, Map<string, string>>;
|
|
97
89
|
rows: WeakMap<object, WeakMap<object, Map<string, Mapping>>>;
|
|
98
90
|
rowScoped: boolean;
|
|
99
91
|
scopes: WeakMap<object, Mappings>;
|
|
@@ -142,9 +134,7 @@ function cache(ctx: object, info: GraphQLResolveInfo): Cache {
|
|
|
142
134
|
|
|
143
135
|
if (!cached) {
|
|
144
136
|
cached = {
|
|
145
|
-
mappings: new Map(),
|
|
146
137
|
places: new Map(),
|
|
147
|
-
rehomed: new Map(),
|
|
148
138
|
rows: new WeakMap(),
|
|
149
139
|
rowScoped: false,
|
|
150
140
|
scopes: new WeakMap(),
|
|
@@ -180,8 +170,9 @@ function placeOf(cached: Cache, info: GraphQLResolveInfo, path: GraphQLResolveIn
|
|
|
180
170
|
/**
|
|
181
171
|
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
182
172
|
* every executor coerces afresh for each operation, so operations sharing a context never share
|
|
183
|
-
* an entry. The events of a subscription may share
|
|
184
|
-
* and `query` callbacks once for all of them
|
|
173
|
+
* an entry. The events of a subscription may share one, so a plan cached here runs its `select`
|
|
174
|
+
* and `query` callbacks once for all of them. Use `forExecution` if the callbacks read per-event
|
|
175
|
+
* state.
|
|
185
176
|
*/
|
|
186
177
|
export function forOperation<T>(
|
|
187
178
|
cache: WeakMap<object, Map<string, T>>,
|
|
@@ -191,9 +182,8 @@ export function forOperation<T>(
|
|
|
191
182
|
}
|
|
192
183
|
|
|
193
184
|
/**
|
|
194
|
-
* The entries of `cache` for the execution `info` is in
|
|
195
|
-
*
|
|
196
|
-
* execution's.
|
|
185
|
+
* The entries of `cache` for the execution `info` is in. Each event of a subscription gets its own
|
|
186
|
+
* entries, and `@defer` and `@stream` payloads share the entries of their execution.
|
|
197
187
|
*/
|
|
198
188
|
export function forExecution<T>(
|
|
199
189
|
cache: WeakMap<object, Map<string, T>>,
|
|
@@ -266,12 +256,12 @@ const fieldNodeIds = new WeakMap<object, number>();
|
|
|
266
256
|
let nextFieldNodeId = 0;
|
|
267
257
|
|
|
268
258
|
/**
|
|
269
|
-
* `cacheKey(type, info.path)`
|
|
270
|
-
*
|
|
271
|
-
* in turn and
|
|
272
|
-
*
|
|
273
|
-
* response path,
|
|
274
|
-
* something else.
|
|
259
|
+
* The key to cache a field's plan under: `cacheKey(type, info.path)` plus an id for each node in
|
|
260
|
+
* `info.fieldNodes`. The path leaves out list indices, so the items of a list share a plan. The
|
|
261
|
+
* root fields of a mutation run in turn, and a callback may read what an earlier field changed.
|
|
262
|
+
* Their paths differ, so each gets its own plan. The nodes are part of the key because fragments on
|
|
263
|
+
* different types can merge different nodes into one response path, and a plan keyed on the path
|
|
264
|
+
* alone would be reused for a field that selects something else.
|
|
275
265
|
*/
|
|
276
266
|
export function fieldKey(type: string, info: GraphQLResolveInfo): string {
|
|
277
267
|
let key = cacheKey(type, info.path);
|
|
@@ -290,56 +280,11 @@ export function fieldKey(type: string, info: GraphQLResolveInfo): string {
|
|
|
290
280
|
return key;
|
|
291
281
|
}
|
|
292
282
|
|
|
293
|
-
/**
|
|
294
|
-
* The keys `mappings` is recorded under when it is rehomed beneath `prefix`. Built once per
|
|
295
|
-
* prefix: the strings depend on the path and the plan's own keys, never on which row is being
|
|
296
|
-
* recorded for.
|
|
297
|
-
*/
|
|
298
|
-
function rehomedKeys(cached: Cache, prefix: string) {
|
|
299
|
-
let keys = cached.rehomed.get(prefix);
|
|
300
|
-
|
|
301
|
-
if (!keys) {
|
|
302
|
-
keys = new Map();
|
|
303
|
-
cached.rehomed.set(prefix, keys);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return keys;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** `key`, a plan's own `Type@relative.path`, moved beneath `prefix`. Built once per prefix. */
|
|
310
|
-
function rehome(keys: Map<string, string>, key: string, prefix: string) {
|
|
311
|
-
let under = keys.get(key);
|
|
312
|
-
|
|
313
|
-
if (under === undefined) {
|
|
314
|
-
const at = key.indexOf('@');
|
|
315
|
-
|
|
316
|
-
under = `${key.slice(0, at)}@${prefix}.${key.slice(at + 1)}`;
|
|
317
|
-
keys.set(key, under);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return under;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
283
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */
|
|
324
284
|
function ownerOf(row: unknown): object | null {
|
|
325
285
|
return typeof row === 'object' && row !== null ? row : null;
|
|
326
286
|
}
|
|
327
287
|
|
|
328
|
-
/**
|
|
329
|
-
* Records `mapping` at `key` for `row`. An unclaimed key takes it, and a key already holding this
|
|
330
|
-
* very mapping needs no write, so the rows after the first write nothing. Only a key two plans
|
|
331
|
-
* disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing.
|
|
332
|
-
*/
|
|
333
|
-
function claim(cached: Cache, key: string, mapping: Mapping, row: object | null, place: object) {
|
|
334
|
-
const held = cached.mappings.get(key);
|
|
335
|
-
|
|
336
|
-
if (held === undefined) {
|
|
337
|
-
cached.mappings.set(key, mapping);
|
|
338
|
-
} else if (held !== mapping && row) {
|
|
339
|
-
claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, place);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
288
|
/**
|
|
344
289
|
* Records `mapping` for this field execution against `row` alone.
|
|
345
290
|
*/
|
|
@@ -360,21 +305,15 @@ function claimForRow(cached: Cache, type: string, mapping: Mapping, row: object,
|
|
|
360
305
|
|
|
361
306
|
/**
|
|
362
307
|
* Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
|
|
363
|
-
* The plan loaded the whole field, so its mappings
|
|
308
|
+
* The plan loaded the whole field, so its mappings are used for everything resolved beneath this
|
|
364
309
|
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
365
310
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
366
311
|
*/
|
|
367
312
|
export function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings) {
|
|
368
313
|
const cached = cache(ctx, info);
|
|
369
|
-
const prefix = responsePath(info.path);
|
|
370
|
-
const keys = rehomedKeys(cached, prefix);
|
|
371
314
|
const place = placeOf(cached, info, info.path);
|
|
372
315
|
const previous = cached.scopes.get(place);
|
|
373
316
|
cached.scopes.set(place, previous ? { ...previous, ...mappings } : mappings);
|
|
374
|
-
|
|
375
|
-
for (const key of Object.keys(mappings)) {
|
|
376
|
-
cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
|
|
377
|
-
}
|
|
378
317
|
}
|
|
379
318
|
|
|
380
319
|
/**
|
|
@@ -389,28 +328,8 @@ export function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings:
|
|
|
389
328
|
}
|
|
390
329
|
|
|
391
330
|
/**
|
|
392
|
-
* Records
|
|
393
|
-
*
|
|
394
|
-
* themselves up. `row` is the value the field is about to resolve with: the parent row when it
|
|
395
|
-
* was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
|
|
396
|
-
*/
|
|
397
|
-
export function setFieldMapping(
|
|
398
|
-
ctx: object,
|
|
399
|
-
info: GraphQLResolveInfo,
|
|
400
|
-
mapping: Mapping,
|
|
401
|
-
row: unknown,
|
|
402
|
-
) {
|
|
403
|
-
const cached = cache(ctx, info);
|
|
404
|
-
const place = placeOf(cached, info, info.path);
|
|
405
|
-
|
|
406
|
-
claim(cached, cacheKey(info.parentType.name, info.path), mapping, ownerOf(row), place);
|
|
407
|
-
cached.scopes.set(place, mapping.nested);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
|
|
412
|
-
* against `row` rather than claimed for the whole field, so the field's lookup on `row` answers
|
|
413
|
-
* from it whatever the field's other rows were loaded with.
|
|
331
|
+
* Records a mapping for `row` only, for the field `info` resolves. Use it when the plan loaded
|
|
332
|
+
* `row` alone. The field's other rows don't use this mapping.
|
|
414
333
|
*
|
|
415
334
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
416
335
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
@@ -435,8 +354,9 @@ export function setRowFieldMapping(
|
|
|
435
354
|
/**
|
|
436
355
|
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
437
356
|
* row over the plan's. `row` is the value whose data the mapping describes — the resolver's
|
|
438
|
-
* parent. The plan's comes from the nearest field execution above
|
|
439
|
-
*
|
|
357
|
+
* parent. The plan's mapping comes from the nearest field execution above this one that recorded
|
|
358
|
+
* mappings. Returns `null` if there is none or it has no mapping for this field, even if a mapping
|
|
359
|
+
* was recorded for another row at the same path.
|
|
440
360
|
*/
|
|
441
361
|
export function getLoaderMapping(
|
|
442
362
|
ctx: object,
|