@pothos/selection-mapper 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +16 -6
  3. package/dts/deep-equal.d.ts +4 -0
  4. package/dts/deep-equal.d.ts.map +1 -1
  5. package/dts/errors.d.ts +7 -0
  6. package/dts/errors.d.ts.map +1 -0
  7. package/dts/index.d.ts +3 -2
  8. package/dts/index.d.ts.map +1 -1
  9. package/dts/loader-map.d.ts +37 -16
  10. package/dts/loader-map.d.ts.map +1 -1
  11. package/dts/matches.d.ts +5 -0
  12. package/dts/matches.d.ts.map +1 -1
  13. package/dts/parent-types.d.ts +9 -0
  14. package/dts/parent-types.d.ts.map +1 -0
  15. package/dts/plan.d.ts +36 -20
  16. package/dts/plan.d.ts.map +1 -1
  17. package/dts/shape.d.ts +8 -0
  18. package/dts/shape.d.ts.map +1 -0
  19. package/dts/types.d.ts +21 -1
  20. package/dts/types.d.ts.map +1 -1
  21. package/dts/walk.d.ts +20 -2
  22. package/dts/walk.d.ts.map +1 -1
  23. package/esm/deep-equal.d.ts +4 -0
  24. package/esm/deep-equal.d.ts.map +1 -1
  25. package/esm/deep-equal.js +60 -28
  26. package/esm/deep-equal.js.map +1 -1
  27. package/esm/errors.d.ts +7 -0
  28. package/esm/errors.d.ts.map +1 -0
  29. package/esm/errors.js +11 -0
  30. package/esm/errors.js.map +1 -0
  31. package/esm/index.d.ts +3 -2
  32. package/esm/index.d.ts.map +1 -1
  33. package/esm/index.js +2 -1
  34. package/esm/index.js.map +1 -1
  35. package/esm/loader-map.d.ts +37 -16
  36. package/esm/loader-map.d.ts.map +1 -1
  37. package/esm/loader-map.js +165 -99
  38. package/esm/loader-map.js.map +1 -1
  39. package/esm/matches.d.ts +5 -0
  40. package/esm/matches.d.ts.map +1 -1
  41. package/esm/matches.js +11 -3
  42. package/esm/matches.js.map +1 -1
  43. package/esm/parent-types.d.ts +9 -0
  44. package/esm/parent-types.d.ts.map +1 -0
  45. package/esm/parent-types.js +24 -0
  46. package/esm/parent-types.js.map +1 -0
  47. package/esm/plan.d.ts +36 -20
  48. package/esm/plan.d.ts.map +1 -1
  49. package/esm/plan.js +107 -71
  50. package/esm/plan.js.map +1 -1
  51. package/esm/shape.d.ts +8 -0
  52. package/esm/shape.d.ts.map +1 -0
  53. package/esm/shape.js +94 -0
  54. package/esm/shape.js.map +1 -0
  55. package/esm/types.d.ts +21 -1
  56. package/esm/types.d.ts.map +1 -1
  57. package/esm/types.js.map +1 -1
  58. package/esm/walk.d.ts +20 -2
  59. package/esm/walk.d.ts.map +1 -1
  60. package/esm/walk.js +199 -71
  61. package/esm/walk.js.map +1 -1
  62. package/lib/deep-equal.js +60 -28
  63. package/lib/deep-equal.js.map +1 -1
  64. package/lib/errors.js +18 -0
  65. package/lib/errors.js.map +1 -0
  66. package/lib/index.js +13 -3
  67. package/lib/index.js.map +1 -1
  68. package/lib/loader-map.js +145 -90
  69. package/lib/loader-map.js.map +1 -1
  70. package/lib/matches.js +14 -3
  71. package/lib/matches.js.map +1 -1
  72. package/lib/parent-types.js +29 -0
  73. package/lib/parent-types.js.map +1 -0
  74. package/lib/plan.js +107 -71
  75. package/lib/plan.js.map +1 -1
  76. package/lib/shape.js +109 -0
  77. package/lib/shape.js.map +1 -0
  78. package/lib/walk.js +186 -68
  79. package/lib/walk.js.map +1 -1
  80. package/package.json +4 -3
  81. package/src/deep-equal.ts +77 -34
  82. package/src/errors.ts +12 -0
  83. package/src/index.ts +6 -1
  84. package/src/loader-map.ts +235 -125
  85. package/src/matches.ts +15 -3
  86. package/src/parent-types.ts +33 -0
  87. package/src/plan.ts +145 -78
  88. package/src/shape.ts +126 -0
  89. package/src/types.ts +25 -1
  90. package/src/walk.ts +250 -83
package/esm/deep-equal.js CHANGED
@@ -2,49 +2,81 @@
2
2
  * Structural equality for query arguments (`where`, `orderBy`, `take`, ...). Keys holding
3
3
  * `undefined` are treated as absent, so `{ where: cond ? filter : undefined }` compares equal to
4
4
  * `{}` when the condition is false.
5
+ *
6
+ * Plain objects and arrays compare by value, and Dates by their time. Any other object (a Temporal
7
+ * value, a `Decimal`, a `Buffer`, a typed array) equals only an object of the same prototype that
8
+ * its `equals` method accepts, or itself when it has none.
5
9
  */ export function deepEqual(left, right) {
6
10
  if (left === right) {
7
11
  return true;
8
12
  }
9
- if (left && right && typeof left === 'object' && typeof right === 'object') {
10
- if (Array.isArray(left) || Array.isArray(right)) {
11
- if (!Array.isArray(left) || !Array.isArray(right)) {
12
- return false;
13
- }
14
- const { length } = left;
15
- if (right.length !== length) {
16
- return false;
17
- }
18
- for(let i = 0; i < length; i += 1){
19
- if (!deepEqual(left[i], right[i])) {
20
- return false;
21
- }
22
- }
23
- return true;
24
- }
25
- const lValue = left.valueOf?.();
26
- const rValue = right.valueOf?.();
27
- // A boxed value (a Date, a boxed primitive) compares by its primitive, whichever side it is
28
- // on: a plain object's `valueOf` returns the object itself, and a null-prototype object has
29
- // none at all, so neither is mistaken for one.
30
- if (lValue != null && typeof lValue !== 'object' || rValue != null && typeof rValue !== 'object') {
31
- return lValue === rValue;
13
+ if (!(left && right && typeof left === 'object' && typeof right === 'object')) {
14
+ return false;
15
+ }
16
+ if (Array.isArray(left) || Array.isArray(right)) {
17
+ if (!Array.isArray(left) || !Array.isArray(right)) {
18
+ return false;
32
19
  }
33
- const keys = comparedKeys(left);
34
- if (keys.length !== comparedKeys(right).length) {
20
+ const { length } = left;
21
+ if (right.length !== length) {
35
22
  return false;
36
23
  }
37
- for (const key of keys){
38
- if (!deepEqual(left[key], right[key])) {
24
+ for(let i = 0; i < length; i += 1){
25
+ if (!deepEqual(left[i], right[i])) {
39
26
  return false;
40
27
  }
41
28
  }
42
29
  return true;
43
30
  }
44
- return false;
31
+ // Two objects of `Object.prototype`, the common case, need no further check.
32
+ if (Object.getPrototypeOf(left) !== Object.prototype || Object.getPrototypeOf(right) !== Object.prototype) {
33
+ const leftPlain = isPlain(left);
34
+ if (leftPlain !== isPlain(right)) {
35
+ return false;
36
+ }
37
+ if (!leftPlain) {
38
+ return instancesEqual(left, right);
39
+ }
40
+ }
41
+ const keys = comparedKeys(left);
42
+ if (keys.length !== definedKeyCount(right)) {
43
+ return false;
44
+ }
45
+ for (const key of keys){
46
+ if (!deepEqual(left[key], right[key])) {
47
+ return false;
48
+ }
49
+ }
50
+ return true;
51
+ }
52
+ function isPlain(value) {
53
+ const proto = Object.getPrototypeOf(value);
54
+ return proto === null || proto === Object.prototype;
55
+ }
56
+ /**
57
+ * The shared prototype keeps the comparison symmetric, since Temporal's `equals` also accepts
58
+ * property bags and strings.
59
+ */ function instancesEqual(left, right) {
60
+ if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) {
61
+ return false;
62
+ }
63
+ if (left instanceof Date) {
64
+ return left.getTime() === right.getTime();
65
+ }
66
+ const { equals } = left;
67
+ return typeof equals === 'function' && equals.call(left, right) === true;
45
68
  }
46
69
  function comparedKeys(value) {
47
70
  return Object.keys(value).filter((key)=>value[key] !== undefined);
48
71
  }
72
+ function definedKeyCount(value) {
73
+ let count = 0;
74
+ for (const key of Object.keys(value)){
75
+ if (value[key] !== undefined) {
76
+ count += 1;
77
+ }
78
+ }
79
+ return count;
80
+ }
49
81
 
50
82
  //# sourceMappingURL=deep-equal.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deep-equal.ts"],"names":["deepEqual","left","right","Array","isArray","length","i","lValue","valueOf","rValue","keys","comparedKeys","key","value","Object","filter","undefined"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,UAAUC,IAAa,EAAEC,KAAc;IACrD,IAAID,SAASC,OAAO;QAClB,OAAO;IACT;IAEA,IAAID,QAAQC,SAAS,OAAOD,SAAS,YAAY,OAAOC,UAAU,UAAU;QAC1E,IAAIC,MAAMC,OAAO,CAACH,SAASE,MAAMC,OAAO,CAACF,QAAQ;YAC/C,IAAI,CAACC,MAAMC,OAAO,CAACH,SAAS,CAACE,MAAMC,OAAO,CAACF,QAAQ;gBACjD,OAAO;YACT;YAEA,MAAM,EAAEG,MAAM,EAAE,GAAGJ;YAEnB,IAAIC,MAAMG,MAAM,KAAKA,QAAQ;gBAC3B,OAAO;YACT;YAEA,IAAK,IAAIC,IAAI,GAAGA,IAAID,QAAQC,KAAK,EAAG;gBAClC,IAAI,CAACN,UAAUC,IAAI,CAACK,EAAE,EAAEJ,KAAK,CAACI,EAAE,GAAG;oBACjC,OAAO;gBACT;YACF;YAEA,OAAO;QACT;QAEA,MAAMC,SAASN,KAAKO,OAAO;QAC3B,MAAMC,SAASP,MAAMM,OAAO;QAE5B,4FAA4F;QAC5F,4FAA4F;QAC5F,+CAA+C;QAC/C,IACE,AAACD,UAAU,QAAQ,OAAOA,WAAW,YACpCE,UAAU,QAAQ,OAAOA,WAAW,UACrC;YACA,OAAOF,WAAWE;QACpB;QAEA,MAAMC,OAAOC,aAAaV;QAE1B,IAAIS,KAAKL,MAAM,KAAKM,aAAaT,OAAkCG,MAAM,EAAE;YACzE,OAAO;QACT;QAEA,KAAK,MAAMO,OAAOF,KAAM;YACtB,IACE,CAACV,UAAU,AAACC,IAAgC,CAACW,IAAI,EAAE,AAACV,KAAiC,CAACU,IAAI,GAC1F;gBACA,OAAO;YACT;QACF;QAEA,OAAO;IACT;IAEA,OAAO;AACT;AAEA,SAASD,aAAaE,KAA8B;IAClD,OAAOC,OAAOJ,IAAI,CAACG,OAAOE,MAAM,CAAC,CAACH,MAAQC,KAAK,CAACD,IAAI,KAAKI;AAC3D"}
1
+ {"version":3,"sources":["../src/deep-equal.ts"],"names":["deepEqual","left","right","Array","isArray","length","i","Object","getPrototypeOf","prototype","leftPlain","isPlain","instancesEqual","keys","comparedKeys","definedKeyCount","key","value","proto","Date","getTime","equals","call","filter","undefined","count"],"mappings":"AAAA;;;;;;;;CAQC,GACD,OAAO,SAASA,UAAUC,IAAa,EAAEC,KAAc;IACrD,IAAID,SAASC,OAAO;QAClB,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ACjD,IAAIK,OAAOC,cAAc,CAACP,UAAUM,OAAOC,cAAc,CAACN,QAAQ;QAChE,OAAO;IACT;IAEA,IAAID,gBAAgBkB,MAAM;QACxB,OAAOlB,KAAKmB,OAAO,OAAO,AAAClB,MAAekB,OAAO;IACnD;IAEA,MAAM,EAAEC,MAAM,EAAE,GAAGpB;IAEnB,OAAO,OAAOoB,WAAW,cAAcA,OAAOC,IAAI,CAACrB,MAAMC,WAAW;AACtE;AAEA,SAASY,aAAaG,KAA8B;IAClD,OAAOV,OAAOM,IAAI,CAACI,OAAOM,MAAM,CAAC,CAACP,MAAQC,KAAK,CAACD,IAAI,KAAKQ;AAC3D;AAEA,SAAST,gBAAgBE,KAA8B;IACrD,IAAIQ,QAAQ;IAEZ,KAAK,MAAMT,OAAOT,OAAOM,IAAI,CAACI,OAAQ;QACpC,IAAIA,KAAK,CAACD,IAAI,KAAKQ,WAAW;YAC5BC,SAAS;QACX;IACF;IAEA,OAAOA;AACT"}
@@ -0,0 +1,7 @@
1
+ import { PothosValidationError } from '@pothos/core';
2
+ /**
3
+ * An error raised while a request runs for a problem in the app's schema or code. Clients see only
4
+ * `Unexpected error.`; `detail` is the message of its `cause`, which responses leave out.
5
+ */
6
+ export declare function unexpectedError(detail: string): PothosValidationError;
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,yBAK7C"}
package/esm/errors.js ADDED
@@ -0,0 +1,11 @@
1
+ import { PothosValidationError } from '@pothos/core';
2
+ /**
3
+ * An error raised while a request runs for a problem in the app's schema or code. Clients see only
4
+ * `Unexpected error.`; `detail` is the message of its `cause`, which responses leave out.
5
+ */ export function unexpectedError(detail) {
6
+ const error = new PothosValidationError('Unexpected error.');
7
+ error.cause = new PothosValidationError(detail);
8
+ return error;
9
+ }
10
+
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"names":["PothosValidationError","unexpectedError","detail","error","cause"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,eAAe;AAErD;;;CAGC,GACD,OAAO,SAASC,gBAAgBC,MAAc;IAC5C,MAAMC,QAAQ,IAAIH,sBAAsB;IACxCG,MAAMC,KAAK,GAAG,IAAIJ,sBAAsBE;IAExC,OAAOC;AACT"}
package/esm/index.d.ts CHANGED
@@ -5,9 +5,10 @@
5
5
  */
6
6
  export { Adapter } from './adapter.js';
7
7
  export { deepEqual } from './deep-equal.js';
8
- export { cacheKey, getLoaderMapping, type Mappings, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
8
+ export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, type Mapping, type Mappings, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
9
9
  export { type IndirectInclude, type IndirectPathSegment, type PathSegment, selectedFieldNames, } from './matches.js';
10
10
  export { type Node, NodeAdapter, type QueryVisitor } from './node.js';
11
+ export { mappingParentTypes } from './parent-types.js';
11
12
  export { Plan, type PlayedPlan } from './plan.js';
12
- export type { MergeOptions, NestedSelection, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
13
+ export type { MergeOptions, NestedSelection, ParentRowOptions, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,QAAQ,EACb,e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js CHANGED
@@ -4,9 +4,10 @@
4
4
  * adapters and loaders call. Everything else is module-private; see the README.
5
5
  */ export { Adapter } from './adapter.js';
6
6
  export { deepEqual } from './deep-equal.js';
7
- export { cacheKey, getLoaderMapping, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
7
+ export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
8
8
  export { selectedFieldNames } from './matches.js';
9
9
  export { NodeAdapter } from './node.js';
10
+ export { mappingParentTypes } from './parent-types.js';
10
11
  export { Plan } from './plan.js';
11
12
 
12
13
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","getLoaderMapping","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","selectedFieldNames","NodeAdapter","Plan"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACEC,QAAQ,EACRC,gBAAgB,EAEhBC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,QACT,kBAAkB;AACzB,SAIEC,kBAAkB,QACb,eAAe;AACtB,SAAoBC,WAAW,QAA2B,YAAY;AACtE,SAASC,IAAI,QAAyB,YAAY"}
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"}
@@ -21,43 +21,64 @@ export declare const EMPTY_MAPPING: Mapping;
21
21
  /**
22
22
  * Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
23
23
  * mapping is never changed after the fact (two plays may accept a different subset of the fields).
24
+ *
25
+ * Invocations of one field share what is beneath them (see `Plan.nested`), so a mapping is a DAG
26
+ * whose keys can all lead to one mapping. A pair is unioned once however many keys lead to it, or
27
+ * the union would take as long as the DAG written out as a tree.
24
28
  */
25
29
  export declare function unionMappings(into: Mapping | undefined, from: Mapping): Mapping;
30
+ /**
31
+ * The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
32
+ * every executor coerces afresh for each operation, so operations sharing a context never share
33
+ * an entry. The events of a subscription may share 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.
36
+ */
37
+ export declare function forOperation<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
38
+ /**
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
+ */
42
+ export declare function forExecution<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
26
43
  /** The string keys of a response path joined by `.`; list indices are dropped. */
27
44
  export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
28
45
  export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
46
+ /**
47
+ * 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
+ */
54
+ export declare function fieldKey(type: string, info: GraphQLResolveInfo): string;
29
55
  /**
30
56
  * Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
31
- * The plan loaded the whole field, so its mappings answer for every row of it: they go to the
32
- * shared tier. Multiple plans can contribute to one field (Relay nodes of different model
57
+ * The plan loaded the whole field, so its mappings are used for everything resolved beneath this
58
+ * execution of it. Multiple plans can contribute to one field (Relay nodes of different model
33
59
  * types share the list's path), so later contributions replace matching keys and retain others.
34
60
  */
35
61
  export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
36
62
  /**
37
63
  * Records a row's mappings and scopes its descendants to this concrete field execution. A
38
64
  * descendant's parent is a different object, so row identity alone cannot carry its plan through
39
- * a relation, connection wrapper, or list. The execution path retains indices to isolate siblings.
65
+ * a relation, connection wrapper, or list. The place keeps list indices to isolate siblings.
40
66
  */
41
67
  export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
42
68
  /**
43
- * Records the mapping of the field `info` resolves (under its own parent type) along with the
44
- * mappings beneath it, so both the field's resolver and the resolvers below it can look
45
- * themselves up. `row` is the value the field is about to resolve with: the parent row when it
46
- * was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
47
- */
48
- export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
49
- /**
50
- * `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
51
- * against `row` rather than claimed for the whole field, so a sibling row the plan never loaded
52
- * keeps falling back instead of reading the entry and resolving against data it does not carry.
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.
53
71
  *
54
72
  * Descendants inherit the mapping through this field's execution scope, even when their parent
55
73
  * is a child object or a connection wrapper rather than the row that was reloaded.
56
74
  */
57
75
  export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
58
76
  /**
59
- * The mapping recorded for the field at `path` on `row`, preferring one recorded for that row
60
- * over the plan's. `row` is the value whose data the mapping describes — the resolver's parent.
77
+ * The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
78
+ * row over the plan's. `row` is the value whose data the mapping describes — the resolver's
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.
61
82
  */
62
- export declare function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path'], type: string, row?: unknown): Mapping | null;
83
+ export declare function getLoaderMapping(ctx: object, info: GraphQLResolveInfo, type: string, row?: unknown): Mapping | null;
63
84
  //# sourceMappingURL=loader-map.d.ts.map
@@ -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;AAE/F;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAY/E;AAgCD,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,CAgBjF;AAED,wBAAgB,QAAQ,CAAC,IAA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