@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.
- package/.swcrc +10 -0
- package/LICENSE +6 -0
- package/README.md +92 -0
- package/dts/adapter.d.ts +74 -0
- package/dts/adapter.d.ts.map +1 -0
- package/dts/deep-equal.d.ts +7 -0
- package/dts/deep-equal.d.ts.map +1 -0
- package/dts/index.d.ts +13 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/loader-map.d.ts +63 -0
- package/dts/loader-map.d.ts.map +1 -0
- package/dts/matches.d.ts +113 -0
- package/dts/matches.d.ts.map +1 -0
- package/dts/node.d.ts +85 -0
- package/dts/node.d.ts.map +1 -0
- package/dts/plan.d.ts +176 -0
- package/dts/plan.d.ts.map +1 -0
- package/dts/types.d.ts +97 -0
- package/dts/types.d.ts.map +1 -0
- package/dts/walk.d.ts +24 -0
- package/dts/walk.d.ts.map +1 -0
- package/esm/adapter.d.ts +74 -0
- package/esm/adapter.d.ts.map +1 -0
- package/esm/adapter.js +47 -0
- package/esm/adapter.js.map +1 -0
- package/esm/deep-equal.d.ts +7 -0
- package/esm/deep-equal.d.ts.map +1 -0
- package/esm/deep-equal.js +50 -0
- package/esm/deep-equal.js.map +1 -0
- package/esm/index.d.ts +13 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +12 -0
- package/esm/index.js.map +1 -0
- package/esm/loader-map.d.ts +63 -0
- package/esm/loader-map.d.ts.map +1 -0
- package/esm/loader-map.js +197 -0
- package/esm/loader-map.js.map +1 -0
- package/esm/matches.d.ts +113 -0
- package/esm/matches.d.ts.map +1 -0
- package/esm/matches.js +419 -0
- package/esm/matches.js.map +1 -0
- package/esm/node.d.ts +85 -0
- package/esm/node.d.ts.map +1 -0
- package/esm/node.js +232 -0
- package/esm/node.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/plan.d.ts +176 -0
- package/esm/plan.d.ts.map +1 -0
- package/esm/plan.js +339 -0
- package/esm/plan.js.map +1 -0
- package/esm/types.d.ts +97 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +10 -0
- package/esm/types.js.map +1 -0
- package/esm/walk.d.ts +24 -0
- package/esm/walk.d.ts.map +1 -0
- package/esm/walk.js +442 -0
- package/esm/walk.js.map +1 -0
- package/lib/adapter.js +43 -0
- package/lib/adapter.js.map +1 -0
- package/lib/deep-equal.js +60 -0
- package/lib/deep-equal.js.map +1 -0
- package/lib/index.js +57 -0
- package/lib/index.js.map +1 -0
- package/lib/loader-map.js +209 -0
- package/lib/loader-map.js.map +1 -0
- package/lib/matches.js +427 -0
- package/lib/matches.js.map +1 -0
- package/lib/node.js +245 -0
- package/lib/node.js.map +1 -0
- package/lib/plan.js +349 -0
- package/lib/plan.js.map +1 -0
- package/lib/types.js +9 -0
- package/lib/types.js.map +1 -0
- package/lib/walk.js +455 -0
- package/lib/walk.js.map +1 -0
- package/package.json +55 -0
- package/src/adapter.ts +96 -0
- package/src/deep-equal.ts +67 -0
- package/src/index.ts +32 -0
- package/src/loader-map.ts +287 -0
- package/src/matches.ts +681 -0
- package/src/node.ts +327 -0
- package/src/plan.ts +454 -0
- package/src/types.ts +123 -0
- package/src/walk.ts +696 -0
package/esm/walk.js
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The traversal: types, variants, fields and fragments read into a plan's merge list. The entry
|
|
3
|
+
* points that drive it are the statics of `Plan` in plan.ts, which imports this module; the
|
|
4
|
+
* `Plan` import below is a type import, so nothing here runs at import time and the pair is not a
|
|
5
|
+
* runtime cycle.
|
|
6
|
+
*/ import { getMappedArgumentValues, isThenable, PothosValidationError } from '@pothos/core';
|
|
7
|
+
import { getNamedType, isInterfaceType, isObjectType, Kind } from 'graphql';
|
|
8
|
+
import { EMPTY_MAPPING, unionMappings } from './loader-map.js';
|
|
9
|
+
import { collectSelectedFieldNames, findMatches, firstMatch, includeOf, isDeferred, isSkipped, matchesForModel, modelOf, normalizeInclude, resolveType } from './matches.js';
|
|
10
|
+
/** Collects a type's type-level selection, once, before its fields are walked. */ function enter(plan, type) {
|
|
11
|
+
const selection = plan.adapter.typeSelection(type);
|
|
12
|
+
if (selection) {
|
|
13
|
+
plan.collect({
|
|
14
|
+
kind: 'type',
|
|
15
|
+
query: selection
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Collects the type-level selection of `variant` when a fragment moves the plan from `type` to
|
|
21
|
+
* another type of the same model, so the variant's resolvers find what its selection promises.
|
|
22
|
+
* Whether the two selections can live in one node is decided when the plan is played.
|
|
23
|
+
*/ function enterVariant(plan, type, variant) {
|
|
24
|
+
const selection = plan.adapter.typeSelection(variant);
|
|
25
|
+
if (selection) {
|
|
26
|
+
plan.collect({
|
|
27
|
+
kind: 'variant',
|
|
28
|
+
type,
|
|
29
|
+
variant,
|
|
30
|
+
query: selection
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Walks every branch into `plan`. The types the selections are walked as, and the variants their
|
|
36
|
+
* fragments move to, are all collected before any field is, so type-level selections come first
|
|
37
|
+
* in the merge list and the plan does not depend on which occurrence of a field, or which path
|
|
38
|
+
* match, came first in the document.
|
|
39
|
+
*/ export function walkBranches(plan, branches) {
|
|
40
|
+
const resolved = branches.flatMap((branch)=>resolveBranch(plan, branch));
|
|
41
|
+
const enteredTypes = new Set();
|
|
42
|
+
let firstType;
|
|
43
|
+
for (const { type, selectionSets } of resolved){
|
|
44
|
+
// The plan is entered as the first type a match landed on, and every other one as a
|
|
45
|
+
// same-model variant of it, so two type-level selections that conflict are reported here
|
|
46
|
+
// exactly as they are when a fragment moves the plan between the same two types. A type two
|
|
47
|
+
// matches share is entered once.
|
|
48
|
+
if (!enteredTypes.has(type)) {
|
|
49
|
+
enteredTypes.add(type);
|
|
50
|
+
if (firstType) {
|
|
51
|
+
enterVariant(plan, firstType, type);
|
|
52
|
+
} else {
|
|
53
|
+
firstType = type;
|
|
54
|
+
enter(plan, type);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const entered = new Set();
|
|
58
|
+
for (const selections of selectionSets){
|
|
59
|
+
enterVariants(plan, type, selections, entered);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const { type, selectionSets, indirectPath } of resolved){
|
|
63
|
+
const walked = new Set();
|
|
64
|
+
for (const selections of selectionSets){
|
|
65
|
+
walkSelections(plan, type, selections, indirectPath, true, walked);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The selections `branch` stands for once its type's indirect include is followed, in the order
|
|
71
|
+
* they are walked. A type-level path yields one per match beneath the wrapper; a plain include
|
|
72
|
+
* re-types the plan; anything but an object or interface type yields nothing.
|
|
73
|
+
*/ function resolveBranch(plan, { type, fieldNodes, indirectPath, deferred }) {
|
|
74
|
+
// Every node selects the same field.
|
|
75
|
+
if (fieldNodes.length === 0 || fieldNodes[0].name.value.startsWith('__')) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
const { info, adapter } = plan;
|
|
79
|
+
const include = includeOf(type);
|
|
80
|
+
const beneath = [];
|
|
81
|
+
if (include?.paths?.length || include?.path?.length) {
|
|
82
|
+
for (const fieldNode of fieldNodes){
|
|
83
|
+
const matches = findMatches(info, type, fieldNode, include.paths ?? [
|
|
84
|
+
include.path
|
|
85
|
+
], {
|
|
86
|
+
path: indirectPath,
|
|
87
|
+
deferred
|
|
88
|
+
});
|
|
89
|
+
for (const match of matches){
|
|
90
|
+
beneath.push(...resolveBranch(plan, {
|
|
91
|
+
type: match.type,
|
|
92
|
+
fieldNodes: [
|
|
93
|
+
match.field
|
|
94
|
+
],
|
|
95
|
+
indirectPath: match.path,
|
|
96
|
+
deferred: match.deferred
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// The wrapper's own selection is planned only when the wrapper itself is backed by the model
|
|
101
|
+
// being queried (a variant that also points at a nested field). A plain wrapper, or one backed
|
|
102
|
+
// by another model, has nothing of its own to add to this query.
|
|
103
|
+
if (adapter.modelFor(type) !== plan.model) {
|
|
104
|
+
return beneath;
|
|
105
|
+
}
|
|
106
|
+
} else if (include) {
|
|
107
|
+
return resolveBranch(plan, {
|
|
108
|
+
type: info.schema.getType(include.getType()),
|
|
109
|
+
fieldNodes,
|
|
110
|
+
indirectPath,
|
|
111
|
+
deferred
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (!(isObjectType(type) || isInterfaceType(type))) {
|
|
115
|
+
return beneath;
|
|
116
|
+
}
|
|
117
|
+
// A deferred selection is entered but, when deferred fragments are skipped, not walked.
|
|
118
|
+
const selectionSets = deferred && plan.skipDeferredFragments ? [] : fieldNodes.flatMap((fieldNode)=>fieldNode.selectionSet ? [
|
|
119
|
+
fieldNode.selectionSet.selections
|
|
120
|
+
] : []);
|
|
121
|
+
return [
|
|
122
|
+
...beneath,
|
|
123
|
+
{
|
|
124
|
+
type,
|
|
125
|
+
selectionSets,
|
|
126
|
+
indirectPath
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Whether `fragment` was already expanded under `key` in the pass `visited` belongs to, recording
|
|
132
|
+
* it if not. A valid fragment DAG can spread the same fragment at every level, so expanding every
|
|
133
|
+
* spread is exponential in its depth. Inline fragments cannot repeat.
|
|
134
|
+
*/ function expandedBefore(visited, key, fragment) {
|
|
135
|
+
if (fragment.kind !== Kind.FRAGMENT_DEFINITION) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const id = `${key}:${fragment.name.value}`;
|
|
139
|
+
if (visited.has(id)) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
visited.add(id);
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* First pass: enters every same-model variant a fragment under `selections` moves the plan to,
|
|
147
|
+
* before any field is merged, so a conflict between two type-level selections is reported
|
|
148
|
+
* whichever order the fragments appear in and never depends on a field-level select.
|
|
149
|
+
*/ function enterVariants(plan, type, selections, visited) {
|
|
150
|
+
for (const selection of selections){
|
|
151
|
+
if (selection.kind === Kind.FIELD) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const fragment = applicableFragment(plan, selection);
|
|
155
|
+
if (!fragment || expandedBefore(visited, type.name, fragment)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const as = fragmentTypeOf(plan, type, fragment);
|
|
159
|
+
if (as && as !== type) {
|
|
160
|
+
enterVariant(plan, type, as);
|
|
161
|
+
}
|
|
162
|
+
enterVariants(plan, as ?? type, fragment.selectionSet.selections, visited);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Second pass: walks `selections` in document order, a fragment's fields where the fragment
|
|
167
|
+
* appears. Fields apply unless the enclosing fragment cannot apply to `type`; nested fragments
|
|
168
|
+
* are always classified against `type`, so one may narrow back to it.
|
|
169
|
+
*/ function walkSelections(plan, type, selections, indirectPath, fieldsApply, visited) {
|
|
170
|
+
for (const selection of selections){
|
|
171
|
+
if (selection.kind === Kind.FIELD) {
|
|
172
|
+
if (fieldsApply) {
|
|
173
|
+
walkField(plan, type, selection, indirectPath);
|
|
174
|
+
}
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const fragment = applicableFragment(plan, selection);
|
|
178
|
+
if (!fragment || expandedBefore(visited, `${type.name}:${fieldsApply}`, fragment)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const as = fragmentTypeOf(plan, type, fragment);
|
|
182
|
+
walkSelections(plan, as ?? type, fragment.selectionSet.selections, indirectPath, // An untyped fragment inherits; a typed one applies iff it can apply to `type`.
|
|
183
|
+
fragment.typeCondition ? as !== undefined : fieldsApply, visited);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The fragment a non-field selection stands for, or undefined when it does not apply: skipped by
|
|
188
|
+
* a directive, or deferred while the plan skips deferred fragments.
|
|
189
|
+
*/ function applicableFragment({ info, skipDeferredFragments }, selection) {
|
|
190
|
+
if (isSkipped(info, selection) || skipDeferredFragments && isDeferred(info, selection)) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
return selection.kind === Kind.FRAGMENT_SPREAD ? info.fragments[selection.name.value] : selection;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The type to walk `fragment` as while walking `type`, or undefined when the fragment cannot
|
|
197
|
+
* apply to `type` (its fields are suppressed; nested fragments are still classified against
|
|
198
|
+
* `type`). An untyped fragment inherits `type`. An object type accepts a fragment on itself or on
|
|
199
|
+
* an interface it implements, walked as itself: a plan on an object type is a plan on rows of that
|
|
200
|
+
* type, so a fragment on any other object type cannot apply to them. An interface accepts a
|
|
201
|
+
* fragment on another type of the same model, walked as that type, so that type's own selection
|
|
202
|
+
* is planned for the rows that resolve to it.
|
|
203
|
+
*/ function fragmentTypeOf(plan, type, fragment) {
|
|
204
|
+
if (!fragment.typeCondition) {
|
|
205
|
+
return type;
|
|
206
|
+
}
|
|
207
|
+
const condition = plan.info.schema.getType(fragment.typeCondition.name.value);
|
|
208
|
+
if (condition === type) {
|
|
209
|
+
return type;
|
|
210
|
+
}
|
|
211
|
+
if (isInterfaceType(condition) && type.getInterfaces().includes(condition)) {
|
|
212
|
+
return type;
|
|
213
|
+
}
|
|
214
|
+
if (isInterfaceType(type) && (isObjectType(condition) || isInterfaceType(condition)) && plan.adapter.modelFor(condition) === plan.adapter.modelFor(type)) {
|
|
215
|
+
return condition;
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
/** Collects what `fieldNode` (a field of `type`) selects. */ export function walkField(plan, type, fieldNode, indirectPath) {
|
|
220
|
+
const { info, context, adapter } = plan;
|
|
221
|
+
const name = fieldNode.name.value;
|
|
222
|
+
if (name.startsWith('__') || isSkipped(info, fieldNode)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const field = type.getFields()[name];
|
|
226
|
+
if (!field) {
|
|
227
|
+
throw new PothosValidationError(`Unknown field ${name} on ${type.name}`);
|
|
228
|
+
}
|
|
229
|
+
const selection = adapter.fieldSelection(field, type);
|
|
230
|
+
if (!selection) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const alias = fieldNode.alias?.value ?? name;
|
|
234
|
+
const key = `${type.name}@${indirectPath.length > 0 ? `${indirectPath.join('.')}.` : ''}${alias}`;
|
|
235
|
+
if (typeof selection !== 'function') {
|
|
236
|
+
collectField(plan, key, alias, selection, EMPTY_MAPPING);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// Where this field is, linked to where the plan it was found in hangs. One link, built once per
|
|
240
|
+
// select invocation; nothing walks it unless the adapter's callback asks.
|
|
241
|
+
const position = {
|
|
242
|
+
parent: plan.position,
|
|
243
|
+
type,
|
|
244
|
+
field,
|
|
245
|
+
node: fieldNode
|
|
246
|
+
};
|
|
247
|
+
// This invocation's mapping; every nested plan it makes records into `mapping.nested`, which
|
|
248
|
+
// stays invisible to the plan until the invocation's query is accepted.
|
|
249
|
+
const mapping = {
|
|
250
|
+
nested: {},
|
|
251
|
+
position
|
|
252
|
+
};
|
|
253
|
+
const args = getMappedArgumentValues(field, fieldNode, context, info);
|
|
254
|
+
const select = selection;
|
|
255
|
+
// The select runs as soon as its own arguments are known; only its merge waits.
|
|
256
|
+
const query = isThenable(args) ? args.then((mapped)=>runSelect(plan, select, mapped, position, mapping)) : runSelect(plan, select, args, position, mapping);
|
|
257
|
+
if (isThenable(query)) {
|
|
258
|
+
plan.chain(query, (resolved)=>collectField(plan, key, alias, resolved, mapping));
|
|
259
|
+
} else {
|
|
260
|
+
collectField(plan, key, alias, query, mapping);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function runSelect(plan, select, args, position, mapping) {
|
|
264
|
+
return select(args, plan.context, nestedSelectionFor(plan, args, position, mapping), selectedFieldNodeFor(plan, position), position);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A field the way the document names it, for an error message. The mapping key cannot say this:
|
|
268
|
+
* it holds the alias in place of the name, under the alias path of any indirect include above it.
|
|
269
|
+
*/ function fieldName({ type, node }) {
|
|
270
|
+
const name = `${type.name}.${node.name.value}`;
|
|
271
|
+
return node.alias ? `${name} (selected as "${node.alias.value}")` : name;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Collects a field's query with the mapping to record if a play takes it. A falsy query is
|
|
275
|
+
* collected as nothing, so the resolver loads its own data; whether the query fits, and so
|
|
276
|
+
* whether the mapping is ever recorded, is `play`'s decision.
|
|
277
|
+
*
|
|
278
|
+
* An invocation whose nested selection is still pending returned without awaiting it, so its
|
|
279
|
+
* query cannot hold what the nested plan will select and recording its mapping would claim data
|
|
280
|
+
* the query never loads. It is refused instead, and the pending plans (already handled, see
|
|
281
|
+
* `awaitNested`) are left to settle unobserved.
|
|
282
|
+
*/ function collectField(plan, key, alias, query, mapping) {
|
|
283
|
+
if (!query) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (mapping.pending) {
|
|
287
|
+
// Only a select invocation can be pending, and every one of those has a position.
|
|
288
|
+
throw new PothosValidationError(`The selection function of ${fieldName(mapping.position)} returned while a nested selection it started was still pending. Await nestedSelection() (or a helper built on it, such as getQuery) inside an async selection function.`);
|
|
289
|
+
}
|
|
290
|
+
plan.collect({
|
|
291
|
+
kind: 'field',
|
|
292
|
+
key,
|
|
293
|
+
alias,
|
|
294
|
+
query,
|
|
295
|
+
mapping
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/** The nested selection callback of one select invocation. */ function nestedSelectionFor(plan, args, position, mapping) {
|
|
299
|
+
const { adapter, context, info } = plan;
|
|
300
|
+
const { node: fieldNode } = position;
|
|
301
|
+
return (rawQuery, pathOrInclude, typeName)=>{
|
|
302
|
+
// A caller may already have started this promise before path/type validation runs.
|
|
303
|
+
let query = typeof rawQuery === 'function' || rawQuery === true ? undefined : rawQuery;
|
|
304
|
+
try {
|
|
305
|
+
const returnType = getNamedType(position.field.type);
|
|
306
|
+
const include = Array.isArray(pathOrInclude) ? normalizeInclude(pathOrInclude, resolveType(info.schema, returnType), typeName ? info.schema.getType(typeName) : undefined, info.schema) : pathOrInclude;
|
|
307
|
+
const target = include ? info.schema.getType(include.getType()) : returnType;
|
|
308
|
+
// `true` is the public "no query"; it never reaches an adapter.
|
|
309
|
+
query = rawQuery === true ? undefined : typeof rawQuery === 'function' ? rawQuery(args, context, position) : rawQuery;
|
|
310
|
+
if (!modelOf(adapter, info.schema, target)) {
|
|
311
|
+
// A model-less field (a scalar, a type without a model) has nothing beneath it to plan:
|
|
312
|
+
// the nested selection is the query alone, and nothing is recorded for it.
|
|
313
|
+
return query ?? {};
|
|
314
|
+
}
|
|
315
|
+
const child = plan.nested(target, position);
|
|
316
|
+
try {
|
|
317
|
+
if (isThenable(query)) {
|
|
318
|
+
child.chain(query, (resolved)=>mergeQuery(child, resolved));
|
|
319
|
+
} else {
|
|
320
|
+
mergeQuery(child, query);
|
|
321
|
+
}
|
|
322
|
+
const paths = include?.paths?.length ? include.paths : include?.path?.length ? [
|
|
323
|
+
include.path
|
|
324
|
+
] : undefined;
|
|
325
|
+
if (paths) {
|
|
326
|
+
// Each match is walked as its own type; the wrapper's selection set is not walked.
|
|
327
|
+
const matches = matchesForModel(adapter, info.schema, findMatches(info, returnType, fieldNode, paths, {
|
|
328
|
+
prefix: includeOf(returnType)?.path
|
|
329
|
+
}), target);
|
|
330
|
+
walkBranches(child, matches.map((match)=>({
|
|
331
|
+
// As `Plan.fromInfo` does for its own paths: a matched type with a model is walked
|
|
332
|
+
// with it, and one without (an interface, a wrapper) as the type asked for, so its
|
|
333
|
+
// fields are found and a fragment narrowing to it applies.
|
|
334
|
+
type: modelOf(adapter, info.schema, match.type) ? match.type : target,
|
|
335
|
+
fieldNodes: [
|
|
336
|
+
match.field
|
|
337
|
+
],
|
|
338
|
+
indirectPath: match.path,
|
|
339
|
+
deferred: match.deferred
|
|
340
|
+
})));
|
|
341
|
+
} else {
|
|
342
|
+
const asType = (type)=>({
|
|
343
|
+
type,
|
|
344
|
+
fieldNodes: [
|
|
345
|
+
fieldNode
|
|
346
|
+
],
|
|
347
|
+
indirectPath: [],
|
|
348
|
+
deferred: false
|
|
349
|
+
});
|
|
350
|
+
walkBranches(child, [
|
|
351
|
+
...target === returnType ? [] : [
|
|
352
|
+
asType(target)
|
|
353
|
+
],
|
|
354
|
+
asType(returnType)
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
} catch (error) {
|
|
358
|
+
child.abandon();
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
// A promise behind the declared synchronous type, as `finish` returns one.
|
|
362
|
+
return child.pending ? awaitNested(child, mapping) : queryNested(child, mapping);
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (isThenable(query)) {
|
|
365
|
+
query.then(()=>{}, ()=>{});
|
|
366
|
+
}
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The promise of a nested selection whose plan is async, counted against its invocation until it
|
|
373
|
+
* settles. Both outcomes clear the count, so an invocation can catch a failure and retry.
|
|
374
|
+
* Rejections are handled here so a discarded selection does not create an unhandled rejection.
|
|
375
|
+
* A failed child publishes no mappings; fields it did not load can fall back independently.
|
|
376
|
+
*/ function awaitNested(child, mapping) {
|
|
377
|
+
mapping.pending = (mapping.pending ?? 0) + 1;
|
|
378
|
+
const result = child.pending.then(()=>queryNested(child, mapping));
|
|
379
|
+
const settled = ()=>{
|
|
380
|
+
if (mapping.pending === 1) {
|
|
381
|
+
delete mapping.pending;
|
|
382
|
+
} else {
|
|
383
|
+
mapping.pending -= 1;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
result.then(settled, settled);
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* The nested plan played where the callback needs it serialized, with the mappings it recorded
|
|
391
|
+
* folded into the invocation that started it. Every nested plan of one invocation records into
|
|
392
|
+
* the same `mapping.nested`, so two that map the same key union.
|
|
393
|
+
*/ function queryNested(child, mapping) {
|
|
394
|
+
const played = child.play();
|
|
395
|
+
// Serialization can throw. Publish mappings only once the caller can use the query.
|
|
396
|
+
const query = child.adapter.toQuery(played.root);
|
|
397
|
+
for (const key of Object.keys(played.mappings)){
|
|
398
|
+
mapping.nested[key] = unionMappings(mapping.nested[key], played.mappings[key]);
|
|
399
|
+
}
|
|
400
|
+
return query;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* The relation query of a nested selection, merged before the walk beneath it whether the
|
|
404
|
+
* callback answered at once or resolved after that walk had already collected its fields — see
|
|
405
|
+
* `collectQuery`. A field of the document that conflicts with the query therefore loses to it
|
|
406
|
+
* either way, and is never mapped to a relation the query loaded with other arguments.
|
|
407
|
+
*/ function mergeQuery(child, query) {
|
|
408
|
+
if (query) {
|
|
409
|
+
child.collectQuery(query);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* The first field node selected at `path` beneath the field, seen through any wrapper on the
|
|
414
|
+
* field's return type (an errors plugin result, for instance), whose own path leads to the type
|
|
415
|
+
* the caller's path starts from. An empty path yields the field node itself, or the wrapper's
|
|
416
|
+
* inner node.
|
|
417
|
+
*
|
|
418
|
+
* A node selected only under a `@defer` is returned like any other, whatever the plan's deferred
|
|
419
|
+
* setting says — an adapter gating a computed value on this over-reports rather than under-;
|
|
420
|
+
* `eachSelectedField` in matches.ts says why that direction is the safe one.
|
|
421
|
+
*/ function selectedFieldNodeFor(plan, { field, node: fieldNode }) {
|
|
422
|
+
const { info } = plan;
|
|
423
|
+
let names;
|
|
424
|
+
function getSelection(path) {
|
|
425
|
+
if (path === undefined) {
|
|
426
|
+
names ??= collectSelectedFieldNames(info, getNamedType(field.type), [
|
|
427
|
+
fieldNode
|
|
428
|
+
]);
|
|
429
|
+
return names;
|
|
430
|
+
}
|
|
431
|
+
const returnType = getNamedType(field.type);
|
|
432
|
+
const match = firstMatch(info, returnType, fieldNode, path.map((name)=>({
|
|
433
|
+
name
|
|
434
|
+
})), {
|
|
435
|
+
prefix: includeOf(returnType)?.path
|
|
436
|
+
});
|
|
437
|
+
return match?.field ?? null;
|
|
438
|
+
}
|
|
439
|
+
return getSelection;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
//# sourceMappingURL=walk.js.map
|
package/esm/walk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/walk.ts"],"names":["getMappedArgumentValues","isThenable","PothosValidationError","getNamedType","isInterfaceType","isObjectType","Kind","EMPTY_MAPPING","unionMappings","collectSelectedFieldNames","findMatches","firstMatch","includeOf","isDeferred","isSkipped","matchesForModel","modelOf","normalizeInclude","resolveType","enter","plan","type","selection","adapter","typeSelection","collect","kind","query","enterVariant","variant","walkBranches","branches","resolved","flatMap","branch","resolveBranch","enteredTypes","Set","firstType","selectionSets","has","add","entered","selections","enterVariants","indirectPath","walked","walkSelections","fieldNodes","deferred","length","name","value","startsWith","info","include","beneath","paths","path","fieldNode","matches","match","push","field","modelFor","model","schema","getType","skipDeferredFragments","selectionSet","expandedBefore","visited","key","fragment","FRAGMENT_DEFINITION","id","FIELD","applicableFragment","as","fragmentTypeOf","fieldsApply","walkField","typeCondition","undefined","FRAGMENT_SPREAD","fragments","condition","getInterfaces","includes","context","getFields","fieldSelection","alias","join","collectField","position","parent","node","mapping","nested","args","select","then","mapped","runSelect","chain","nestedSelectionFor","selectedFieldNodeFor","fieldName","pending","rawQuery","pathOrInclude","typeName","returnType","Array","isArray","target","child","mergeQuery","prefix","map","asType","error","abandon","awaitNested","queryNested","result","settled","played","play","toQuery","root","Object","keys","mappings","collectQuery","names","getSelection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J,SAASC,aAAa/E,IAAe;QACnC,IAAIA,SAASyB,WAAW;YACtBqD,UAAU/H,0BAA0B6C,MAAMnD,aAAa4D,MAAM1C,IAAI,GAAG;gBAACsC;aAAU;YAC/E,OAAO6E;QACT;QACA,MAAMvB,aAAa9G,aAAa4D,MAAM1C,IAAI;QAC1C,MAAMwC,QAAQlD,WACZ2C,MACA2D,YACAtD,WACAD,KAAK8D,GAAG,CAAC,CAACrE,OAAU,CAAA;gBAAEA;YAAK,CAAA,IAC3B;YAAEoE,QAAQ3G,UAAUqG,aAAavD;QAAK;QAGxC,OAAOG,OAAOE,SAAS;IACzB;IAEA,OAAO0E;AACT"}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ORM boundary: what an adapter tells the traversal, and where the selections it produces
|
|
3
|
+
* accumulate. One class, so an adapter's state and helpers have a home and the members it has
|
|
4
|
+
* nothing to say about are inherited rather than checked for.
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "Adapter", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return Adapter;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
class Adapter {
|
|
16
|
+
/**
|
|
17
|
+
* Whether a fragment under `@defer` is walked. `EntryOptions.skipDeferredFragments` overrides
|
|
18
|
+
* it for one entry point.
|
|
19
|
+
*/ skipDeferredFragments = true;
|
|
20
|
+
/**
|
|
21
|
+
* Whether merging `query` into `node` would leave everything already selected as it is. A yes
|
|
22
|
+
* or no; `firstConflict` is the version that names a key. Inherited: nothing ever conflicts.
|
|
23
|
+
*/ canMergeQuery(_node, _query, _options) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The first key of a type-level `query` that conflicts with what `node` holds, for the error
|
|
28
|
+
* message that names it. Inherited: none.
|
|
29
|
+
*/ firstConflict(_node, _query) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `mergeQuery` from another node: everything `from` holds, merged into `node`. Inherited: the
|
|
34
|
+
* round trip through `toQuery`.
|
|
35
|
+
*/ mergeNode(node, from) {
|
|
36
|
+
this.mergeQuery(node, this.toQuery(from));
|
|
37
|
+
}
|
|
38
|
+
/** `canMergeQuery` node to node. Inherited: the round trip through `toQuery`. */ canMergeNode(node, from) {
|
|
39
|
+
return this.canMergeQuery(node, this.toQuery(from));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"names":["Adapter","skipDeferredFragments","canMergeQuery","_node","_query","_options","firstConflict","undefined","mergeNode","node","from","mergeQuery","toQuery","canMergeNode"],"mappings":"AAAA;;;;CAIC;;;;+BA4BqBA;;;eAAAA;;;AAAf,MAAeA;IACpB;;;GAGC,GACDC,wBAAwB,KAAK;IA8B7B;;;GAGC,GACDC,cAAcC,KAAe,EAAEC,MAAa,EAAEC,QAAuB,EAAW;QAC9E,OAAO;IACT;IAEA;;;GAGC,GACDC,cAAcH,KAAe,EAAEC,MAAa,EAAiC;QAC3E,OAAOG;IACT;IAEA;;;GAGC,GACDC,UAAUC,IAAc,EAAEC,IAAc,EAAQ;QAC9C,IAAI,CAACC,UAAU,CAACF,MAAM,IAAI,CAACG,OAAO,CAACF;IACrC;IAEA,+EAA+E,GAC/EG,aAAaJ,IAAc,EAAEC,IAAc,EAAW;QACpD,OAAO,IAAI,CAACR,aAAa,CAACO,MAAM,IAAI,CAACG,OAAO,CAACF;IAC/C;AACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural equality for query arguments (`where`, `orderBy`, `take`, ...). Keys holding
|
|
3
|
+
* `undefined` are treated as absent, so `{ where: cond ? filter : undefined }` compares equal to
|
|
4
|
+
* `{}` when the condition is false.
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "deepEqual", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return deepEqual;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
function deepEqual(left, right) {
|
|
16
|
+
if (left === right) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
20
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
21
|
+
if (!Array.isArray(left) || !Array.isArray(right)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const { length } = left;
|
|
25
|
+
if (right.length !== length) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for(let i = 0; i < length; i += 1){
|
|
29
|
+
if (!deepEqual(left[i], right[i])) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const lValue = left.valueOf?.();
|
|
36
|
+
const rValue = right.valueOf?.();
|
|
37
|
+
// A boxed value (a Date, a boxed primitive) compares by its primitive, whichever side it is
|
|
38
|
+
// on: a plain object's `valueOf` returns the object itself, and a null-prototype object has
|
|
39
|
+
// none at all, so neither is mistaken for one.
|
|
40
|
+
if (lValue != null && typeof lValue !== 'object' || rValue != null && typeof rValue !== 'object') {
|
|
41
|
+
return lValue === rValue;
|
|
42
|
+
}
|
|
43
|
+
const keys = comparedKeys(left);
|
|
44
|
+
if (keys.length !== comparedKeys(right).length) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
for (const key of keys){
|
|
48
|
+
if (!deepEqual(left[key], right[key])) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
function comparedKeys(value) {
|
|
57
|
+
return Object.keys(value).filter((key)=>value[key] !== undefined);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=deep-equal.js.map
|
|
@@ -0,0 +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;;;;+BACeA;;;eAAAA;;;AAAT,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"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the ORM plugins use: the `Plan` class with the two entry points on it, the `Adapter`
|
|
3
|
+
* classes their own adapters extend, and the loader-map, usage and equality helpers their
|
|
4
|
+
* adapters and loaders call. Everything else is module-private; see the README.
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
function _export(target, all) {
|
|
10
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_export(exports, {
|
|
16
|
+
get Adapter () {
|
|
17
|
+
return _adapter.Adapter;
|
|
18
|
+
},
|
|
19
|
+
get NodeAdapter () {
|
|
20
|
+
return _node.NodeAdapter;
|
|
21
|
+
},
|
|
22
|
+
get Plan () {
|
|
23
|
+
return _plan.Plan;
|
|
24
|
+
},
|
|
25
|
+
get cacheKey () {
|
|
26
|
+
return _loadermap.cacheKey;
|
|
27
|
+
},
|
|
28
|
+
get deepEqual () {
|
|
29
|
+
return _deepequal.deepEqual;
|
|
30
|
+
},
|
|
31
|
+
get getLoaderMapping () {
|
|
32
|
+
return _loadermap.getLoaderMapping;
|
|
33
|
+
},
|
|
34
|
+
get selectedFieldNames () {
|
|
35
|
+
return _matches.selectedFieldNames;
|
|
36
|
+
},
|
|
37
|
+
get setFieldMapping () {
|
|
38
|
+
return _loadermap.setFieldMapping;
|
|
39
|
+
},
|
|
40
|
+
get setLoaderMappings () {
|
|
41
|
+
return _loadermap.setLoaderMappings;
|
|
42
|
+
},
|
|
43
|
+
get setRowFieldMapping () {
|
|
44
|
+
return _loadermap.setRowFieldMapping;
|
|
45
|
+
},
|
|
46
|
+
get setRowMappings () {
|
|
47
|
+
return _loadermap.setRowMappings;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const _adapter = require("./adapter.js");
|
|
51
|
+
const _deepequal = require("./deep-equal.js");
|
|
52
|
+
const _loadermap = require("./loader-map.js");
|
|
53
|
+
const _matches = require("./matches.js");
|
|
54
|
+
const _node = require("./node.js");
|
|
55
|
+
const _plan = require("./plan.js");
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["Adapter","NodeAdapter","Plan","cacheKey","deepEqual","getLoaderMapping","selectedFieldNames","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings"],"mappings":"AAAA;;;;CAIC;;;;;;;;;;;QACQA;eAAAA,gBAAO;;QAiBIC;eAAAA,iBAAW;;QACtBC;eAAAA,UAAI;;QAfXC;eAAAA,mBAAQ;;QAFDC;eAAAA,oBAAS;;QAGhBC;eAAAA,2BAAgB;;QAWhBC;eAAAA,2BAAkB;;QATlBC;eAAAA,0BAAe;;QACfC;eAAAA,4BAAiB;;QACjBC;eAAAA,6BAAkB;;QAClBC;eAAAA,yBAAc;;;yBATQ;2BACE;2BASnB;yBAMA;sBACmD;sBACpB"}
|