@pothos/selection-mapper 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +17 -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 +36 -8
  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 +36 -8
  36. package/esm/loader-map.d.ts.map +1 -1
  37. package/esm/loader-map.js +177 -60
  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 -0
  67. package/lib/index.js.map +1 -1
  68. package/lib/loader-map.js +157 -53
  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 -0
  84. package/src/loader-map.ts +261 -71
  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, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
9
9
  export { type IndirectInclude, type IndirectPathSegment, type PathSegment, selectedFieldNames, } from './matches.js';
10
10
  export { type Node, NodeAdapter, type QueryVisitor } from './node.js';
11
+ export { mappingParentTypes } from './parent-types.js';
11
12
  export { Plan, type PlayedPlan } from './plan.js';
12
- export type { MergeOptions, NestedSelection, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
13
+ export type { MergeOptions, NestedSelection, ParentRowOptions, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -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,QAA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AY,CAAC"}
package/esm/index.js CHANGED
@@ -4,9 +4,10 @@
4
4
  * adapters and loaders call. Everything else is module-private; see the README.
5
5
  */ export { Adapter } from './adapter.js';
6
6
  export { deepEqual } from './deep-equal.js';
7
- export { cacheKey, getLoaderMapping, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
7
+ export { cacheKey, fieldKey, forExecution, forOperation, getLoaderMapping, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
8
8
  export { selectedFieldNames } from './matches.js';
9
9
  export { NodeAdapter } from './node.js';
10
+ export { mappingParentTypes } from './parent-types.js';
10
11
  export { Plan } from './plan.js';
11
12
 
12
13
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","getLoaderMapping","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","selectedFieldNames","NodeAdapter","Plan"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACEC,QAAQ,EACRC,gBAAgB,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","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","selectedFieldNames","NodeAdapter","mappingParentTypes","Plan"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACEC,QAAQ,EACRC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,gBAAgB,EAGhBC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,QACT,kBAAkB;AACzB,SAIEC,kBAAkB,QACb,eAAe;AACtB,SAAoBC,WAAW,QAA2B,YAAY;AACtE,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,IAAI,QAAyB,YAAY"}
@@ -21,22 +21,48 @@ export declare const EMPTY_MAPPING: Mapping;
21
21
  /**
22
22
  * Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
23
23
  * mapping is never changed after the fact (two plays may accept a different subset of the fields).
24
+ *
25
+ * Invocations of one field share what is beneath them (see `Plan.nested`), so a mapping is a DAG
26
+ * whose keys can all lead to one mapping. A pair is unioned once however many keys lead to it, or
27
+ * the union would take as long as the DAG written out as a tree.
24
28
  */
25
29
  export declare function unionMappings(into: Mapping | undefined, from: Mapping): Mapping;
30
+ /**
31
+ * The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
32
+ * every executor coerces afresh for each operation, so operations sharing a context never share
33
+ * an entry. The events of a subscription may share them, so a plan cached here runs its `select`
34
+ * and `query` callbacks once for all of them; use `forExecution` where they read per-event state.
35
+ */
36
+ export declare function forOperation<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
37
+ /**
38
+ * The entries of `cache` for the execution `info` is in, by `executionOf`, as mappings are kept:
39
+ * each event of a subscription gets its own, and @defer and @stream payloads share their
40
+ * execution's.
41
+ */
42
+ export declare function forExecution<T>(cache: WeakMap<object, Map<string, T>>, info: GraphQLResolveInfo): Map<string, T>;
26
43
  /** The string keys of a response path joined by `.`; list indices are dropped. */
27
44
  export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
28
45
  export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
46
+ /**
47
+ * `cacheKey(type, info.path)` and the identity of every node in `info.fieldNodes`. The path keeps
48
+ * each place in the response apart, list indices aside, so the root fields of a mutation, which run
49
+ * in turn and whose callbacks may read what an earlier one changed, never share a plan. The nodes
50
+ * decide what a plan loads: fragments on different types can merge different nodes into one
51
+ * response path, so a plan keyed on the path alone would be reused for a field asking for
52
+ * something else.
53
+ */
54
+ export declare function fieldKey(type: string, info: GraphQLResolveInfo): string;
29
55
  /**
30
56
  * Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
31
- * The plan loaded the whole field, so its mappings answer for 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 answer for everything resolved beneath this
58
+ * execution of it. Multiple plans can contribute to one field (Relay nodes of different model
33
59
  * types share the list's path), so later contributions replace matching keys and retain others.
34
60
  */
35
61
  export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
36
62
  /**
37
63
  * Records a row's mappings and scopes its descendants to this concrete field execution. A
38
64
  * descendant's parent is a different object, so row identity alone cannot carry its plan through
39
- * a relation, connection wrapper, or list. The 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
  /**
@@ -48,16 +74,18 @@ export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, ma
48
74
  export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
49
75
  /**
50
76
  * `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
51
- * against `row` rather than claimed for the whole field, so a sibling row the plan never loaded
52
- * keeps falling back instead of reading the entry and resolving against data it does not carry.
77
+ * against `row` rather than claimed for the whole field, so the field's lookup on `row` answers
78
+ * from it whatever the field's other rows were loaded with.
53
79
  *
54
80
  * Descendants inherit the mapping through this field's execution scope, even when their parent
55
81
  * is a child object or a connection wrapper rather than the row that was reloaded.
56
82
  */
57
83
  export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
58
84
  /**
59
- * The mapping recorded for the field 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.
85
+ * The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
86
+ * row over the plan's. `row` is the value whose data the mapping describes — the resolver's
87
+ * parent. The plan's comes from the nearest field execution above that recorded one: with none
88
+ * above, no plan loaded `row`, whatever was recorded for another row at the same path.
61
89
  */
62
- export declare function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path'], type: string, row?: unknown): Mapping | null;
90
+ export declare function getLoaderMapping(ctx: object, info: GraphQLResolveInfo, type: string, row?: unknown): Mapping | null;
63
91
  //# 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,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,UAEtE;AAuFD;;;;;GAKG;AACH,wBAA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xB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,QAWb;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,kBAAkB,EACxB,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,OAAO,GACZ,OAAO,GAAG,IAAI,CA+BhB"}
package/esm/loader-map.js CHANGED
@@ -2,45 +2,129 @@ import { createContextCache } from '@pothos/core';
2
2
  /** The mapping of a static selection: nothing can ever be recorded beneath one. */ export const EMPTY_MAPPING = Object.freeze({
3
3
  nested: Object.freeze({})
4
4
  });
5
+ /** Unions already made. A mapping is not changed once recorded, so one pair has one answer. */ const unions = new WeakMap();
5
6
  /**
6
7
  * Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
7
8
  * mapping is never changed after the fact (two plays may accept a different subset of the fields).
9
+ *
10
+ * Invocations of one field share what is beneath them (see `Plan.nested`), so a mapping is a DAG
11
+ * whose keys can all lead to one mapping. A pair is unioned once however many keys lead to it, or
12
+ * the union would take as long as the DAG written out as a tree.
8
13
  */ export function unionMappings(into, from) {
9
14
  if (!into || into === EMPTY_MAPPING) {
10
15
  return from;
11
16
  }
17
+ if (into === from || from === EMPTY_MAPPING) {
18
+ return into;
19
+ }
20
+ let byFrom = unions.get(into);
21
+ if (!byFrom) {
22
+ byFrom = new WeakMap();
23
+ unions.set(into, byFrom);
24
+ }
25
+ const known = byFrom.get(from);
26
+ if (known) {
27
+ return known;
28
+ }
12
29
  const nested = {
13
30
  ...into.nested
14
31
  };
15
32
  for (const key of Object.keys(from.nested)){
16
33
  nested[key] = unionMappings(nested[key], from.nested[key]);
17
34
  }
18
- return into.position === undefined ? {
35
+ const union = into.position === undefined ? {
19
36
  nested
20
37
  } : {
21
38
  nested,
22
39
  position: into.position
23
40
  };
41
+ byFrom.set(from, union);
42
+ return union;
24
43
  }
44
+ /** Per context: the cache of each execution, by `executionOf`. */ const contextCaches = createContextCache(()=>new WeakMap());
25
45
  /**
26
- * Per request context: the mappings recorded so far, and the keys they were recorded under, by
27
- * the path prefix that rehomed them. `responsePath` drops list indices, so every row of a list
28
- * rebuilds the same key strings; a prefix builds them once.
46
+ * An object the executor builds once per execution, and once per event of a subscription, and
47
+ * hands to every resolver in it, @defer and @stream payloads included:
29
48
  *
30
- * `mappings` holds what a plan recorded for a whole field: every row of that field was loaded by
31
- * it, so one mapping per path answers for all of them. `rows` holds a mapping that answers for
32
- * one row only — because two plans disagreed about a key, or because the plan loaded that row
33
- * alone. A mapping carries the position a connection pages with, so a row answering from another
34
- * row's mapping would page with arguments its own data was never fetched with. `rowScoped` stays
35
- * false while nothing has been recorded there, so a request whose rows were all loaded the same
36
- * way pays nothing for the row tier.
37
- */ const cache = createContextCache(()=>({
38
- mappings: new Map(),
39
- rehomed: new Map(),
40
- rows: new WeakMap(),
41
- rowScoped: false,
42
- scopes: new WeakMap()
43
- }));
49
+ * - graphql-js 17: the `getAbortSignal` of the execution.
50
+ * - graphql-js 16 and @graphql-tools/executor (Yoga): the root link of the path. They build one
51
+ * path chain per execution or event, linking each field to its parent's, so every resolver
52
+ * beneath a root field shares its link, and the `subscribe` resolver has its own. Their fields'
53
+ * links carry a `typename`. A root field doesn't share its link with the others, so each root
54
+ * field has a cache of its own, which is all it reads.
55
+ * - graphql-jit: the coerced `variableValues`. It builds a new path, without `typename`, for every
56
+ * resolver, but coerces the variables afresh for every execution and event.
57
+ */ function executionOf(info) {
58
+ const signal = info.getAbortSignal;
59
+ if (signal) {
60
+ return signal;
61
+ }
62
+ let { path } = info;
63
+ if (path.typename === undefined) {
64
+ return info.variableValues;
65
+ }
66
+ while(path.prev){
67
+ path = path.prev;
68
+ }
69
+ return path;
70
+ }
71
+ function cache(ctx, info) {
72
+ const executions = contextCaches(ctx);
73
+ const execution = executionOf(info);
74
+ let cached = executions.get(execution);
75
+ if (!cached) {
76
+ cached = {
77
+ mappings: new Map(),
78
+ places: new Map(),
79
+ rehomed: new Map(),
80
+ rows: new WeakMap(),
81
+ rowScoped: false,
82
+ scopes: new WeakMap()
83
+ };
84
+ executions.set(execution, cached);
85
+ }
86
+ return cached;
87
+ }
88
+ /**
89
+ * Where `path`, a link of `info.path`, sits in its execution: the link itself, where the executor
90
+ * builds one per field execution and shares it with the resolvers beneath, which a field's link
91
+ * carrying a `typename` tells. Where it builds a new path for every resolver (graphql-jit), an
92
+ * object standing for the path's keys, list indices included.
93
+ */ function placeOf(cached, info, path) {
94
+ if (info.path.typename !== undefined) {
95
+ return path;
96
+ }
97
+ const at = executionPath(path);
98
+ let place = cached.places.get(at);
99
+ if (!place) {
100
+ place = {};
101
+ cached.places.set(at, place);
102
+ }
103
+ return place;
104
+ }
105
+ /**
106
+ * The entries of `cache` for the operation `info` is in. Keyed on its `variableValues`, which
107
+ * every executor coerces afresh for each operation, so operations sharing a context never share
108
+ * an entry. The events of a subscription may share them, so a plan cached here runs its `select`
109
+ * and `query` callbacks once for all of them; use `forExecution` where they read per-event state.
110
+ */ export function forOperation(cache, info) {
111
+ return entriesFor(cache, info.variableValues);
112
+ }
113
+ /**
114
+ * The entries of `cache` for the execution `info` is in, by `executionOf`, as mappings are kept:
115
+ * each event of a subscription gets its own, and @defer and @stream payloads share their
116
+ * execution's.
117
+ */ export function forExecution(cache, info) {
118
+ return entriesFor(cache, executionOf(info));
119
+ }
120
+ function entriesFor(cache, key) {
121
+ let entries = cache.get(key);
122
+ if (!entries) {
123
+ entries = new Map();
124
+ cache.set(key, entries);
125
+ }
126
+ return entries;
127
+ }
44
128
  /**
45
129
  * Memoised per path link, which is created once per field per row and never mutated. graphql-js
46
130
  * shares the links above a list between every row of it, so the prefix of a field resolved for
@@ -59,13 +143,46 @@ import { createContextCache } from '@pothos/core';
59
143
  }
60
144
  return key;
61
145
  }
146
+ /**
147
+ * Memoised per path link, as `pathKeys` is. Built only where paths are rebuilt for every resolver,
148
+ * so it saves the walk over a resolver's ancestors from building each prefix again.
149
+ */ const executionPaths = new WeakMap();
150
+ /** Every key of a response path, list indices included, joined by `.`. */ function executionPath(path) {
151
+ let key = executionPaths.get(path);
152
+ if (key === undefined) {
153
+ key = path.prev ? `${executionPath(path.prev)}.${path.key}` : String(path.key);
154
+ executionPaths.set(path, key);
155
+ }
156
+ return key;
157
+ }
62
158
  export function cacheKey(type, path) {
63
159
  return `${type}@${responsePath(path)}`;
64
160
  }
161
+ /** A number for each field node seen, by identity. Weak, so the nodes go with their document. */ const fieldNodeIds = new WeakMap();
162
+ let nextFieldNodeId = 0;
163
+ /**
164
+ * `cacheKey(type, info.path)` and the identity of every node in `info.fieldNodes`. The path keeps
165
+ * each place in the response apart, list indices aside, so the root fields of a mutation, which run
166
+ * in turn and whose callbacks may read what an earlier one changed, never share a plan. The nodes
167
+ * decide what a plan loads: fragments on different types can merge different nodes into one
168
+ * response path, so a plan keyed on the path alone would be reused for a field asking for
169
+ * something else.
170
+ */ export function fieldKey(type, info) {
171
+ let key = cacheKey(type, info.path);
172
+ for (const node of info.fieldNodes){
173
+ let id = fieldNodeIds.get(node);
174
+ if (id === undefined) {
175
+ id = nextFieldNodeId++;
176
+ fieldNodeIds.set(node, id);
177
+ }
178
+ key += `:${id}`;
179
+ }
180
+ return key;
181
+ }
65
182
  /**
66
183
  * The keys `mappings` is recorded under when it is rehomed beneath `prefix`. Built once per
67
- * prefix and shared by both tiers: the strings depend on the path and the plan's own keys, never
68
- * on which row is being recorded for.
184
+ * prefix: the strings depend on the path and the plan's own keys, never on which row is being
185
+ * recorded for.
69
186
  */ function rehomedKeys(cached, prefix) {
70
187
  let keys = cached.rehomed.get(prefix);
71
188
  if (!keys) {
@@ -89,47 +206,43 @@ export function cacheKey(type, path) {
89
206
  /**
90
207
  * Records `mapping` at `key` for `row`. An unclaimed key takes it, and a key already holding this
91
208
  * very mapping needs no write, so the rows after the first write nothing. Only a key two plans
92
- * disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing, so
93
- * the resolvers beneath fall back and load their own data.
94
- */ function claim(cached, key, mapping, row, path) {
209
+ * disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing.
210
+ */ function claim(cached, key, mapping, row, place) {
95
211
  const held = cached.mappings.get(key);
96
212
  if (held === undefined) {
97
213
  cached.mappings.set(key, mapping);
98
214
  } else if (held !== mapping && row) {
99
- claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, path);
215
+ claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, place);
100
216
  }
101
217
  }
102
218
  /**
103
- * Records `mapping` for this field execution against `row` alone, never in the shared tier. The caller loaded
104
- * `row` by itself, so an unclaimed key is not the caller's to take: the shared tier answers for
105
- * every row of a field, and a sibling that was never loaded would read the entry as proof that
106
- * it had been. With no row to hang it off there is nothing to record, and the resolvers beneath
107
- * fall back and load their own data.
108
- */ function claimForRow(cached, type, mapping, row, path) {
109
- let byPath = cached.rows.get(row);
110
- if (!byPath) {
111
- byPath = new WeakMap();
112
- cached.rows.set(row, byPath);
219
+ * Records `mapping` for this field execution against `row` alone.
220
+ */ function claimForRow(cached, type, mapping, row, place) {
221
+ let byPlace = cached.rows.get(row);
222
+ if (!byPlace) {
223
+ byPlace = new WeakMap();
224
+ cached.rows.set(row, byPlace);
113
225
  cached.rowScoped = true;
114
226
  }
115
- let own = byPath.get(path);
227
+ let own = byPlace.get(place);
116
228
  if (!own) {
117
229
  own = new Map();
118
- byPath.set(path, own);
230
+ byPlace.set(place, own);
119
231
  }
120
232
  own.set(type, mapping);
121
233
  }
122
234
  /**
123
235
  * Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
124
- * The plan loaded the whole field, so its mappings answer for every row of it: they go to the
125
- * shared tier. Multiple plans can contribute to one field (Relay nodes of different model
236
+ * The plan loaded the whole field, so its mappings answer for everything resolved beneath this
237
+ * execution of it. Multiple plans can contribute to one field (Relay nodes of different model
126
238
  * types share the list's path), so later contributions replace matching keys and retain others.
127
239
  */ export function setLoaderMappings(ctx, info, mappings) {
128
- const cached = cache(ctx);
240
+ const cached = cache(ctx, info);
129
241
  const prefix = responsePath(info.path);
130
242
  const keys = rehomedKeys(cached, prefix);
131
- const previous = cached.scopes.get(info.path);
132
- cached.scopes.set(info.path, previous ? {
243
+ const place = placeOf(cached, info, info.path);
244
+ const previous = cached.scopes.get(place);
245
+ cached.scopes.set(place, previous ? {
133
246
  ...previous,
134
247
  ...mappings
135
248
  } : mappings);
@@ -140,9 +253,10 @@ export function cacheKey(type, path) {
140
253
  /**
141
254
  * Records a row's mappings and scopes its descendants to this concrete field execution. A
142
255
  * descendant's parent is a different object, so row identity alone cannot carry its plan through
143
- * a relation, connection wrapper, or list. The execution path retains indices to isolate siblings.
256
+ * a relation, connection wrapper, or list. The place keeps list indices to isolate siblings.
144
257
  */ export function setRowMappings(ctx, info, mappings) {
145
- cache(ctx).scopes.set(info.path, mappings);
258
+ const cached = cache(ctx, info);
259
+ cached.scopes.set(placeOf(cached, info, info.path), mappings);
146
260
  }
147
261
  /**
148
262
  * Records the mapping of the field `info` resolves (under its own parent type) along with the
@@ -150,48 +264,51 @@ export function cacheKey(type, path) {
150
264
  * themselves up. `row` is the value the field is about to resolve with: the parent row when it
151
265
  * was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
152
266
  */ export function setFieldMapping(ctx, info, mapping, row) {
153
- const cached = cache(ctx);
154
- const owner = ownerOf(row);
155
- claim(cached, cacheKey(info.parentType.name, info.path), mapping, owner, info.path);
156
- cached.scopes.set(info.path, mapping.nested);
267
+ const cached = cache(ctx, info);
268
+ const place = placeOf(cached, info, info.path);
269
+ claim(cached, cacheKey(info.parentType.name, info.path), mapping, ownerOf(row), place);
270
+ cached.scopes.set(place, mapping.nested);
157
271
  }
158
272
  /**
159
273
  * `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
160
- * against `row` rather than claimed for the whole field, so a sibling row the plan never loaded
161
- * keeps falling back instead of reading the entry and resolving against data it does not carry.
274
+ * against `row` rather than claimed for the whole field, so the field's lookup on `row` answers
275
+ * from it whatever the field's other rows were loaded with.
162
276
  *
163
277
  * Descendants inherit the mapping through this field's execution scope, even when their parent
164
278
  * is a child object or a connection wrapper rather than the row that was reloaded.
165
279
  */ export function setRowFieldMapping(ctx, info, mapping, row) {
166
- const cached = cache(ctx);
280
+ const cached = cache(ctx, info);
167
281
  const owner = ownerOf(row);
282
+ const place = placeOf(cached, info, info.path);
168
283
  if (owner) {
169
- claimForRow(cached, info.parentType.name, mapping, owner, info.path);
284
+ claimForRow(cached, info.parentType.name, mapping, owner, place);
170
285
  }
171
- cached.scopes.set(info.path, mapping.nested);
286
+ cached.scopes.set(place, mapping.nested);
172
287
  }
173
288
  /**
174
- * The mapping recorded for the field at `path` on `row`, preferring one recorded for that row
175
- * over the plan's. `row` is the value whose data the mapping describes — the resolver's parent.
176
- */ export function getLoaderMapping(ctx, path, type, row) {
177
- const cached = cache(ctx);
178
- const key = cacheKey(type, path);
289
+ * The mapping recorded for the field `info` resolves on `row`, preferring one recorded for that
290
+ * row over the plan's. `row` is the value whose data the mapping describes — the resolver's
291
+ * parent. The plan's comes from the nearest field execution above that recorded one: with none
292
+ * above, no plan loaded `row`, whatever was recorded for another row at the same path.
293
+ */ export function getLoaderMapping(ctx, info, type, row) {
294
+ const { path } = info;
295
+ const cached = cache(ctx, info);
179
296
  if (cached.rowScoped) {
180
297
  const owner = ownerOf(row);
181
- const own = owner && cached.rows.get(owner)?.get(path)?.get(type);
298
+ const own = owner && cached.rows.get(owner)?.get(placeOf(cached, info, path))?.get(type);
182
299
  if (own) {
183
300
  return own;
184
301
  }
185
302
  }
186
303
  for(let ancestor = path.prev; ancestor; ancestor = ancestor.prev){
187
- const scope = cached.scopes.get(ancestor);
304
+ const scope = cached.scopes.get(placeOf(cached, info, ancestor));
188
305
  if (scope) {
189
306
  // A different plan may have omitted this field. Do not treat a sibling's shared mapping
190
307
  // as proof that this execution loaded it.
191
308
  return scope[`${type}@${responsePath(path).slice(responsePath(ancestor).length + 1)}`] ?? null;
192
309
  }
193
310
  }
194
- return cached.mappings.get(key) ?? null;
311
+ return null;
195
312
  }
196
313
 
197
314
  //# sourceMappingURL=loader-map.js.map