@pothos/selection-mapper 0.1.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 (86) hide show
  1. package/.swcrc +10 -0
  2. package/LICENSE +6 -0
  3. package/README.md +92 -0
  4. package/dts/adapter.d.ts +74 -0
  5. package/dts/adapter.d.ts.map +1 -0
  6. package/dts/deep-equal.d.ts +7 -0
  7. package/dts/deep-equal.d.ts.map +1 -0
  8. package/dts/index.d.ts +13 -0
  9. package/dts/index.d.ts.map +1 -0
  10. package/dts/loader-map.d.ts +63 -0
  11. package/dts/loader-map.d.ts.map +1 -0
  12. package/dts/matches.d.ts +113 -0
  13. package/dts/matches.d.ts.map +1 -0
  14. package/dts/node.d.ts +85 -0
  15. package/dts/node.d.ts.map +1 -0
  16. package/dts/plan.d.ts +176 -0
  17. package/dts/plan.d.ts.map +1 -0
  18. package/dts/types.d.ts +97 -0
  19. package/dts/types.d.ts.map +1 -0
  20. package/dts/walk.d.ts +24 -0
  21. package/dts/walk.d.ts.map +1 -0
  22. package/esm/adapter.d.ts +74 -0
  23. package/esm/adapter.d.ts.map +1 -0
  24. package/esm/adapter.js +47 -0
  25. package/esm/adapter.js.map +1 -0
  26. package/esm/deep-equal.d.ts +7 -0
  27. package/esm/deep-equal.d.ts.map +1 -0
  28. package/esm/deep-equal.js +50 -0
  29. package/esm/deep-equal.js.map +1 -0
  30. package/esm/index.d.ts +13 -0
  31. package/esm/index.d.ts.map +1 -0
  32. package/esm/index.js +12 -0
  33. package/esm/index.js.map +1 -0
  34. package/esm/loader-map.d.ts +63 -0
  35. package/esm/loader-map.d.ts.map +1 -0
  36. package/esm/loader-map.js +197 -0
  37. package/esm/loader-map.js.map +1 -0
  38. package/esm/matches.d.ts +113 -0
  39. package/esm/matches.d.ts.map +1 -0
  40. package/esm/matches.js +419 -0
  41. package/esm/matches.js.map +1 -0
  42. package/esm/node.d.ts +85 -0
  43. package/esm/node.d.ts.map +1 -0
  44. package/esm/node.js +232 -0
  45. package/esm/node.js.map +1 -0
  46. package/esm/package.json +3 -0
  47. package/esm/plan.d.ts +176 -0
  48. package/esm/plan.d.ts.map +1 -0
  49. package/esm/plan.js +339 -0
  50. package/esm/plan.js.map +1 -0
  51. package/esm/types.d.ts +97 -0
  52. package/esm/types.d.ts.map +1 -0
  53. package/esm/types.js +10 -0
  54. package/esm/types.js.map +1 -0
  55. package/esm/walk.d.ts +24 -0
  56. package/esm/walk.d.ts.map +1 -0
  57. package/esm/walk.js +442 -0
  58. package/esm/walk.js.map +1 -0
  59. package/lib/adapter.js +43 -0
  60. package/lib/adapter.js.map +1 -0
  61. package/lib/deep-equal.js +60 -0
  62. package/lib/deep-equal.js.map +1 -0
  63. package/lib/index.js +57 -0
  64. package/lib/index.js.map +1 -0
  65. package/lib/loader-map.js +209 -0
  66. package/lib/loader-map.js.map +1 -0
  67. package/lib/matches.js +427 -0
  68. package/lib/matches.js.map +1 -0
  69. package/lib/node.js +245 -0
  70. package/lib/node.js.map +1 -0
  71. package/lib/plan.js +349 -0
  72. package/lib/plan.js.map +1 -0
  73. package/lib/types.js +9 -0
  74. package/lib/types.js.map +1 -0
  75. package/lib/walk.js +455 -0
  76. package/lib/walk.js.map +1 -0
  77. package/package.json +55 -0
  78. package/src/adapter.ts +96 -0
  79. package/src/deep-equal.ts +67 -0
  80. package/src/index.ts +32 -0
  81. package/src/loader-map.ts +287 -0
  82. package/src/matches.ts +681 -0
  83. package/src/node.ts +327 -0
  84. package/src/plan.ts +454 -0
  85. package/src/types.ts +123 -0
  86. package/src/walk.ts +696 -0
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get EMPTY_MAPPING () {
13
+ return EMPTY_MAPPING;
14
+ },
15
+ get cacheKey () {
16
+ return cacheKey;
17
+ },
18
+ get getLoaderMapping () {
19
+ return getLoaderMapping;
20
+ },
21
+ get responsePath () {
22
+ return responsePath;
23
+ },
24
+ get setFieldMapping () {
25
+ return setFieldMapping;
26
+ },
27
+ get setLoaderMappings () {
28
+ return setLoaderMappings;
29
+ },
30
+ get setRowFieldMapping () {
31
+ return setRowFieldMapping;
32
+ },
33
+ get setRowMappings () {
34
+ return setRowMappings;
35
+ },
36
+ get unionMappings () {
37
+ return unionMappings;
38
+ }
39
+ });
40
+ const _core = require("@pothos/core");
41
+ const EMPTY_MAPPING = Object.freeze({
42
+ nested: Object.freeze({})
43
+ });
44
+ function unionMappings(into, from) {
45
+ if (!into || into === EMPTY_MAPPING) {
46
+ return from;
47
+ }
48
+ const nested = {
49
+ ...into.nested
50
+ };
51
+ for (const key of Object.keys(from.nested)){
52
+ nested[key] = unionMappings(nested[key], from.nested[key]);
53
+ }
54
+ return into.position === undefined ? {
55
+ nested
56
+ } : {
57
+ nested,
58
+ position: into.position
59
+ };
60
+ }
61
+ /**
62
+ * Per request context: the mappings recorded so far, and the keys they were recorded under, by
63
+ * the path prefix that rehomed them. `responsePath` drops list indices, so every row of a list
64
+ * rebuilds the same key strings; a prefix builds them once.
65
+ *
66
+ * `mappings` holds what a plan recorded for a whole field: every row of that field was loaded by
67
+ * it, so one mapping per path answers for all of them. `rows` holds a mapping that answers for
68
+ * one row only — because two plans disagreed about a key, or because the plan loaded that row
69
+ * alone. A mapping carries the position a connection pages with, so a row answering from another
70
+ * row's mapping would page with arguments its own data was never fetched with. `rowScoped` stays
71
+ * false while nothing has been recorded there, so a request whose rows were all loaded the same
72
+ * way pays nothing for the row tier.
73
+ */ const cache = (0, _core.createContextCache)(()=>({
74
+ mappings: new Map(),
75
+ rehomed: new Map(),
76
+ rows: new WeakMap(),
77
+ rowScoped: false,
78
+ scopes: new WeakMap()
79
+ }));
80
+ /**
81
+ * Memoised per path link, which is created once per field per row and never mutated. graphql-js
82
+ * shares the links above a list between every row of it, so the prefix of a field resolved for
83
+ * each of N rows is built once rather than N times. Weak, so the links go with the request.
84
+ */ const pathKeys = new WeakMap();
85
+ function responsePath(path) {
86
+ if (!path) {
87
+ return '';
88
+ }
89
+ let key = pathKeys.get(path);
90
+ if (key === undefined) {
91
+ const prefix = responsePath(path.prev);
92
+ // A list index contributes nothing, so the link's key is its prefix's.
93
+ key = typeof path.key === 'string' ? prefix ? `${prefix}.${path.key}` : path.key : prefix;
94
+ pathKeys.set(path, key);
95
+ }
96
+ return key;
97
+ }
98
+ function cacheKey(type, path) {
99
+ return `${type}@${responsePath(path)}`;
100
+ }
101
+ /**
102
+ * The keys `mappings` is recorded under when it is rehomed beneath `prefix`. Built once per
103
+ * prefix and shared by both tiers: the strings depend on the path and the plan's own keys, never
104
+ * on which row is being recorded for.
105
+ */ function rehomedKeys(cached, prefix) {
106
+ let keys = cached.rehomed.get(prefix);
107
+ if (!keys) {
108
+ keys = new Map();
109
+ cached.rehomed.set(prefix, keys);
110
+ }
111
+ return keys;
112
+ }
113
+ /** `key`, a plan's own `Type@relative.path`, moved beneath `prefix`. Built once per prefix. */ function rehome(keys, key, prefix) {
114
+ let under = keys.get(key);
115
+ if (under === undefined) {
116
+ const at = key.indexOf('@');
117
+ under = `${key.slice(0, at)}@${prefix}.${key.slice(at + 1)}`;
118
+ keys.set(key, under);
119
+ }
120
+ return under;
121
+ }
122
+ /** `row` if a mapping can be hung off it. A root field resolves with no parent value at all. */ function ownerOf(row) {
123
+ return typeof row === 'object' && row !== null ? row : null;
124
+ }
125
+ /**
126
+ * Records `mapping` at `key` for `row`. An unclaimed key takes it, and a key already holding this
127
+ * very mapping needs no write, so the rows after the first write nothing. Only a key two plans
128
+ * disagree about gives the row a mapping of its own — or, with no row to hang it off, nothing, so
129
+ * the resolvers beneath fall back and load their own data.
130
+ */ function claim(cached, key, mapping, row, path) {
131
+ const held = cached.mappings.get(key);
132
+ if (held === undefined) {
133
+ cached.mappings.set(key, mapping);
134
+ } else if (held !== mapping && row) {
135
+ claimForRow(cached, key.slice(0, key.indexOf('@')), mapping, row, path);
136
+ }
137
+ }
138
+ /**
139
+ * Records `mapping` for this field execution against `row` alone, never in the shared tier. The caller loaded
140
+ * `row` by itself, so an unclaimed key is not the caller's to take: the shared tier answers for
141
+ * every row of a field, and a sibling that was never loaded would read the entry as proof that
142
+ * it had been. With no row to hang it off there is nothing to record, and the resolvers beneath
143
+ * fall back and load their own data.
144
+ */ function claimForRow(cached, type, mapping, row, path) {
145
+ let byPath = cached.rows.get(row);
146
+ if (!byPath) {
147
+ byPath = new WeakMap();
148
+ cached.rows.set(row, byPath);
149
+ cached.rowScoped = true;
150
+ }
151
+ let own = byPath.get(path);
152
+ if (!own) {
153
+ own = new Map();
154
+ byPath.set(path, own);
155
+ }
156
+ own.set(type, mapping);
157
+ }
158
+ function setLoaderMappings(ctx, info, mappings) {
159
+ const cached = cache(ctx);
160
+ const prefix = responsePath(info.path);
161
+ const keys = rehomedKeys(cached, prefix);
162
+ const previous = cached.scopes.get(info.path);
163
+ cached.scopes.set(info.path, previous ? {
164
+ ...previous,
165
+ ...mappings
166
+ } : mappings);
167
+ for (const key of Object.keys(mappings)){
168
+ cached.mappings.set(rehome(keys, key, prefix), mappings[key]);
169
+ }
170
+ }
171
+ function setRowMappings(ctx, info, mappings) {
172
+ cache(ctx).scopes.set(info.path, mappings);
173
+ }
174
+ function setFieldMapping(ctx, info, mapping, row) {
175
+ const cached = cache(ctx);
176
+ const owner = ownerOf(row);
177
+ claim(cached, cacheKey(info.parentType.name, info.path), mapping, owner, info.path);
178
+ cached.scopes.set(info.path, mapping.nested);
179
+ }
180
+ function setRowFieldMapping(ctx, info, mapping, row) {
181
+ const cached = cache(ctx);
182
+ const owner = ownerOf(row);
183
+ if (owner) {
184
+ claimForRow(cached, info.parentType.name, mapping, owner, info.path);
185
+ }
186
+ cached.scopes.set(info.path, mapping.nested);
187
+ }
188
+ function getLoaderMapping(ctx, path, type, row) {
189
+ const cached = cache(ctx);
190
+ const key = cacheKey(type, path);
191
+ if (cached.rowScoped) {
192
+ const owner = ownerOf(row);
193
+ const own = owner && cached.rows.get(owner)?.get(path)?.get(type);
194
+ if (own) {
195
+ return own;
196
+ }
197
+ }
198
+ for(let ancestor = path.prev; ancestor; ancestor = ancestor.prev){
199
+ const scope = cached.scopes.get(ancestor);
200
+ if (scope) {
201
+ // A different plan may have omitted this field. Do not treat a sibling's shared mapping
202
+ // as proof that this execution loaded it.
203
+ return scope[`${type}@${responsePath(path).slice(responsePath(ancestor).length + 1)}`] ?? null;
204
+ }
205
+ }
206
+ return cached.mappings.get(key) ?? null;
207
+ }
208
+
209
+ //# sourceMappingURL=loader-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/loader-map.ts"],"names":["EMPTY_MAPPING","cacheKey","getLoaderMapping","responsePath","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","unionMappings","Object","freeze","nested","into","from","key","keys","position","undefined","cache","createContextCache","mappings","Map","rehomed","rows","WeakMap","rowScoped","scopes","pathKeys","path","get","prefix","prev","set","type","rehomedKeys","cached","rehome","under","at","indexOf","slice","ownerOf","row","claim","mapping","held","claimForRow","byPath","own","ctx","info","previous","owner","parentType","name","ancestor","scope","length"],"mappings":";;;;;;;;;;;QAuBaA;eAAAA;;QAqEGC;eAAAA;;QAmKAC;eAAAA;;QArLAC;eAAAA;;QA4IAC;eAAAA;;QA3BAC;eAAAA;;QAgDAC;eAAAA;;QA/BAC;eAAAA;;QA/KAC;eAAAA;;;sBA7BmB;AAuB5B,MAAMR,gBAAyBS,OAAOC,MAAM,CAAC;IAAEC,QAAQF,OAAOC,MAAM,CAAC,CAAC;AAAe;AAMrF,SAASF,cAAcI,IAAyB,EAAEC,IAAa;IACpE,IAAI,CAACD,QAAQA,SAASZ,eAAe;QACnC,OAAOa;IACT;IAEA,MAAMF,SAAmB;QAAE,GAAGC,KAAKD,MAAM;IAAC;IAE1C,KAAK,MAAMG,O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AAG,CAACkB,KAAKtB,IAAI,EAAEgB,QAAQjC,MAAM;AAC7C;AAMO,SAAST,iBACd+C,GAAW,EACXrB,IAAgC,EAChCK,IAAY,EACZS,GAAa;IAEb,MAAMP,SAASjB,MAAM+B;IACrB,MAAMnC,MAAMb,SAASgC,MAAML;IAE3B,IAAIO,OAAOV,SAAS,EAAE;QACpB,MAAM2B,QAAQX,QAAQC;QACtB,MAAMM,MAAMI,SAASjB,OAAOZ,IAAI,CAACM,GAAG,CAACuB,QAAQvB,IAAID,OAAOC,IAAII;QAE5D,IAAIe,KAAK;YACP,OAAOA;QACT;IACF;IAEA,IAAK,IAAIO,WAAW3B,KAAKG,IAAI,EAAEwB,UAAUA,WAAWA,SAASxB,IAAI,CAAE;QACjE,MAAMyB,QAAQrB,OAAOT,MAAM,CAACG,GAAG,CAAC0B;QAEhC,IAAIC,OAAO;YACT,wFAAwF;YACxF,0CAA0C;YAC1C,OACEA,KAAK,CAAC,GAAGvB,KAAK,CAAC,EAAE9B,aAAayB,MAAMY,KAAK,CAACrC,aAAaoD,UAAUE,MAAM,GAAG,IAAI,CAAC,IAAI;QAEvF;IACF;IAEA,OAAOtB,OAAOf,QAAQ,CAACS,GAAG,CAACf,QAAQ;AACrC"}
package/lib/matches.js ADDED
@@ -0,0 +1,427 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get collectSelectedFieldNames () {
13
+ return collectSelectedFieldNames;
14
+ },
15
+ get findMatches () {
16
+ return findMatches;
17
+ },
18
+ get firstMatch () {
19
+ return firstMatch;
20
+ },
21
+ get includeOf () {
22
+ return includeOf;
23
+ },
24
+ get isDeferred () {
25
+ return isDeferred;
26
+ },
27
+ get isSkipped () {
28
+ return isSkipped;
29
+ },
30
+ get matchesForModel () {
31
+ return matchesForModel;
32
+ },
33
+ get modelOf () {
34
+ return modelOf;
35
+ },
36
+ get normalizeInclude () {
37
+ return normalizeInclude;
38
+ },
39
+ get resolveType () {
40
+ return resolveType;
41
+ },
42
+ get selectedFieldNames () {
43
+ return selectedFieldNames;
44
+ }
45
+ });
46
+ const _core = require("@pothos/core");
47
+ const _graphql = require("graphql");
48
+ function includeOf(type) {
49
+ return type.extensions?.pothosIndirectInclude;
50
+ }
51
+ function resolveType(schema, type) {
52
+ let target = type;
53
+ let include = includeOf(target);
54
+ while(include){
55
+ target = schema.getType(include.getType());
56
+ include = includeOf(target);
57
+ }
58
+ return target;
59
+ }
60
+ function modelOf(adapter, schema, type) {
61
+ return adapter.modelFor(resolveType(schema, type));
62
+ }
63
+ function matchesForModel(adapter, schema, matches, targetType) {
64
+ const targetModel = modelOf(adapter, schema, targetType);
65
+ if (!targetModel) {
66
+ return matches;
67
+ }
68
+ return matches.filter((match)=>{
69
+ const model = modelOf(adapter, schema, match.type);
70
+ return !model || model === targetModel;
71
+ });
72
+ }
73
+ /**
74
+ * The one selection traversal this package owns. It reads the selections of `selection` at
75
+ * `level`: drops what `@skip`/`@include` removes, classifies every fragment
76
+ * (`resolveFragmentTypes`), notes whether a `@defer` was crossed, descends into the fragments
77
+ * that apply, expands a named fragment once per state (`memo`), and calls `visit` at every field
78
+ * that applies to `level.type`. What happens at a field is the caller's alone, which is the whole
79
+ * of the difference between its consumers: `matchPath` matches one path segment's name and
80
+ * descends with the rest of the path, `collectSelectedFieldNames` adds every name and descends no
81
+ * further, and `firstMatch` takes the first match and stops.
82
+ *
83
+ * `segment` is the indirect-include path segment the caller is looking for, when it has one; only
84
+ * its `type` is read, to pin the type a fragment is expected on.
85
+ *
86
+ * `memo` records the named fragments already expanded, keyed on the fragment, the two types, the
87
+ * deferred flag, and `memoKey` — whatever else the caller varies as it descends (`matchPath`
88
+ * passes its remaining path length and its alias path). A fragment spread more than once at one
89
+ * point of the traversal is expanded once: a valid fragment DAG can spread the same fragment at
90
+ * every level, which makes expanding every spread exponential in its depth. A caller that varies
91
+ * nothing passes no `memoKey`, leaving its memo finer than it needs to be by the deferred flag —
92
+ * a little time, never correctness, for a caller that accumulates.
93
+ *
94
+ * This traversal decides nothing about `@defer`: it reports `level.deferred` and the visitor
95
+ * chooses, and the consumers do not choose alike. `findMatches` reports the flag and
96
+ * `walkBranches` honours it, so a deferred branch is entered but its fields are not walked while
97
+ * `skipDeferredFragments` is set; `firstMatch` (the `selectedFieldNode` a select function is
98
+ * handed) and `selectedFieldNames` both discard it.
99
+ *
100
+ * The last two therefore over-report — they answer "yes, the document selects this" for a
101
+ * selection branch resolution will skip — and that direction is what makes the divergence safe.
102
+ * The plugins use both as gates, and a gate computed from an over-reporting source can only be
103
+ * wrongly true, which loads a column or a count nothing reads; it can never be wrongly false, so
104
+ * no row goes missing and anything under-fetched falls through to the model loader, which
105
+ * re-queries. Make either honour the flag and the gates start under-reporting, which loses data;
106
+ * `matches.test.ts` pins the direction.
107
+ */ function eachSelectedField(info, selection, level, segment, visit, memo, memoKey = '') {
108
+ if (!selection.selectionSet) {
109
+ return false;
110
+ }
111
+ const { type, path, deferred } = level;
112
+ // A segment that pins a type condition pins it here too: its field must be found under a
113
+ // fragment on that type, never taken from a level that merely has a field of the same name.
114
+ const expectedType = pinnedType(info, segment) ?? level.expectedType;
115
+ const fieldsApply = expectedType.name === type.name && ((0, _graphql.isObjectType)(type) || (0, _graphql.isInterfaceType)(type));
116
+ for (const sel of selection.selectionSet.selections){
117
+ if (isSkipped(info, sel)) {
118
+ continue;
119
+ }
120
+ let fragment;
121
+ switch(sel.kind){
122
+ case _graphql.Kind.FIELD:
123
+ {
124
+ if (fieldsApply && visit(sel, level) === true) {
125
+ return true;
126
+ }
127
+ continue;
128
+ }
129
+ case _graphql.Kind.FRAGMENT_SPREAD:
130
+ fragment = info.fragments[sel.name.value];
131
+ break;
132
+ case _graphql.Kind.INLINE_FRAGMENT:
133
+ fragment = sel;
134
+ break;
135
+ default:
136
+ {
137
+ const unsupported = sel;
138
+ throw new _core.PothosValidationError(`Unsupported selection kind ${unsupported.kind}`);
139
+ }
140
+ }
141
+ const next = resolveFragmentTypes(info, fragment.typeCondition ? info.schema.getType(fragment.typeCondition.name.value) : undefined, type, expectedType);
142
+ const deferredHere = deferred || isDeferred(info, sel);
143
+ if (fragment.kind === _graphql.Kind.FRAGMENT_DEFINITION) {
144
+ const state = `${fragment.name.value}|${next.type.name}|${next.expectedType.name}|${deferredHere}|${memoKey}`;
145
+ if (memo.has(state)) {
146
+ continue;
147
+ }
148
+ memo.add(state);
149
+ }
150
+ const stopped = eachSelectedField(info, fragment, {
151
+ type: next.type,
152
+ expectedType: next.expectedType,
153
+ path,
154
+ deferred: deferredHere
155
+ }, segment, visit, memo, memoKey);
156
+ if (stopped) {
157
+ return true;
158
+ }
159
+ }
160
+ return false;
161
+ }
162
+ /**
163
+ * The field `name` of `type`, or a validation error. A document naming a field the type does not
164
+ * have only reaches here when graphql validation was skipped; without this it would read a
165
+ * property of undefined.
166
+ */ function fieldOn(type, name) {
167
+ const field = (0, _graphql.isObjectType)(type) || (0, _graphql.isInterfaceType)(type) ? type.getFields()[name] : undefined;
168
+ if (!field) {
169
+ throw new _core.PothosValidationError(`Unknown field ${name} on ${type.name}`);
170
+ }
171
+ return field;
172
+ }
173
+ /**
174
+ * Follows `includePath` from `level`, starting at segment `at`, to the fields selected at its end,
175
+ * reporting each to `onMatch` in document order and stopping when `onMatch` says to. Every step is
176
+ * one `eachSelectedField` whose visitor matches that segment by name and follows the rest of the
177
+ * path beneath it. The path is walked by index, so a step allocates nothing but the alias path it
178
+ * grew.
179
+ */ function matchPath(info, selection, level, includePath, at, onMatch, memo) {
180
+ const remaining = includePath.length - at;
181
+ if (remaining === 0) {
182
+ return onMatch({
183
+ type: level.type,
184
+ field: selection,
185
+ path: level.path,
186
+ deferred: level.deferred
187
+ }) === true;
188
+ }
189
+ const segment = includePath[at];
190
+ return eachSelectedField(info, selection, level, segment, (field, on)=>{
191
+ if (field.name.value !== segment.name) {
192
+ return false;
193
+ }
194
+ const returnType = (0, _graphql.getNamedType)(fieldOn(on.type, field.name.value).type);
195
+ return matchPath(info, field, {
196
+ type: returnType,
197
+ expectedType: returnType,
198
+ path: [
199
+ ...on.path,
200
+ field.alias?.value ?? field.name.value
201
+ ],
202
+ deferred: on.deferred
203
+ }, includePath, at + 1, onMatch, memo);
204
+ }, memo, `${remaining}|${level.path.join('.')}`);
205
+ }
206
+ /**
207
+ * Follows each of `paths`, prefixed by any type-level `prefix`, from `selection` (which is expected
208
+ * to be a selection on `type`), reporting the fields at their ends to `onMatch` in path order then
209
+ * document order, and stopping when `onMatch` says to. Paths are followed through fragments; see
210
+ * `resolveFragmentTypes` for the rules. Each path gets its own memo: what one path expanded says
211
+ * nothing about the next.
212
+ */ function eachMatch(info, type, selection, paths, { prefix, path = [], deferred = false }, onMatch) {
213
+ for (const includePath of paths){
214
+ const stopped = matchPath(info, selection, {
215
+ type,
216
+ expectedType: type,
217
+ path,
218
+ deferred
219
+ }, prefix?.length ? [
220
+ ...prefix,
221
+ ...includePath
222
+ ] : includePath, 0, onMatch, new Set());
223
+ if (stopped) {
224
+ return;
225
+ }
226
+ }
227
+ }
228
+ function findMatches(info, type, selection, paths, options = {}) {
229
+ const matches = [];
230
+ eachMatch(info, type, selection, paths, options, (match)=>{
231
+ matches.push(match);
232
+ });
233
+ return matches;
234
+ }
235
+ function firstMatch(info, type, selection, path, { prefix } = {}) {
236
+ let first;
237
+ eachMatch(info, type, selection, [
238
+ path
239
+ ], {
240
+ prefix
241
+ }, (match)=>{
242
+ first = match;
243
+ return true;
244
+ });
245
+ return first;
246
+ }
247
+ /**
248
+ * Per request context, per execution (`info.variableValues` is built once per execution, and the
249
+ * names depend on the variables through `@skip`/`@include`), per return type, then per field node.
250
+ */ const selectedFieldNamesCache = (0, _core.createContextCache)(()=>new WeakMap());
251
+ function selectedFieldNames(context, info) {
252
+ const byExecution = selectedFieldNamesCache(context);
253
+ let byType = byExecution.get(info.variableValues);
254
+ if (!byType) {
255
+ byType = new WeakMap();
256
+ byExecution.set(info.variableValues, byType);
257
+ }
258
+ let memo = memoIn(byType, (0, _graphql.getNamedType)(info.returnType));
259
+ for (const node of info.fieldNodes){
260
+ memo = memoIn(memo.next, node);
261
+ }
262
+ memo.names ??= collectSelectedFieldNames(info);
263
+ return memo.names;
264
+ }
265
+ function memoIn(map, key) {
266
+ let memo = map.get(key);
267
+ if (!memo) {
268
+ memo = {
269
+ next: new WeakMap()
270
+ };
271
+ map.set(key, memo);
272
+ }
273
+ return memo;
274
+ }
275
+ function collectSelectedFieldNames(info, returnType = (0, _graphql.getNamedType)(info.returnType), fieldNodes = info.fieldNodes) {
276
+ const prefix = includeOf(returnType)?.path;
277
+ const names = new Set();
278
+ // Every name at one level: `eachSelectedField`'s last step for all of them at once. The level's
279
+ // `deferred` flag is never read, which is the asymmetry `eachSelectedField` documents.
280
+ const addName = (field)=>{
281
+ names.add(field.name.value);
282
+ };
283
+ for (const node of fieldNodes){
284
+ // Through a wrapper, the fields are those beneath its inner field.
285
+ const roots = prefix?.length ? findMatches(info, returnType, node, [
286
+ prefix
287
+ ]) : [
288
+ {
289
+ type: returnType,
290
+ field: node,
291
+ deferred: false
292
+ }
293
+ ];
294
+ for (const root of roots){
295
+ eachSelectedField(info, root.field, {
296
+ type: root.type,
297
+ expectedType: root.type,
298
+ path: [],
299
+ deferred: root.deferred
300
+ }, undefined, addName, new Set());
301
+ }
302
+ }
303
+ return names;
304
+ }
305
+ /**
306
+ * The type to walk and the type the next segment is expected on, when descending into a fragment.
307
+ * `expected` arrives pinned: `eachSelectedField` resolved any `type` on the segment before it
308
+ * classified a single selection.
309
+ *
310
+ * - A fragment on the expected type, or on an abstract type the expected type belongs to, walks as
311
+ * the expected type: every field selectable there also exists on it.
312
+ * - A fragment that narrows an abstract expected type to an implementation or member, or to an
313
+ * abstract type that overlaps it, advances the expected type so the segment's field can be found
314
+ * on the narrower type.
315
+ * - Fragments on unrelated types keep the expected type, so their fields are skipped until a nested
316
+ * fragment narrows back to it.
317
+ */ function resolveFragmentTypes(info, fragmentType, type, expected) {
318
+ if (!fragmentType || fragmentType.name === expected.name) {
319
+ return {
320
+ type: fragmentType ?? type,
321
+ expectedType: expected
322
+ };
323
+ }
324
+ if ((0, _graphql.isAbstractType)(fragmentType) && ((0, _graphql.isObjectType)(expected) || (0, _graphql.isInterfaceType)(expected)) && info.schema.isSubType(fragmentType, expected)) {
325
+ return {
326
+ type: expected,
327
+ expectedType: expected
328
+ };
329
+ }
330
+ if ((0, _graphql.isAbstractType)(expected)) {
331
+ const narrows = (0, _graphql.isObjectType)(fragmentType) || (0, _graphql.isInterfaceType)(fragmentType) ? info.schema.isSubType(expected, fragmentType) : false;
332
+ const overlaps = (0, _graphql.isAbstractType)(fragmentType) && (0, _graphql.doTypesOverlap)(info.schema, expected, fragmentType);
333
+ if (narrows || overlaps) {
334
+ return {
335
+ type: fragmentType,
336
+ expectedType: fragmentType
337
+ };
338
+ }
339
+ }
340
+ return {
341
+ type: fragmentType,
342
+ expectedType: expected
343
+ };
344
+ }
345
+ /**
346
+ * The type an indirect-include segment pins its field to, or undefined when it pins none. A
347
+ * pinned segment names the fragment type condition the field must be found under, so the pin
348
+ * decides both which fragments are descended into and whether a field selected directly at a
349
+ * level counts as the segment's.
350
+ */ function pinnedType(info, segment) {
351
+ if (!segment?.type) {
352
+ return undefined;
353
+ }
354
+ const pinned = info.schema.getType(segment.type);
355
+ if (!pinned) {
356
+ throw new _core.PothosValidationError(`Unknown type ${segment.type} in indirect include path segment ${segment.name}`);
357
+ }
358
+ return pinned;
359
+ }
360
+ function normalizeInclude(path, type, expectedType, schema) {
361
+ let currentType = path.length > 0 ? type : expectedType ?? type;
362
+ const normalized = [];
363
+ if (path.length === 0 && !((0, _graphql.isObjectType)(currentType) || (0, _graphql.isInterfaceType)(currentType))) {
364
+ throw new _core.PothosValidationError(`Expected ${currentType} to be an Object or Interface type`);
365
+ }
366
+ for (const segment of path){
367
+ const { name, type: pinned } = typeof segment === 'string' ? {
368
+ name: segment
369
+ } : segment;
370
+ if (pinned) {
371
+ const pinnedType = schema.getType(pinned);
372
+ if (!pinnedType) {
373
+ throw new _core.PothosValidationError(`Unknown type ${pinned} in nested selection path segment ${name}`);
374
+ }
375
+ currentType = pinnedType;
376
+ }
377
+ if (!((0, _graphql.isObjectType)(currentType) || (0, _graphql.isInterfaceType)(currentType))) {
378
+ throw new _core.PothosValidationError(`Expected ${currentType} to be an Object or Interface type`);
379
+ }
380
+ const field = currentType.getFields()[name];
381
+ if (!field) {
382
+ throw new _core.PothosValidationError(`Expected ${currentType} to have a field ${name}`);
383
+ }
384
+ currentType = (0, _graphql.getNamedType)(field.type);
385
+ if (!((0, _graphql.isObjectType)(currentType) || (0, _graphql.isInterfaceType)(currentType))) {
386
+ throw new _core.PothosValidationError(`Expected ${currentType} to be an Object or Interface type`);
387
+ }
388
+ normalized.push(pinned ? {
389
+ name,
390
+ type: pinned
391
+ } : {
392
+ name
393
+ });
394
+ }
395
+ const targetType = currentType;
396
+ return {
397
+ getType: ()=>expectedType?.name ?? targetType.name,
398
+ path: normalized
399
+ };
400
+ }
401
+ function isSkipped(info, selection) {
402
+ if (!selection.directives?.length) {
403
+ return false;
404
+ }
405
+ const skip = (0, _graphql.getDirectiveValues)(_graphql.GraphQLSkipDirective, selection, info.variableValues);
406
+ if (skip?.if === true) {
407
+ return true;
408
+ }
409
+ const include = (0, _graphql.getDirectiveValues)(_graphql.GraphQLIncludeDirective, selection, info.variableValues);
410
+ if (include?.if === false) {
411
+ return true;
412
+ }
413
+ return false;
414
+ }
415
+ function isDeferred(info, node) {
416
+ if (!node.directives?.length) {
417
+ return false;
418
+ }
419
+ const deferDirective = info.schema.getDirective('defer');
420
+ if (!deferDirective) {
421
+ return false;
422
+ }
423
+ const defer = (0, _graphql.getDirectiveValues)(deferDirective, node, info.variableValues);
424
+ return !!defer && defer.if !== false;
425
+ }
426
+
427
+ //# sourceMappingURL=matches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/matches.ts"],"names":["collectSelectedFieldNames","findMatches","firstMatch","includeOf","isDeferred","isSkipped","matchesForModel","modelOf","normalizeInclude","resolveType","selectedFieldNames","type","extensions","pothosIndirectInclude","schema","target","include","getType","adapter","modelFor","matches","targetType","targetModel","filter","match","model","eachSelectedField","info","selection","level","segment","visit","memo","memoKey","selectionSet","path","deferred","expectedType","pinnedType","fieldsApply","name","isObjectType","isInterfaceType","sel","selections","fragment","kind","Kind","FIELD","FRAGMENT_SPREAD","fragments","value","INLINE_FRAGMENT","unsupported","PothosValidationError","next","resolveFragmentTypes","typeCondition","undefined","deferredHere","FRAGMENT_DEFINITION","state","has","add","stopped","fieldOn","field","getFields","matchPath","includePath","at","onMatch","remaining","length","on","returnType","getNamedType","alias","join","eachMatch","paths","prefix","Set","options","push","first","selectedFieldNamesCache","createContextCache","WeakMap","context","byExecution","byType","get","variableValues","set","memoIn","node","fieldNodes","names","map","key","addName","roots","root","fragmentType","expected","isAbstractType","isSubType","narrows","overlaps","doTypesOverlap","pinned","currentType","normalized","directives","skip","getDirectiveValues","GraphQLSkipDirective","if","GraphQLIncludeDirective","deferDirective","getDirective","defer"],"mappings":";;;;;;;;;;;QAydgBA;eAAAA;;QArGAC;eAAAA;;QAsBAC;eAAAA;;QA7UAC;eAAAA;;QA4lBAC;eAAAA;;QAtBAC;eAAAA;;QAniBAC;eAAAA;;QAdAC;eAAAA;;QAofAC;eAAAA;;QApgBAC;eAAAA;;QAqXAC;eAAAA;;;sBAvb0C;yBAmBnD;AA0CA,SAASP,UAAUQ,IAAsB;IAC9C,OAAOA,KAAKC,UAAU,EAAEC;AAC1B;AAGO,SAASJ,YAAYK,MAAqB,EAAEH,IAAsB;IACvE,IAAII,SAASJ;IACb,IAAIK,UAAUb,UAAUY;IAExB,MAAOC,QAAS;QACdD,SAASD,OAAOG,OAAO,CAACD,QAAQC,OAAO;QACvCD,UAAUb,UA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