@graphql-codegen/visitor-plugin-common 7.1.1 → 7.1.2
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.
|
@@ -373,7 +373,31 @@ class SelectionSetToObject {
|
|
|
373
373
|
}
|
|
374
374
|
return prev;
|
|
375
375
|
}, []);
|
|
376
|
-
|
|
376
|
+
// Top-level INLINE_FRAGMENT / FRAGMENT_SPREAD nodes among the
|
|
377
|
+
// inlined selections cannot be consumed directly by
|
|
378
|
+
// `buildSelectionSet`, which only handles FIELD and DIRECTIVE
|
|
379
|
+
// kinds for AST nodes and throws "Unexpected type." otherwise.
|
|
380
|
+
// Route them through `flattenSelectionSet` — which already
|
|
381
|
+
// expands inline fragments and fragment spreads per type — and
|
|
382
|
+
// merge the FIELD-only result with the already-FIELD selections
|
|
383
|
+
// before handing off.
|
|
384
|
+
const directNodes = [];
|
|
385
|
+
const nestedSelections = [];
|
|
386
|
+
for (const n of flattenedSelectionNodes) {
|
|
387
|
+
if ('kind' in n &&
|
|
388
|
+
(n.kind === graphql_1.Kind.INLINE_FRAGMENT || n.kind === graphql_1.Kind.FRAGMENT_SPREAD)) {
|
|
389
|
+
nestedSelections.push(n);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
directNodes.push(n);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (nestedSelections.length) {
|
|
396
|
+
const { selectionNodesByTypeName: nestedByType } = this.flattenSelectionSet(nestedSelections, schemaType);
|
|
397
|
+
const nestedForThisType = nestedByType.get(typeName) ?? [];
|
|
398
|
+
directNodes.push(...nestedForThisType);
|
|
399
|
+
}
|
|
400
|
+
collectGrouped(directNodes);
|
|
377
401
|
}
|
|
378
402
|
if (incrementalDirectivesFound) {
|
|
379
403
|
for (const incrementalNode of selectionNodes) {
|
|
@@ -369,7 +369,31 @@ export class SelectionSetToObject {
|
|
|
369
369
|
}
|
|
370
370
|
return prev;
|
|
371
371
|
}, []);
|
|
372
|
-
|
|
372
|
+
// Top-level INLINE_FRAGMENT / FRAGMENT_SPREAD nodes among the
|
|
373
|
+
// inlined selections cannot be consumed directly by
|
|
374
|
+
// `buildSelectionSet`, which only handles FIELD and DIRECTIVE
|
|
375
|
+
// kinds for AST nodes and throws "Unexpected type." otherwise.
|
|
376
|
+
// Route them through `flattenSelectionSet` — which already
|
|
377
|
+
// expands inline fragments and fragment spreads per type — and
|
|
378
|
+
// merge the FIELD-only result with the already-FIELD selections
|
|
379
|
+
// before handing off.
|
|
380
|
+
const directNodes = [];
|
|
381
|
+
const nestedSelections = [];
|
|
382
|
+
for (const n of flattenedSelectionNodes) {
|
|
383
|
+
if ('kind' in n &&
|
|
384
|
+
(n.kind === Kind.INLINE_FRAGMENT || n.kind === Kind.FRAGMENT_SPREAD)) {
|
|
385
|
+
nestedSelections.push(n);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
directNodes.push(n);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (nestedSelections.length) {
|
|
392
|
+
const { selectionNodesByTypeName: nestedByType } = this.flattenSelectionSet(nestedSelections, schemaType);
|
|
393
|
+
const nestedForThisType = nestedByType.get(typeName) ?? [];
|
|
394
|
+
directNodes.push(...nestedForThisType);
|
|
395
|
+
}
|
|
396
|
+
collectGrouped(directNodes);
|
|
373
397
|
}
|
|
374
398
|
if (incrementalDirectivesFound) {
|
|
375
399
|
for (const incrementalNode of selectionNodes) {
|