@pothos/selection-mapper 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +16 -6
- package/dts/deep-equal.d.ts +4 -0
- package/dts/deep-equal.d.ts.map +1 -1
- package/dts/errors.d.ts +7 -0
- package/dts/errors.d.ts.map +1 -0
- package/dts/index.d.ts +3 -2
- package/dts/index.d.ts.map +1 -1
- package/dts/loader-map.d.ts +37 -16
- package/dts/loader-map.d.ts.map +1 -1
- package/dts/matches.d.ts +5 -0
- package/dts/matches.d.ts.map +1 -1
- package/dts/parent-types.d.ts +9 -0
- package/dts/parent-types.d.ts.map +1 -0
- package/dts/plan.d.ts +36 -20
- package/dts/plan.d.ts.map +1 -1
- package/dts/shape.d.ts +8 -0
- package/dts/shape.d.ts.map +1 -0
- package/dts/types.d.ts +21 -1
- package/dts/types.d.ts.map +1 -1
- package/dts/walk.d.ts +20 -2
- package/dts/walk.d.ts.map +1 -1
- package/esm/deep-equal.d.ts +4 -0
- package/esm/deep-equal.d.ts.map +1 -1
- package/esm/deep-equal.js +60 -28
- package/esm/deep-equal.js.map +1 -1
- package/esm/errors.d.ts +7 -0
- package/esm/errors.d.ts.map +1 -0
- package/esm/errors.js +11 -0
- package/esm/errors.js.map +1 -0
- package/esm/index.d.ts +3 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/loader-map.d.ts +37 -16
- package/esm/loader-map.d.ts.map +1 -1
- package/esm/loader-map.js +165 -99
- package/esm/loader-map.js.map +1 -1
- package/esm/matches.d.ts +5 -0
- package/esm/matches.d.ts.map +1 -1
- package/esm/matches.js +11 -3
- package/esm/matches.js.map +1 -1
- package/esm/parent-types.d.ts +9 -0
- package/esm/parent-types.d.ts.map +1 -0
- package/esm/parent-types.js +24 -0
- package/esm/parent-types.js.map +1 -0
- package/esm/plan.d.ts +36 -20
- package/esm/plan.d.ts.map +1 -1
- package/esm/plan.js +107 -71
- package/esm/plan.js.map +1 -1
- package/esm/shape.d.ts +8 -0
- package/esm/shape.d.ts.map +1 -0
- package/esm/shape.js +94 -0
- package/esm/shape.js.map +1 -0
- package/esm/types.d.ts +21 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/walk.d.ts +20 -2
- package/esm/walk.d.ts.map +1 -1
- package/esm/walk.js +199 -71
- package/esm/walk.js.map +1 -1
- package/lib/deep-equal.js +60 -28
- package/lib/deep-equal.js.map +1 -1
- package/lib/errors.js +18 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.js +13 -3
- package/lib/index.js.map +1 -1
- package/lib/loader-map.js +145 -90
- package/lib/loader-map.js.map +1 -1
- package/lib/matches.js +14 -3
- package/lib/matches.js.map +1 -1
- package/lib/parent-types.js +29 -0
- package/lib/parent-types.js.map +1 -0
- package/lib/plan.js +107 -71
- package/lib/plan.js.map +1 -1
- package/lib/shape.js +109 -0
- package/lib/shape.js.map +1 -0
- package/lib/walk.js +186 -68
- package/lib/walk.js.map +1 -1
- package/package.json +4 -3
- package/src/deep-equal.ts +77 -34
- package/src/errors.ts +12 -0
- package/src/index.ts +6 -1
- package/src/loader-map.ts +235 -125
- package/src/matches.ts +15 -3
- package/src/parent-types.ts +33 -0
- package/src/plan.ts +145 -78
- package/src/shape.ts +126 -0
- package/src/types.ts +25 -1
- package/src/walk.ts +250 -83
package/lib/walk.js
CHANGED
|
@@ -23,8 +23,41 @@ _export(exports, {
|
|
|
23
23
|
});
|
|
24
24
|
const _core = require("@pothos/core");
|
|
25
25
|
const _graphql = require("graphql");
|
|
26
|
+
const _errors = require("./errors.js");
|
|
26
27
|
const _loadermap = require("./loader-map.js");
|
|
27
28
|
const _matches = require("./matches.js");
|
|
29
|
+
const _shape = require("./shape.js");
|
|
30
|
+
/**
|
|
31
|
+
* What defines a field, to tell an implementation's copy of an interface field from an override.
|
|
32
|
+
* Pothos builds every implementation's copy of an inherited field from the interface's own field
|
|
33
|
+
* options, so those agree exactly when the field was not redefined, the way plugin-prisma-next
|
|
34
|
+
* names slots and every plugin's resolver accepts an interface's mapping. A field built elsewhere
|
|
35
|
+
* has no options, and only an identical select function says the same.
|
|
36
|
+
*
|
|
37
|
+
* `Adapter.fieldSelection` is handed the walked type and may vary a selection by it. Only a select
|
|
38
|
+
* function is ever moved to the interface, and the adapters vary only a static selection by type
|
|
39
|
+
* (prisma-next's empty selection for an interface field without one), so a select function is
|
|
40
|
+
* taken to depend on the field's definition alone.
|
|
41
|
+
*/ function definitionOf(field, selection) {
|
|
42
|
+
return field.extensions?.pothosOptions ?? selection;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The position of one select invocation. Its own link is exact for that invocation, and reading
|
|
46
|
+
* further up is what ties a walk to the invocations above it, so `parent` tells the plan.
|
|
47
|
+
*/ function positionIn(plan, type, field, node) {
|
|
48
|
+
return {
|
|
49
|
+
get parent () {
|
|
50
|
+
plan.positionRead = true;
|
|
51
|
+
return plan.position;
|
|
52
|
+
},
|
|
53
|
+
get walkParent () {
|
|
54
|
+
return plan.position;
|
|
55
|
+
},
|
|
56
|
+
type,
|
|
57
|
+
field,
|
|
58
|
+
node
|
|
59
|
+
};
|
|
60
|
+
}
|
|
28
61
|
/** Collects a type's type-level selection, once, before its fields are walked. */ function enter(plan, type) {
|
|
29
62
|
const selection = plan.adapter.typeSelection(type);
|
|
30
63
|
if (selection) {
|
|
@@ -69,13 +102,14 @@ function walkBranches(plan, branches) {
|
|
|
69
102
|
}
|
|
70
103
|
const entered = new Set();
|
|
71
104
|
for (const selections of selectionSets){
|
|
72
|
-
enterVariants(plan, type, selections, entered);
|
|
105
|
+
enterVariants(plan, type, type, selections, entered);
|
|
73
106
|
}
|
|
74
107
|
}
|
|
108
|
+
const invocations = new Set();
|
|
75
109
|
for (const { type, selectionSets, indirectPath } of resolved){
|
|
76
110
|
const walked = new Set();
|
|
77
111
|
for (const selections of selectionSets){
|
|
78
|
-
walkSelections(plan, type, selections, indirectPath, true, walked);
|
|
112
|
+
walkSelections(plan, type, selections, indirectPath, true, walked, invocations);
|
|
79
113
|
}
|
|
80
114
|
}
|
|
81
115
|
}
|
|
@@ -90,12 +124,11 @@ function walkBranches(plan, branches) {
|
|
|
90
124
|
}
|
|
91
125
|
const { info, adapter } = plan;
|
|
92
126
|
const include = (0, _matches.includeOf)(type);
|
|
127
|
+
const paths = include && (0, _matches.includePaths)(include);
|
|
93
128
|
const beneath = [];
|
|
94
|
-
if (
|
|
129
|
+
if (paths) {
|
|
95
130
|
for (const fieldNode of fieldNodes){
|
|
96
|
-
const matches = (0, _matches.findMatches)(info, type, fieldNode,
|
|
97
|
-
include.path
|
|
98
|
-
], {
|
|
131
|
+
const matches = (0, _matches.findMatches)(info, type, fieldNode, paths, {
|
|
99
132
|
path: indirectPath,
|
|
100
133
|
deferred
|
|
101
134
|
});
|
|
@@ -141,10 +174,10 @@ function walkBranches(plan, branches) {
|
|
|
141
174
|
];
|
|
142
175
|
}
|
|
143
176
|
/**
|
|
144
|
-
* Whether `fragment` was already
|
|
145
|
-
* it if not. A valid fragment DAG can spread the same fragment at every level, so
|
|
177
|
+
* Whether `fragment` was already visited under `key` in the pass `visited` belongs to, recording
|
|
178
|
+
* it if not. A valid fragment DAG can spread the same fragment at every level, so visiting every
|
|
146
179
|
* spread is exponential in its depth. Inline fragments cannot repeat.
|
|
147
|
-
*/ function
|
|
180
|
+
*/ function visitedBefore(visited, key, fragment) {
|
|
148
181
|
if (fragment.kind !== _graphql.Kind.FRAGMENT_DEFINITION) {
|
|
149
182
|
return false;
|
|
150
183
|
}
|
|
@@ -159,43 +192,69 @@ function walkBranches(plan, branches) {
|
|
|
159
192
|
* First pass: enters every same-model variant a fragment under `selections` moves the plan to,
|
|
160
193
|
* before any field is merged, so a conflict between two type-level selections is reported
|
|
161
194
|
* whichever order the fragments appear in and never depends on a field-level select.
|
|
162
|
-
|
|
195
|
+
*
|
|
196
|
+
* `selections` are walked as `type`, and variants are entered relative to `origin`, the type the
|
|
197
|
+
* plan was last entered as. They differ only under a fragment that did not move the plan, such as
|
|
198
|
+
* an expansion that selects no fields of its own: it narrows the walk to the implementations it
|
|
199
|
+
* covers without entering them, so a nested fragment that selects fields enters the variant
|
|
200
|
+
* instead.
|
|
201
|
+
*/ function enterVariants(plan, origin, type, selections, visited) {
|
|
163
202
|
for (const selection of selections){
|
|
164
203
|
if (selection.kind === _graphql.Kind.FIELD) {
|
|
165
204
|
continue;
|
|
166
205
|
}
|
|
167
206
|
const fragment = applicableFragment(plan, selection);
|
|
168
|
-
if (!fragment ||
|
|
207
|
+
if (!fragment || visitedBefore(visited, `${origin.name}>${type.name}`, fragment)) {
|
|
169
208
|
continue;
|
|
170
209
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
210
|
+
const { types, isExpansion } = fragmentTypesOf(plan, type, fragment);
|
|
211
|
+
// A typed fragment directly under `origin` moves the plan to its type. An expansion, an
|
|
212
|
+
// untyped fragment, or one nested under a fragment that did not move the plan, moves it only
|
|
213
|
+
// when it selects fields of its own.
|
|
214
|
+
const enters = types.length > 0 && (fragment.typeCondition && !isExpansion && type === origin || selectsFields(plan.info, fragment.selectionSet.selections));
|
|
215
|
+
for (const as of types.length > 0 ? types : [
|
|
216
|
+
type
|
|
217
|
+
]){
|
|
218
|
+
if (enters && as !== origin) {
|
|
219
|
+
enterVariant(plan, origin, as);
|
|
220
|
+
}
|
|
221
|
+
enterVariants(plan, enters ? as : origin, as, fragment.selectionSet.selections, visited);
|
|
174
222
|
}
|
|
175
|
-
enterVariants(plan, as ?? type, fragment.selectionSet.selections, visited);
|
|
176
223
|
}
|
|
177
224
|
}
|
|
178
225
|
/**
|
|
179
226
|
* Second pass: walks `selections` in document order, a fragment's fields where the fragment
|
|
180
227
|
* appears. Fields apply unless the enclosing fragment cannot apply to `type`; nested fragments
|
|
181
228
|
* are always classified against `type`, so one may narrow back to it.
|
|
182
|
-
*/ function walkSelections(plan, type, selections, indirectPath, fieldsApply, visited) {
|
|
229
|
+
*/ function walkSelections(plan, type, selections, indirectPath, fieldsApply, visited, invocations, expandedFrom) {
|
|
183
230
|
for (const selection of selections){
|
|
184
231
|
if (selection.kind === _graphql.Kind.FIELD) {
|
|
185
232
|
if (fieldsApply) {
|
|
186
|
-
walkField(plan, type, selection, indirectPath);
|
|
233
|
+
walkField(plan, type, selection, indirectPath, invocations, expandedFrom);
|
|
187
234
|
}
|
|
188
235
|
continue;
|
|
189
236
|
}
|
|
190
237
|
const fragment = applicableFragment(plan, selection);
|
|
191
|
-
if (!fragment ||
|
|
238
|
+
if (!fragment || visitedBefore(visited, `${type.name}:${fieldsApply}:${expandedFrom?.name}`, fragment)) {
|
|
192
239
|
continue;
|
|
193
240
|
}
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
241
|
+
const { types, isExpansion } = fragmentTypesOf(plan, type, fragment);
|
|
242
|
+
for (const as of types.length > 0 ? types : [
|
|
243
|
+
type
|
|
244
|
+
]){
|
|
245
|
+
walkSelections(plan, as, fragment.selectionSet.selections, indirectPath, // An untyped fragment inherits; a typed one applies iff it can apply to `type`.
|
|
246
|
+
fragment.typeCondition ? types.length > 0 : fieldsApply, visited, invocations, isExpansion ? type : expandedFrom && keptBy(plan, expandedFrom, fragment));
|
|
247
|
+
}
|
|
197
248
|
}
|
|
198
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* `expandedFrom` while fields under `fragment` still name it: the fragment is untyped, on
|
|
252
|
+
* `expandedFrom` or an interface it implements, or expands it again. A fragment narrowing to one
|
|
253
|
+
* type names its fields on that type.
|
|
254
|
+
*/ function keptBy(plan, expandedFrom, fragment) {
|
|
255
|
+
const { types, isExpansion } = fragmentTypesOf(plan, expandedFrom, fragment);
|
|
256
|
+
return isExpansion || types[0] === expandedFrom ? expandedFrom : undefined;
|
|
257
|
+
}
|
|
199
258
|
/**
|
|
200
259
|
* The fragment a non-field selection stands for, or undefined when it does not apply: skipped by
|
|
201
260
|
* a directive, or deferred while the plan skips deferred fragments.
|
|
@@ -206,57 +265,108 @@ function walkBranches(plan, branches) {
|
|
|
206
265
|
return selection.kind === _graphql.Kind.FRAGMENT_SPREAD ? info.fragments[selection.name.value] : selection;
|
|
207
266
|
}
|
|
208
267
|
/**
|
|
209
|
-
* The
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
|
|
268
|
+
* The types to walk `fragment` as while walking `type`, or none when the fragment cannot apply to
|
|
269
|
+
* `type` (its fields are suppressed; nested fragments are still classified against `type`). An
|
|
270
|
+
* untyped fragment inherits `type`. A type accepts a fragment on itself or on an interface it
|
|
271
|
+
* implements, walked as itself: a plan on an object type is a plan on rows of that type, so a
|
|
272
|
+
* fragment on any other object type cannot apply to them. An interface also accepts a fragment
|
|
273
|
+
* on another type of the same model, walked as that type, so that type's own selection is planned
|
|
274
|
+
* for the rows that resolve to it. A fragment on an abstract type of no model (`... on Node`
|
|
275
|
+
* beneath a model interface), or of another model, is an expansion. It is walked as each
|
|
276
|
+
* implementation of `type` it covers, so the variants' type-level selections are planned for their
|
|
277
|
+
* rows and the fields it selects load with the parent query. When those selections conflict, the
|
|
278
|
+
* play throws, as it does for two same-model fragments.
|
|
279
|
+
*/ function fragmentTypesOf(plan, type, fragment) {
|
|
217
280
|
if (!fragment.typeCondition) {
|
|
218
|
-
return
|
|
281
|
+
return {
|
|
282
|
+
types: [
|
|
283
|
+
type
|
|
284
|
+
],
|
|
285
|
+
isExpansion: false
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const { schema } = plan.info;
|
|
289
|
+
const condition = schema.getType(fragment.typeCondition.name.value);
|
|
290
|
+
if (isOfType(type, condition)) {
|
|
291
|
+
return {
|
|
292
|
+
types: [
|
|
293
|
+
type
|
|
294
|
+
],
|
|
295
|
+
isExpansion: false
|
|
296
|
+
};
|
|
219
297
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
298
|
+
if (!(0, _graphql.isInterfaceType)(type)) {
|
|
299
|
+
return {
|
|
300
|
+
types: [],
|
|
301
|
+
isExpansion: false
|
|
302
|
+
};
|
|
223
303
|
}
|
|
224
|
-
|
|
225
|
-
|
|
304
|
+
const model = plan.adapter.modelFor(type);
|
|
305
|
+
if (((0, _graphql.isObjectType)(condition) || (0, _graphql.isInterfaceType)(condition)) && plan.adapter.modelFor(condition) === model) {
|
|
306
|
+
return {
|
|
307
|
+
types: [
|
|
308
|
+
condition
|
|
309
|
+
],
|
|
310
|
+
isExpansion: false
|
|
311
|
+
};
|
|
226
312
|
}
|
|
227
|
-
if ((0, _graphql.
|
|
228
|
-
return
|
|
313
|
+
if ((0, _graphql.isAbstractType)(condition)) {
|
|
314
|
+
return {
|
|
315
|
+
types: schema.getPossibleTypes(type).filter((possible)=>schema.isSubType(condition, possible) && plan.adapter.modelFor(possible) === model),
|
|
316
|
+
isExpansion: plan.adapter.modelFor(condition) !== model
|
|
317
|
+
};
|
|
229
318
|
}
|
|
230
|
-
return
|
|
319
|
+
return {
|
|
320
|
+
types: [],
|
|
321
|
+
isExpansion: false
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/** Whether `type` is `condition` itself or implements it. */ function isOfType(type, condition) {
|
|
325
|
+
return condition === type || (0, _graphql.isInterfaceType)(condition) && type.getInterfaces().includes(condition);
|
|
231
326
|
}
|
|
232
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Whether `selections` select a field directly; `__typename` reads nothing from the row, and a
|
|
329
|
+
* skipped field never runs.
|
|
330
|
+
*/ function selectsFields(info, selections) {
|
|
331
|
+
return selections.some((selection)=>selection.kind === _graphql.Kind.FIELD && !selection.name.value.startsWith('__') && !(0, _matches.isSkipped)(info, selection));
|
|
332
|
+
}
|
|
333
|
+
function walkField(plan, walkedType, fieldNode, indirectPath, invocations, expandedFrom) {
|
|
233
334
|
const { info, context, adapter } = plan;
|
|
234
335
|
const name = fieldNode.name.value;
|
|
235
336
|
if (name.startsWith('__') || (0, _matches.isSkipped)(info, fieldNode)) {
|
|
236
337
|
return;
|
|
237
338
|
}
|
|
238
|
-
const
|
|
239
|
-
if (!
|
|
240
|
-
throw
|
|
339
|
+
const walkedField = walkedType.getFields()[name];
|
|
340
|
+
if (!walkedField) {
|
|
341
|
+
throw (0, _errors.unexpectedError)(`Unknown field ${name} on ${walkedType.name}`);
|
|
241
342
|
}
|
|
242
|
-
const selection = adapter.fieldSelection(
|
|
343
|
+
const selection = adapter.fieldSelection(walkedField, walkedType);
|
|
243
344
|
if (!selection) {
|
|
244
345
|
return;
|
|
245
346
|
}
|
|
246
347
|
const alias = fieldNode.alias?.value ?? name;
|
|
247
|
-
const
|
|
348
|
+
const relative = `${indirectPath.length > 0 ? `${indirectPath.join('.')}.` : ''}${alias}`;
|
|
248
349
|
if (typeof selection !== 'function') {
|
|
249
|
-
collectField(plan,
|
|
350
|
+
collectField(plan, `${walkedType.name}@${relative}`, alias, selection, _loadermap.EMPTY_MAPPING);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const inherited = expandedFrom?.getFields()[name];
|
|
354
|
+
const [type, field] = expandedFrom && inherited && definitionOf(inherited, adapter.fieldSelection(inherited, expandedFrom)) === definitionOf(walkedField, selection) ? [
|
|
355
|
+
expandedFrom,
|
|
356
|
+
inherited
|
|
357
|
+
] : [
|
|
358
|
+
walkedType,
|
|
359
|
+
walkedField
|
|
360
|
+
];
|
|
361
|
+
const key = `${type.name}@${relative}`;
|
|
362
|
+
const place = `${(0, _shape.fieldShape)(info, fieldNode)}:${key}`;
|
|
363
|
+
if (invocations?.has(place)) {
|
|
250
364
|
return;
|
|
251
365
|
}
|
|
366
|
+
invocations?.add(place);
|
|
252
367
|
// Where this field is, linked to where the plan it was found in hangs. One link, built once per
|
|
253
368
|
// select invocation; nothing walks it unless the adapter's callback asks.
|
|
254
|
-
const position =
|
|
255
|
-
parent: plan.position,
|
|
256
|
-
type,
|
|
257
|
-
field,
|
|
258
|
-
node: fieldNode
|
|
259
|
-
};
|
|
369
|
+
const position = positionIn(plan, type, field, fieldNode);
|
|
260
370
|
// This invocation's mapping; every nested plan it makes records into `mapping.nested`, which
|
|
261
371
|
// stays invisible to the plan until the invocation's query is accepted.
|
|
262
372
|
const mapping = {
|
|
@@ -298,7 +408,7 @@ function runSelect(plan, select, args, position, mapping) {
|
|
|
298
408
|
}
|
|
299
409
|
if (mapping.pending) {
|
|
300
410
|
// Only a select invocation can be pending, and every one of those has a position.
|
|
301
|
-
throw
|
|
411
|
+
throw (0, _errors.unexpectedError)(`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.`);
|
|
302
412
|
}
|
|
303
413
|
plan.collect({
|
|
304
414
|
kind: 'field',
|
|
@@ -316,7 +426,7 @@ function runSelect(plan, select, args, position, mapping) {
|
|
|
316
426
|
let query = typeof rawQuery === 'function' || rawQuery === true ? undefined : rawQuery;
|
|
317
427
|
try {
|
|
318
428
|
const returnType = (0, _graphql.getNamedType)(position.field.type);
|
|
319
|
-
const include = Array.isArray(pathOrInclude) ? (
|
|
429
|
+
const include = Array.isArray(pathOrInclude) ? includeForPath(pathOrInclude, (0, _matches.resolveType)(info.schema, returnType), typeName ? info.schema.getType(typeName) : undefined, info.schema) : pathOrInclude;
|
|
320
430
|
const target = include ? info.schema.getType(include.getType()) : returnType;
|
|
321
431
|
// `true` is the public "no query"; it never reaches an adapter.
|
|
322
432
|
query = rawQuery === true ? undefined : typeof rawQuery === 'function' ? rawQuery(args, context, position) : rawQuery;
|
|
@@ -325,22 +435,18 @@ function runSelect(plan, select, args, position, mapping) {
|
|
|
325
435
|
// the nested selection is the query alone, and nothing is recorded for it.
|
|
326
436
|
return query ?? {};
|
|
327
437
|
}
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
const paths = include?.paths?.length ? include.paths : include?.path?.length ? [
|
|
336
|
-
include.path
|
|
337
|
-
] : undefined;
|
|
438
|
+
const paths = include && (0, _matches.includePaths)(include);
|
|
439
|
+
// Everything a walk beneath this field node reads: the shape of its selection set, not the
|
|
440
|
+
// node, so a fragment spread beneath many fields is walked once. The paths are data: an
|
|
441
|
+
// include's segments are names and type names.
|
|
442
|
+
const walkKey = `${(0, _shape.selectionShape)(info, fieldNode.selectionSet)}:${returnType.name}:${target.name}:${paths ? JSON.stringify(paths) : ''}`;
|
|
443
|
+
const child = plan.nested(target, position, walkKey, (walked)=>{
|
|
338
444
|
if (paths) {
|
|
339
445
|
// Each match is walked as its own type; the wrapper's selection set is not walked.
|
|
340
446
|
const matches = (0, _matches.matchesForModel)(adapter, info.schema, (0, _matches.findMatches)(info, returnType, fieldNode, paths, {
|
|
341
447
|
prefix: (0, _matches.includeOf)(returnType)?.path
|
|
342
448
|
}), target);
|
|
343
|
-
walkBranches(
|
|
449
|
+
walkBranches(walked, matches.map((match)=>({
|
|
344
450
|
// As `Plan.fromInfo` does for its own paths: a matched type with a model is walked
|
|
345
451
|
// with it, and one without (an interface, a wrapper) as the type asked for, so its
|
|
346
452
|
// fields are found and a fragment narrowing to it applies.
|
|
@@ -360,16 +466,18 @@ function runSelect(plan, select, args, position, mapping) {
|
|
|
360
466
|
indirectPath: [],
|
|
361
467
|
deferred: false
|
|
362
468
|
});
|
|
363
|
-
walkBranches(
|
|
469
|
+
walkBranches(walked, [
|
|
364
470
|
...target === returnType ? [] : [
|
|
365
471
|
asType(target)
|
|
366
472
|
],
|
|
367
473
|
asType(returnType)
|
|
368
474
|
]);
|
|
369
475
|
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
476
|
+
});
|
|
477
|
+
if ((0, _core.isThenable)(query)) {
|
|
478
|
+
child.chain(query, (resolved)=>mergeQuery(child, resolved));
|
|
479
|
+
} else {
|
|
480
|
+
mergeQuery(child, query);
|
|
373
481
|
}
|
|
374
482
|
// A promise behind the declared synchronous type, as `finish` returns one.
|
|
375
483
|
return child.pending ? awaitNested(child, mapping) : queryNested(child, mapping);
|
|
@@ -381,6 +489,16 @@ function runSelect(plan, select, args, position, mapping) {
|
|
|
381
489
|
}
|
|
382
490
|
};
|
|
383
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* `normalizeInclude` for a path an app's select passed while a request is planned. A path that
|
|
494
|
+
* doesn't fit the field's type is an error in the app, which clients see as `Unexpected error.`.
|
|
495
|
+
*/ function includeForPath(...args) {
|
|
496
|
+
try {
|
|
497
|
+
return (0, _matches.normalizeInclude)(...args);
|
|
498
|
+
} catch (error) {
|
|
499
|
+
throw (0, _errors.unexpectedError)(error.message);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
384
502
|
/**
|
|
385
503
|
* The promise of a nested selection whose plan is async, counted against its invocation until it
|
|
386
504
|
* settles. Both outcomes clear the count, so an invocation can catch a failure and retry.
|
package/lib/walk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/walk.ts"],"names":["walkBranches","walkField","enter","plan","type","selection","adapter","typeSelection","collect","kind","query","enterVariant","variant","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","includeOf","beneath","paths","path","fieldNode","matches","findMatches","match","push","field","modelFor","model","schema","getType","isObjectType","isInterfaceType","skipDeferredFragments","selectionSet","expandedBefore","visited","key","fragment","Kind","FRAGMENT_DEFINITION","id","FIELD","applicableFragment","as","fragmentTypeOf","fieldsApply","typeCondition","undefined","isSkipped","isDeferred","FRAGMENT_SPREAD","fragments","condition","getInterfaces","includes","context","getFields","PothosValidationError","fieldSelection","alias","join","collectField","EMPTY_MAPPING","position","parent","node","mapping","nested","args","getMappedArgumentValues","select","isThenable","then","mapped","runSelect","chain","nestedSelectionFor","selectedFieldNodeFor","fieldName","pending","rawQuery","pathOrInclude","typeName","returnType","getNamedType","Array","isArray","normalizeInclude","resolveType","target","modelOf","child","mergeQuery","matchesForModel","prefix","map","asType","error","abandon","awaitNested","queryNested","result","settled","played","play","toQuery","root","Object","keys","mappings","unionMappings","collectQuery","names","getSelection","collectSelectedFieldNames","firstMatch"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAqGeA;eAAAA;;QAmQAC;eAAAA;;;sBAlWT;yBAYA;2BAEoD;yBAYpD;AAaP,gFAAgF,GAChF,SAASC,MACPC,IAAkC,EAClCC,IAAsB;IAEtB,MAAMC,YAAYF,KAAKG,OAAO,CAACC,aAAa,CAACH;IAE7C,IAAIC,WAAW;QACbF,KAAKK,OAAO,CAAC;YAAEC,MAAM;YAAQC,OAAOL;QAAU;IAChD;AACF;AAEA;;;;CAIC,GACD,SAASM,aACPR,IAAkC,EAClCC,IAAgB,EAChBQ,OAAmB;IAEnB,MAAMP,YAAYF,KAAKG,OAAO,CAACC,aAAa,CAACK;IAE7C,IAAIP,WAAW;QACbF,KAAKK,OAAO,CAAC;YAAEC,MAAM;YAAWL;YAAMQ;YAASF,OAAOL;QAAU;IAClE;AACF;AA6BO,SAASL,aACdG,IAAkC,EAClCU,QAAkB;IAElB,MAAMC,WAAWD,SAASE,OAAO,CAAC,CAACC,SAAWC,cAAcd,MAAMa;IAClE,MAAME,eAAe,IAAIC;IACzB,IAAIC;IAEJ,KAAK,MAAM,EAAEhB,IAAI,EAAEiB,aAAa,EAAE,IAAIP,SAAU;QAC9C,oFAAoF;QACpF,yFAAyF;QACzF,4FAA4F;QAC5F,iCAAiC;QACjC,IAAI,CAACI,aAAaI,GAAG,CAAClB,OAAO;YAC3Bc,aAAaK,GAAG,CAACnB;YAEjB,IAAIgB,WAAW;gBACbT,aAAaR,MAAMiB,WAAWhB;YAChC,OAAO;gBACLgB,YAAYhB;gBACZF,MAAMC,MAAMC;YACd;QACF;QAEA,MAAMoB,UAAU,IAAIL;QAEpB,KAA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;;CAKC,GACD,SAASwG,WACPD,KAAmC,EACnCvG,KAA+B;IAE/B,IAAIA,OAAO;QACTuG,MAAMoB,YAAY,CAAC3H;IACrB;AACF;AAEA;;;;;;;;;CASC,GACD,SAASyF,qBACPhG,IAAkC,EAClC,EAAE4C,KAAK,EAAEwC,MAAM7C,SAAS,EAAY;IAEpC,MAAM,EAAEN,IAAI,EAAE,GAAGjC;IACjB,IAAImI;IAIJ,SAASC,aAAa9F,IAAe;QACnC,IAAIA,SAAS4B,WAAW;YACtBiE,UAAUE,IAAAA,kCAAyB,EAACpG,MAAMsE,IAAAA,qBAAY,EAAC3D,MAAM3C,IAAI,GAAG;gBAACsC;aAAU;YAC/E,OAAO4F;QACT;QACA,MAAM7B,aAAaC,IAAAA,qBAAY,EAAC3D,MAAM3C,IAAI;QAC1C,MAAMyC,QAAQ4F,IAAAA,mBAAU,EACtBrG,MACAqE,YACA/D,WACAD,KAAK4E,GAAG,CAAC,CAACpF,OAAU,CAAA;gBAAEA;YAAK,CAAA,IAC3B;YAAEmF,QAAQ9E,IAAAA,kBAAS,EAACmE,aAAahE;QAAK;QAGxC,OAAOI,OAAOE,SAAS;IACzB;IAEA,OAAOwF;AACT"}
|
|
1
|
+
{"version":3,"sources":["../src/walk.ts"],"names":["walkBranches","walkField","definitionOf","field","selection","extensions","pothosOptions","positionIn","plan","type","node","parent","positionRead","position","walkParent","enter","adapter","typeSelection","collect","kind","query","enterVariant","variant","branches","resolved","flatMap","branch","resolveBranch","enteredTypes","Set","firstType","selectionSets","has","add","entered","selections","enterVariants","invocations","indirectPath","walked","walkSelections","fieldNodes","deferred","length","name","value","startsWith","info","include","includeOf","paths","includePaths","beneath","fieldNode","matches","findMatches","path","match","push","modelFor","model","schema","getType","isObjectType","isInterfaceType","skipDeferredFragments","selectionSet","visitedBefore","visited","key","fragment","Kind","FRAGMENT_DEFINITION","id","origin","FIELD","applicableFragment","types","isExpansion","fragmentTypesOf","enters","typeCondition","selectsFields","as","fieldsApply","expandedFrom","keptBy","undefined","isSkipped","isDeferred","FRAGMENT_SPREAD","fragments","condition","isOfType","isAbstractType","getPossibleTypes","filter","possible","isSubType","getInterfaces","includes","some","walkedType","context","walkedField","getFields","unexpectedError","fieldSelection","alias","relative","join","collectField","EMPTY_MAPPING","inherited","place","fieldShape","mapping","nested","args","getMappedArgumentValues","select","isThenable","then","mapped","runSelect","chain","nestedSelectionFor","selectedFieldNodeFor","fieldName","pending","rawQuery","pathOrInclude","typeName","returnType","getNamedType","Array","isArray","includeForPath","resolveType","target","modelOf","walkKey","selectionShape","JSON","stringify","child","matchesForModel","prefix","map","asType","mergeQuery","awaitNested","queryNested","error","normalizeInclude","message","result","settled","played","play","toQuery","root","Object","keys","mappings","unionMappings","collectQuery","names","getSelection","collectSelectedFieldNames","firstMatch"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAsJeA;eAAAA;;QA8VAC;eAAAA;;;sBAnfuD;yBAchE;wBAEyB;2BAC2B;yBAapD;uBAEoC;AAoB3C;;;;;;;;;;;CAWC,GACD,SAASC,aAAaC,KAAwB,EAAEC,SAAkB;IAChE,OAAOD,MAAME,UAAU,EAAEC,iBAAiBF;AAC5C;AAEA;;;CAGC,GACD,SAASG,WACPC,IAA6D,EAC7DC,IAAgB,EAChBN,KAAwB,EACxBO,IAAe;IAEf,OAAO;QACL,IAAIC,UAAS;YACXH,KAAKI,YAAY,GAAG;YAEpB,OAAOJ,KAAKK,QAAQ;QACtB;QACA,IAAIC,cAAa;YACf,OAAON,KAAKK,QAAQ;QACtB;QACAJ;QACAN;QACAO;IACF;AACF;AAEA,gFAAgF,GAChF,SAASK,MACPP,IAAkC,EAClCC,IAAsB;IAEtB,MAAML,YAAYI,KAAKQ,OAAO,CAACC,aAAa,CAACR;IAE7C,IAAIL,WAAW;QACbI,KAAKU,OAAO,CAAC;YAAEC,MAAM;YAAQC,OAAOhB;QAAU;IAChD;AACF;AAEA;;;;CAIC,GACD,SAASiB,aACPb,IAAkC,EAClCC,IAAg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AAA,qBAAY,EAACnI,MAAMM,IAAI,GAAG;gBAAC4C;aAAU;YAC/E,OAAOkH;QACT;QACA,MAAMlC,aAAaC,IAAAA,qBAAY,EAACnI,MAAMM,IAAI;QAC1C,MAAMgD,QAAQiH,IAAAA,mBAAU,EACtB3H,MACAsF,YACAhF,WACAG,KAAK4F,GAAG,CAAC,CAACxG,OAAU,CAAA;gBAAEA;YAAK,CAAA,IAC3B;YAAEuG,QAAQlG,IAAAA,kBAAS,EAACoF,aAAa7E;QAAK;QAGxC,OAAOC,OAAOtD,SAAS;IACzB;IAEA,OAAOqK;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pothos/selection-mapper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "shared selection-to-query walker for Pothos ORM plugins",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dts/index.d.ts",
|
|
@@ -37,11 +37,12 @@
|
|
|
37
37
|
"graphql": "^16.10.0 || ^17.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@graphql-tools/executor": "^1.5.2",
|
|
40
41
|
"graphql": "^17.0.1",
|
|
41
42
|
"graphql-tag": "^2.12.6",
|
|
42
43
|
"vitest": "^4.1.4",
|
|
43
|
-
"@pothos/core": "4.
|
|
44
|
-
"@pothos/test-utils": "2.
|
|
44
|
+
"@pothos/core": "4.17.0",
|
|
45
|
+
"@pothos/test-utils": "2.3.0"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
48
|
"type": "tsc --project tsconfig.type.json",
|
package/src/deep-equal.ts
CHANGED
|
@@ -2,66 +2,109 @@
|
|
|
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
|
*/
|
|
6
10
|
export function deepEqual(left: unknown, right: unknown): boolean {
|
|
7
11
|
if (left === right) {
|
|
8
12
|
return true;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
if (left && right && typeof left === 'object' && typeof right === 'object') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
if (!(left && right && typeof left === 'object' && typeof right === 'object')) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
20
|
+
if (!Array.isArray(left) || !Array.isArray(right)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
const { length } = left;
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
if (right.length !== length) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < length; i += 1) {
|
|
31
|
+
if (!deepEqual(left[i], right[i])) {
|
|
20
32
|
return false;
|
|
21
33
|
}
|
|
34
|
+
}
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Two objects of `Object.prototype`, the common case, need no further check.
|
|
40
|
+
if (
|
|
41
|
+
Object.getPrototypeOf(left) !== Object.prototype ||
|
|
42
|
+
Object.getPrototypeOf(right) !== Object.prototype
|
|
43
|
+
) {
|
|
44
|
+
const leftPlain = isPlain(left);
|
|
45
|
+
|
|
46
|
+
if (leftPlain !== isPlain(right)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
28
49
|
|
|
29
|
-
|
|
50
|
+
if (!leftPlain) {
|
|
51
|
+
return instancesEqual(left, right);
|
|
30
52
|
}
|
|
53
|
+
}
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
const rValue = right.valueOf?.();
|
|
55
|
+
const keys = comparedKeys(left as Record<string, unknown>);
|
|
34
56
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
if (keys.length !== definedKeyCount(right as Record<string, unknown>)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (const key of keys) {
|
|
38
62
|
if (
|
|
39
|
-
(
|
|
40
|
-
(rValue != null && typeof rValue !== 'object')
|
|
63
|
+
!deepEqual((left as Record<string, unknown>)[key], (right as Record<string, unknown>)[key])
|
|
41
64
|
) {
|
|
42
|
-
return
|
|
65
|
+
return false;
|
|
43
66
|
}
|
|
67
|
+
}
|
|
44
68
|
|
|
45
|
-
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
46
71
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
72
|
+
function isPlain(value: object) {
|
|
73
|
+
const proto = Object.getPrototypeOf(value);
|
|
50
74
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
!deepEqual((left as Record<string, unknown>)[key], (right as Record<string, unknown>)[key])
|
|
54
|
-
) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
75
|
+
return proto === null || proto === Object.prototype;
|
|
76
|
+
}
|
|
58
77
|
|
|
59
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The shared prototype keeps the comparison symmetric, since Temporal's `equals` also accepts
|
|
80
|
+
* property bags and strings.
|
|
81
|
+
*/
|
|
82
|
+
function instancesEqual(left: object, right: object) {
|
|
83
|
+
if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (left instanceof Date) {
|
|
88
|
+
return left.getTime() === (right as Date).getTime();
|
|
60
89
|
}
|
|
61
90
|
|
|
62
|
-
|
|
91
|
+
const { equals } = left as { equals?: unknown };
|
|
92
|
+
|
|
93
|
+
return typeof equals === 'function' && equals.call(left, right) === true;
|
|
63
94
|
}
|
|
64
95
|
|
|
65
96
|
function comparedKeys(value: Record<string, unknown>) {
|
|
66
97
|
return Object.keys(value).filter((key) => value[key] !== undefined);
|
|
67
98
|
}
|
|
99
|
+
|
|
100
|
+
function definedKeyCount(value: Record<string, unknown>) {
|
|
101
|
+
let count = 0;
|
|
102
|
+
|
|
103
|
+
for (const key of Object.keys(value)) {
|
|
104
|
+
if (value[key] !== undefined) {
|
|
105
|
+
count += 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return count;
|
|
110
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PothosValidationError } from '@pothos/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An error raised while a request runs for a problem in the app's schema or code. Clients see only
|
|
5
|
+
* `Unexpected error.`; `detail` is the message of its `cause`, which responses leave out.
|
|
6
|
+
*/
|
|
7
|
+
export function unexpectedError(detail: string) {
|
|
8
|
+
const error = new PothosValidationError('Unexpected error.');
|
|
9
|
+
error.cause = new PothosValidationError(detail);
|
|
10
|
+
|
|
11
|
+
return error;
|
|
12
|
+
}
|