@pothos/selection-mapper 0.2.0 → 0.3.1
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 +12 -0
- package/README.md +9 -8
- 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 +21 -74
- 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 +4 -55
- package/lib/loader-map.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +0 -1
- package/src/loader-map.ts +29 -113
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @pothos/selection-mapper
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3f99569: Fix relations being reloaded for every row under graphql-yoga with graphql 17 (`@graphql-tools/executor` 2). Loader mappings were keyed on `info.getAbortSignal`, which that executor builds anew for every resolver, so no resolver found the mapping its parent recorded. Executions are now told apart by the root link of their path under every executor that shares path links, and by their `variableValues` under graphql-jit. This affects plugin-prisma, plugin-drizzle and plugin-prisma-next.
|
|
8
|
+
|
|
9
|
+
## 0.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- b9fd6f2: Remove the `setFieldMapping` export, which no Pothos plugin uses any more.
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
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
|
|
|
@@ -85,10 +84,12 @@ extends `Adapter` directly.
|
|
|
85
84
|
this package and could only be copied by round-tripping it through the adapter on every field.
|
|
86
85
|
- Every play records its loader mappings on the request context, which pothos requires to be an
|
|
87
86
|
object, per execution: operations and subscription events sharing a context don't see each
|
|
88
|
-
other's. An execution is told apart by the
|
|
89
|
-
|
|
90
|
-
field has a path chain, and so a cache, of its own, which is enough
|
|
91
|
-
read beneath the root field that recorded it.
|
|
87
|
+
other's. An execution is told apart by the root link of its path under graphql-js and
|
|
88
|
+
`@graphql-tools/executor` (Yoga), which build a path chain for each execution and subscription
|
|
89
|
+
event. There each root field has a path chain, and so a cache, of its own, which is enough
|
|
90
|
+
because a mapping is only read beneath the root field that recorded it. `getAbortSignal` can't
|
|
91
|
+
tell executions apart: `@graphql-tools/executor` 2 builds a new one for every resolver, and the
|
|
92
|
+
signal it returns is the caller's, shared by every event of a subscription. Under graphql-jit, which builds a new path for
|
|
92
93
|
every resolver, it is told apart by its `variableValues`, coerced afresh for each execution and
|
|
93
94
|
event. The plugins pass `getLoaderMapping` the resolver's `info`. An adapter whose resolvers
|
|
94
95
|
read a loaded row another way simply never looks them up.
|
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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,EAAE,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,UAEtE;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,IAA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AAE,kBAAkB,EACxB,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,OAAO,GACZ,OAAO,GAAG,IAAI,CA+BhB"}
|
package/esm/loader-map.js
CHANGED
|
@@ -46,19 +46,17 @@ import { createContextCache } from '@pothos/core';
|
|
|
46
46
|
* An object the executor builds once per execution, and once per event of a subscription, and
|
|
47
47
|
* hands to every resolver in it, @defer and @stream payloads included:
|
|
48
48
|
*
|
|
49
|
-
* - graphql-js 17: the
|
|
50
|
-
* - graphql-js 16 and @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
49
|
+
* - graphql-js 16 and 17, @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
51
50
|
* path chain per execution or event, linking each field to its parent's, so every resolver
|
|
52
51
|
* beneath a root field shares its link, and the `subscribe` resolver has its own. Their fields'
|
|
53
52
|
* links carry a `typename`. A root field doesn't share its link with the others, so each root
|
|
54
53
|
* field has a cache of its own, which is all it reads.
|
|
55
54
|
* - graphql-jit: the coerced `variableValues`. It builds a new path, without `typename`, for every
|
|
56
55
|
* resolver, but coerces the variables afresh for every execution and event.
|
|
56
|
+
*
|
|
57
|
+
* Not `info.getAbortSignal`: @graphql-tools/executor 2 builds a new getter for every resolver, and
|
|
58
|
+
* the signal it returns is the caller's, absent or shared by every event of a subscription.
|
|
57
59
|
*/ function executionOf(info) {
|
|
58
|
-
const signal = info.getAbortSignal;
|
|
59
|
-
if (signal) {
|
|
60
|
-
return signal;
|
|
61
|
-
}
|
|
62
60
|
let { path } = info;
|
|
63
61
|
if (path.typename === undefined) {
|
|
64
62
|
return info.variableValues;
|
|
@@ -74,9 +72,7 @@ function cache(ctx, info) {
|
|
|
74
72
|
let cached = executions.get(execution);
|
|
75
73
|
if (!cached) {
|
|
76
74
|
cached = {
|
|
77
|
-
mappings: new Map(),
|
|
78
75
|
places: new Map(),
|
|
79
|
-
rehomed: new Map(),
|
|
80
76
|
rows: new WeakMap(),
|
|
81
77
|
rowScoped: false,
|
|
82
78
|
scopes: new WeakMap()
|
|
@@ -105,15 +101,15 @@ function cache(ctx, info) {
|
|
|
105
101
|
/**
|
|
106
102
|
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
107
103
|
* 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
|
|
104
|
+
* an entry. The events of a subscription may share one, so a plan cached here runs its `select`
|
|
105
|
+
* and `query` callbacks once for all of them. Use `forExecution` if the callbacks read per-event
|
|
106
|
+
* state.
|
|
110
107
|
*/ export function forOperation(cache, info) {
|
|
111
108
|
return entriesFor(cache, info.variableValues);
|
|
112
109
|
}
|
|
113
110
|
/**
|
|
114
|
-
* The entries of `cache` for the execution `info` is in
|
|
115
|
-
*
|
|
116
|
-
* execution's.
|
|
111
|
+
* The entries of `cache` for the execution `info` is in. Each event of a subscription gets its own
|
|
112
|
+
* entries, and `@defer` and `@stream` payloads share the entries of their execution.
|
|
117
113
|
*/ export function forExecution(cache, info) {
|
|
118
114
|
return entriesFor(cache, executionOf(info));
|
|
119
115
|
}
|
|
@@ -161,12 +157,12 @@ export function cacheKey(type, path) {
|
|
|
161
157
|
/** A number for each field node seen, by identity. Weak, so the nodes go with their document. */ const fieldNodeIds = new WeakMap();
|
|
162
158
|
let nextFieldNodeId = 0;
|
|
163
159
|
/**
|
|
164
|
-
* `cacheKey(type, info.path)`
|
|
165
|
-
*
|
|
166
|
-
* in turn and
|
|
167
|
-
*
|
|
168
|
-
* response path,
|
|
169
|
-
* something else.
|
|
160
|
+
* The key to cache a field's plan under: `cacheKey(type, info.path)` plus an id for each node in
|
|
161
|
+
* `info.fieldNodes`. The path leaves out list indices, so the items of a list share a plan. The
|
|
162
|
+
* root fields of a mutation run in turn, and a callback may read what an earlier field changed.
|
|
163
|
+
* Their paths differ, so each gets its own plan. The nodes are part of the key because fragments on
|
|
164
|
+
* different types can merge different nodes into one response path, and a plan keyed on the path
|
|
165
|
+
* alone would be reused for a field that selects something else.
|
|
170
166
|
*/ export function fieldKey(type, info) {
|
|
171
167
|
let key = cacheKey(type, info.path);
|
|
172
168
|
for (const node of info.fieldNodes){
|
|
@@ -179,42 +175,9 @@ let nextFieldNodeId = 0;
|
|
|
179
175
|
}
|
|
180
176
|
return key;
|
|
181
177
|
}
|
|
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
178
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */ function ownerOf(row) {
|
|
204
179
|
return typeof row === 'object' && row !== null ? row : null;
|
|
205
180
|
}
|
|
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
181
|
/**
|
|
219
182
|
* Records `mapping` for this field execution against `row` alone.
|
|
220
183
|
*/ function claimForRow(cached, type, mapping, row, place) {
|
|
@@ -233,22 +196,17 @@ let nextFieldNodeId = 0;
|
|
|
233
196
|
}
|
|
234
197
|
/**
|
|
235
198
|
* 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
|
|
199
|
+
* The plan loaded the whole field, so its mappings are used for everything resolved beneath this
|
|
237
200
|
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
238
201
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
239
202
|
*/ export function setLoaderMappings(ctx, info, mappings) {
|
|
240
203
|
const cached = cache(ctx, info);
|
|
241
|
-
const prefix = responsePath(info.path);
|
|
242
|
-
const keys = rehomedKeys(cached, prefix);
|
|
243
204
|
const place = placeOf(cached, info, info.path);
|
|
244
205
|
const previous = cached.scopes.get(place);
|
|
245
206
|
cached.scopes.set(place, previous ? {
|
|
246
207
|
...previous,
|
|
247
208
|
...mappings
|
|
248
209
|
} : mappings);
|
|
249
|
-
for (const key of Object.keys(mappings)){
|
|
250
|
-
cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
|
|
251
|
-
}
|
|
252
210
|
}
|
|
253
211
|
/**
|
|
254
212
|
* Records a row's mappings and scopes its descendants to this concrete field execution. A
|
|
@@ -259,20 +217,8 @@ let nextFieldNodeId = 0;
|
|
|
259
217
|
cached.scopes.set(placeOf(cached, info, info.path), mappings);
|
|
260
218
|
}
|
|
261
219
|
/**
|
|
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.
|
|
220
|
+
* Records a mapping for `row` only, for the field `info` resolves. Use it when the plan loaded
|
|
221
|
+
* `row` alone. The field's other rows don't use this mapping.
|
|
276
222
|
*
|
|
277
223
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
278
224
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
@@ -288,8 +234,9 @@ let nextFieldNodeId = 0;
|
|
|
288
234
|
/**
|
|
289
235
|
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
290
236
|
* 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
|
-
*
|
|
237
|
+
* parent. The plan's mapping comes from the nearest field execution above this one that recorded
|
|
238
|
+
* mappings. Returns `null` if there is none or it has no mapping for this field, even if a mapping
|
|
239
|
+
* was recorded for another row at the same path.
|
|
293
240
|
*/ export function getLoaderMapping(ctx, info, type, row) {
|
|
294
241
|
const { path } = info;
|
|
295
242
|
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","
|
|
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","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,MAAME;IACnB;IAEA,MAAMG,QAAQH,OAAOC,GAAG,CAACF;IAEzB,IAAII,OAAO;QACT,OAAOA;IACT;IAEA,MAAMT,SAAmB;QAAE,GAAGI,KAAKJ,MAAM;IAAC;IAE1C,KAAK,MAAMU,OAAOZ,OAAOa,IAAI,CAACN,KAAKL,MAAM,EAAG;QAC1CA,MAAM,CAACU,IAAI,GAAGP,cAAcH,MAAM,CAACU,IAAI,EAAEL,KAAKL,MAAM,CAACU,IAAI;IAC3D;IAEA,MAAME,QAAQR,KAAKS,QAAQ,KAAKC,YAAY;QAAEd;IAAO,IAAI;QAA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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
|
},
|
|
@@ -87,19 +84,17 @@ function unionMappings(into, from) {
|
|
|
87
84
|
* An object the executor builds once per execution, and once per event of a subscription, and
|
|
88
85
|
* hands to every resolver in it, @defer and @stream payloads included:
|
|
89
86
|
*
|
|
90
|
-
* - graphql-js 17: the
|
|
91
|
-
* - graphql-js 16 and @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
87
|
+
* - graphql-js 16 and 17, @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
92
88
|
* path chain per execution or event, linking each field to its parent's, so every resolver
|
|
93
89
|
* beneath a root field shares its link, and the `subscribe` resolver has its own. Their fields'
|
|
94
90
|
* links carry a `typename`. A root field doesn't share its link with the others, so each root
|
|
95
91
|
* field has a cache of its own, which is all it reads.
|
|
96
92
|
* - graphql-jit: the coerced `variableValues`. It builds a new path, without `typename`, for every
|
|
97
93
|
* resolver, but coerces the variables afresh for every execution and event.
|
|
94
|
+
*
|
|
95
|
+
* Not `info.getAbortSignal`: @graphql-tools/executor 2 builds a new getter for every resolver, and
|
|
96
|
+
* the signal it returns is the caller's, absent or shared by every event of a subscription.
|
|
98
97
|
*/ function executionOf(info) {
|
|
99
|
-
const signal = info.getAbortSignal;
|
|
100
|
-
if (signal) {
|
|
101
|
-
return signal;
|
|
102
|
-
}
|
|
103
98
|
let { path } = info;
|
|
104
99
|
if (path.typename === undefined) {
|
|
105
100
|
return info.variableValues;
|
|
@@ -115,9 +110,7 @@ function cache(ctx, info) {
|
|
|
115
110
|
let cached = executions.get(execution);
|
|
116
111
|
if (!cached) {
|
|
117
112
|
cached = {
|
|
118
|
-
mappings: new Map(),
|
|
119
113
|
places: new Map(),
|
|
120
|
-
rehomed: new Map(),
|
|
121
114
|
rows: new WeakMap(),
|
|
122
115
|
rowScoped: false,
|
|
123
116
|
scopes: new WeakMap()
|
|
@@ -204,42 +197,9 @@ function fieldKey(type, info) {
|
|
|
204
197
|
}
|
|
205
198
|
return key;
|
|
206
199
|
}
|
|
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
200
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */ function ownerOf(row) {
|
|
229
201
|
return typeof row === 'object' && row !== null ? row : null;
|
|
230
202
|
}
|
|
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
203
|
/**
|
|
244
204
|
* Records `mapping` for this field execution against `row` alone.
|
|
245
205
|
*/ function claimForRow(cached, type, mapping, row, place) {
|
|
@@ -258,28 +218,17 @@ function fieldKey(type, info) {
|
|
|
258
218
|
}
|
|
259
219
|
function setLoaderMappings(ctx, info, mappings) {
|
|
260
220
|
const cached = cache(ctx, info);
|
|
261
|
-
const prefix = responsePath(info.path);
|
|
262
|
-
const keys = rehomedKeys(cached, prefix);
|
|
263
221
|
const place = placeOf(cached, info, info.path);
|
|
264
222
|
const previous = cached.scopes.get(place);
|
|
265
223
|
cached.scopes.set(place, previous ? {
|
|
266
224
|
...previous,
|
|
267
225
|
...mappings
|
|
268
226
|
} : mappings);
|
|
269
|
-
for (const key of Object.keys(mappings)){
|
|
270
|
-
cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
|
|
271
|
-
}
|
|
272
227
|
}
|
|
273
228
|
function setRowMappings(ctx, info, mappings) {
|
|
274
229
|
const cached = cache(ctx, info);
|
|
275
230
|
cached.scopes.set(placeOf(cached, info, info.path), mappings);
|
|
276
231
|
}
|
|
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
232
|
function setRowFieldMapping(ctx, info, mapping, row) {
|
|
284
233
|
const cached = cache(ctx, info);
|
|
285
234
|
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","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;;QA8NGC;eAAAA;;QAgBAC;eAAAA;;QA9EAC;eAAAA;;QAXAC;eAAAA;;QAwLAC;eAAAA;;QAnJAC;eAAAA;;QAkGAC;eAAAA;;QAyBAC;eAAAA;;QAbAC;eAAAA;;QA3RAC;eAAAA;;;sBApCmB;AAuB5B,MAAMV,gBAAyBW,OAAOC,MAAM,CAAC;IAAEC,QAAQF,OAAOC,MAAM,CAAC,CAAC;AAAe;AAE5F,6FAA6F,GAC7F,MAAME,SAAS,IAAIC;AAUZ,SAASL,cAAcM,IAAyB,EAAEC,IAAa;IACpE,IAAI,CAACD,QAAQA,SAAShB,eAAe;QACnC,OAAOiB;IACT;IAEA,IAAID,SAASC,QAAQA,SAASjB,eAAe;QAC3C,OAAOgB;IACT;IAEA,IAAIE,SAASJ,OAAOK,GAAG,CAACH;IAExB,IAAI,CAACE,QAAQ;QACXA,SAAS,IAAIH;QACbD,OAAOM,GAAG,CAACJ,MAAME;IACnB;IAEA,MAAMG,QAAQH,OAAOC,GAAG,CAACF;IAEzB,IAAII,OAAO;QACT,OAAOA;IACT;IAEA,MAAMR,SAAmB;QAAE,GAAGG,KAAKH,MAAM;IAAC;IAE1C,KAAK,MAAMS,OAAOX,OAAOY,IAAI,CAACN,KAAKJ,MAAM,EAAG;QAC1CA,MAAM,CAACS,IAAI,GAAGZ,cAAcG,MAAM,CAACS,IAAI,EAAEL,KAAKJ,MAAM,CAACS,IAAI;IAC3D;IAEA,MAAME,QAAQR,KAAKS,QAAQ,KAAKC,YAAY;QAAEb;IAAO,IAAI;QAAEA;QAAQY,UAAUT,KAAKS,QAAQ;IAAC;IAE3FP,OAAOE,GAAG,CAACH,MAAMO;IAEjB,OAAOA;AACT;AAwBA,gEAAgE,GAChE,MAAMG,gBAAgB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AAwB,EACxBkC,OAAgB,EAChBF,GAAY;IAEZ,MAAMvB,SAASJ,MAAMC,KAAKN;IAC1B,MAAMuC,QAAQR,QAAQC;IACtB,MAAMd,QAAQH,QAAQN,QAAQT,MAAMA,KAAKC,IAAI;IAE7C,IAAIsC,OAAO;QACTN,YAAYxB,QAAQT,KAAKwC,UAAU,CAACC,IAAI,EAAEP,SAASK,OAAOrB;IAC5D;IAEAT,OAAOK,MAAM,CAACxB,GAAG,CAAC4B,OAAOgB,QAAQnD,MAAM;AACzC;AASO,SAASR,iBACd+B,GAAW,EACXN,IAAwB,EACxByB,IAAY,EACZO,GAAa;IAEb,MAAM,EAAE/B,IAAI,EAAE,GAAGD;IACjB,MAAMS,SAASJ,MAAMC,KAAKN;IAE1B,IAAIS,OAAOI,SAAS,EAAE;QACpB,MAAM0B,QAAQR,QAAQC;QACtB,MAAMI,MACJG,SACA9B,OAAOG,IAAI,CACRvB,GAAG,CAACkD,QACHlD,IAAI0B,QAAQN,QAAQT,MAAMC,QAC1BZ,IAAIoC;QAEV,IAAIW,KAAK;YACP,OAAOA;QACT;IACF;IAEA,IAAK,IAAIM,WAAWzC,KAAKG,IAAI,EAAEsC,UAAUA,WAAWA,SAAStC,IAAI,CAAE;QACjE,MAAMuC,QAAQlC,OAAOK,MAAM,CAACzB,GAAG,CAAC0B,QAAQN,QAAQT,MAAM0C;QAEtD,IAAIC,OAAO;YACT,wFAAwF;YACxF,0CAA0C;YAC1C,OACEA,KAAK,CAAC,GAAGlB,KAAK,CAAC,EAAEjD,aAAayB,MAAM2C,KAAK,CAACpE,aAAakE,UAAUG,MAAM,GAAG,IAAI,CAAC,IAAI;QAEvF;IACF;IAEA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pothos/selection-mapper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "shared selection-to-query walker for Pothos ORM plugins",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dts/index.d.ts",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"graphql": "^16.10.0 || ^17.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@graphql-tools/executor": "^
|
|
40
|
+
"@graphql-tools/executor": "^2.0.1",
|
|
41
41
|
"graphql": "^17.0.1",
|
|
42
42
|
"graphql-tag": "^2.12.6",
|
|
43
43
|
"vitest": "^4.1.4",
|
|
44
|
-
"@pothos/core": "4.
|
|
44
|
+
"@pothos/core": "4.18.1",
|
|
45
45
|
"@pothos/test-utils": "2.3.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
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>;
|
|
@@ -106,22 +98,18 @@ const contextCaches = createContextCache(() => new WeakMap<object, Cache>());
|
|
|
106
98
|
* An object the executor builds once per execution, and once per event of a subscription, and
|
|
107
99
|
* hands to every resolver in it, @defer and @stream payloads included:
|
|
108
100
|
*
|
|
109
|
-
* - graphql-js 17: the
|
|
110
|
-
* - graphql-js 16 and @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
101
|
+
* - graphql-js 16 and 17, @graphql-tools/executor (Yoga): the root link of the path. They build one
|
|
111
102
|
* path chain per execution or event, linking each field to its parent's, so every resolver
|
|
112
103
|
* beneath a root field shares its link, and the `subscribe` resolver has its own. Their fields'
|
|
113
104
|
* links carry a `typename`. A root field doesn't share its link with the others, so each root
|
|
114
105
|
* field has a cache of its own, which is all it reads.
|
|
115
106
|
* - graphql-jit: the coerced `variableValues`. It builds a new path, without `typename`, for every
|
|
116
107
|
* resolver, but coerces the variables afresh for every execution and event.
|
|
108
|
+
*
|
|
109
|
+
* Not `info.getAbortSignal`: @graphql-tools/executor 2 builds a new getter for every resolver, and
|
|
110
|
+
* the signal it returns is the caller's, absent or shared by every event of a subscription.
|
|
117
111
|
*/
|
|
118
112
|
function executionOf(info: GraphQLResolveInfo): object {
|
|
119
|
-
const signal = (info as { getAbortSignal?: object }).getAbortSignal;
|
|
120
|
-
|
|
121
|
-
if (signal) {
|
|
122
|
-
return signal;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
113
|
let { path } = info;
|
|
126
114
|
|
|
127
115
|
if (path.typename === undefined) {
|
|
@@ -142,9 +130,7 @@ function cache(ctx: object, info: GraphQLResolveInfo): Cache {
|
|
|
142
130
|
|
|
143
131
|
if (!cached) {
|
|
144
132
|
cached = {
|
|
145
|
-
mappings: new Map(),
|
|
146
133
|
places: new Map(),
|
|
147
|
-
rehomed: new Map(),
|
|
148
134
|
rows: new WeakMap(),
|
|
149
135
|
rowScoped: false,
|
|
150
136
|
scopes: new WeakMap(),
|
|
@@ -180,8 +166,9 @@ function placeOf(cached: Cache, info: GraphQLResolveInfo, path: GraphQLResolveIn
|
|
|
180
166
|
/**
|
|
181
167
|
* The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
|
|
182
168
|
* 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
|
|
169
|
+
* an entry. The events of a subscription may share one, so a plan cached here runs its `select`
|
|
170
|
+
* and `query` callbacks once for all of them. Use `forExecution` if the callbacks read per-event
|
|
171
|
+
* state.
|
|
185
172
|
*/
|
|
186
173
|
export function forOperation<T>(
|
|
187
174
|
cache: WeakMap<object, Map<string, T>>,
|
|
@@ -191,9 +178,8 @@ export function forOperation<T>(
|
|
|
191
178
|
}
|
|
192
179
|
|
|
193
180
|
/**
|
|
194
|
-
* The entries of `cache` for the execution `info` is in
|
|
195
|
-
*
|
|
196
|
-
* execution's.
|
|
181
|
+
* The entries of `cache` for the execution `info` is in. Each event of a subscription gets its own
|
|
182
|
+
* entries, and `@defer` and `@stream` payloads share the entries of their execution.
|
|
197
183
|
*/
|
|
198
184
|
export function forExecution<T>(
|
|
199
185
|
cache: WeakMap<object, Map<string, T>>,
|
|
@@ -266,12 +252,12 @@ const fieldNodeIds = new WeakMap<object, number>();
|
|
|
266
252
|
let nextFieldNodeId = 0;
|
|
267
253
|
|
|
268
254
|
/**
|
|
269
|
-
* `cacheKey(type, info.path)`
|
|
270
|
-
*
|
|
271
|
-
* in turn and
|
|
272
|
-
*
|
|
273
|
-
* response path,
|
|
274
|
-
* something else.
|
|
255
|
+
* The key to cache a field's plan under: `cacheKey(type, info.path)` plus an id for each node in
|
|
256
|
+
* `info.fieldNodes`. The path leaves out list indices, so the items of a list share a plan. The
|
|
257
|
+
* root fields of a mutation run in turn, and a callback may read what an earlier field changed.
|
|
258
|
+
* Their paths differ, so each gets its own plan. The nodes are part of the key because fragments on
|
|
259
|
+
* different types can merge different nodes into one response path, and a plan keyed on the path
|
|
260
|
+
* alone would be reused for a field that selects something else.
|
|
275
261
|
*/
|
|
276
262
|
export function fieldKey(type: string, info: GraphQLResolveInfo): string {
|
|
277
263
|
let key = cacheKey(type, info.path);
|
|
@@ -290,56 +276,11 @@ export function fieldKey(type: string, info: GraphQLResolveInfo): string {
|
|
|
290
276
|
return key;
|
|
291
277
|
}
|
|
292
278
|
|
|
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
279
|
/** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */
|
|
324
280
|
function ownerOf(row: unknown): object | null {
|
|
325
281
|
return typeof row === 'object' && row !== null ? row : null;
|
|
326
282
|
}
|
|
327
283
|
|
|
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
284
|
/**
|
|
344
285
|
* Records `mapping` for this field execution against `row` alone.
|
|
345
286
|
*/
|
|
@@ -360,21 +301,15 @@ function claimForRow(cached: Cache, type: string, mapping: Mapping, row: object,
|
|
|
360
301
|
|
|
361
302
|
/**
|
|
362
303
|
* 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
|
|
304
|
+
* The plan loaded the whole field, so its mappings are used for everything resolved beneath this
|
|
364
305
|
* execution of it. Multiple plans can contribute to one field (Relay nodes of different model
|
|
365
306
|
* types share the list's path), so later contributions replace matching keys and retain others.
|
|
366
307
|
*/
|
|
367
308
|
export function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings) {
|
|
368
309
|
const cached = cache(ctx, info);
|
|
369
|
-
const prefix = responsePath(info.path);
|
|
370
|
-
const keys = rehomedKeys(cached, prefix);
|
|
371
310
|
const place = placeOf(cached, info, info.path);
|
|
372
311
|
const previous = cached.scopes.get(place);
|
|
373
312
|
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
313
|
}
|
|
379
314
|
|
|
380
315
|
/**
|
|
@@ -389,28 +324,8 @@ export function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings:
|
|
|
389
324
|
}
|
|
390
325
|
|
|
391
326
|
/**
|
|
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.
|
|
327
|
+
* Records a mapping for `row` only, for the field `info` resolves. Use it when the plan loaded
|
|
328
|
+
* `row` alone. The field's other rows don't use this mapping.
|
|
414
329
|
*
|
|
415
330
|
* Descendants inherit the mapping through this field's execution scope, even when their parent
|
|
416
331
|
* is a child object or a connection wrapper rather than the row that was reloaded.
|
|
@@ -435,8 +350,9 @@ export function setRowFieldMapping(
|
|
|
435
350
|
/**
|
|
436
351
|
* The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
|
|
437
352
|
* 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
|
-
*
|
|
353
|
+
* parent. The plan's mapping comes from the nearest field execution above this one that recorded
|
|
354
|
+
* mappings. Returns `null` if there is none or it has no mapping for this field, even if a mapping
|
|
355
|
+
* was recorded for another row at the same path.
|
|
440
356
|
*/
|
|
441
357
|
export function getLoaderMapping(
|
|
442
358
|
ctx: object,
|