@graphql-codegen/visitor-plugin-common 7.2.2 → 7.2.3-alpha-20260727134316-0680bb167a9e79a645f8adf39f73f7cfe2044b4d
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.
|
@@ -360,22 +360,33 @@ class SelectionSetToObject {
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
if (conditionalDirectivesFound) {
|
|
363
|
-
|
|
364
|
-
//
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
363
|
+
const flattenedSelectionNodes = [];
|
|
364
|
+
// A conditional FragmentSpreadUsage is handled one of two ways.
|
|
365
|
+
for (const conditionalNode of selectionNodes) {
|
|
366
|
+
// 1. Fragment masking: preserve the mask as an optional `Partial`
|
|
367
|
+
// ref rather than inlining the fragment's fields.
|
|
368
|
+
if (this._config.inlineFragmentTypes === 'mask' &&
|
|
369
|
+
'fragmentName' in conditionalNode) {
|
|
370
|
+
const { fields: partialFields, dependentTypes: partialDependentTypes } = this.buildSelectionSet(schemaType, [conditionalNode], {
|
|
371
|
+
partialTypes: true,
|
|
372
|
+
parentFieldName: parentName,
|
|
373
|
+
});
|
|
374
|
+
prev[typeName].push(this.selectionSetStringFromFields(partialFields));
|
|
375
|
+
dependentTypes.push(...partialDependentTypes);
|
|
376
|
+
continue;
|
|
370
377
|
}
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
|
|
378
|
+
// 2. Otherwise (`combine` / conditional inline-fragment fields):
|
|
379
|
+
// treat it like an Inline Fragment - inline the fields so
|
|
380
|
+
// `buildSelectionSet` can make each one optional. Note: each field
|
|
381
|
+
// carries `fragmentDirectives` containing `@skip`/`@include`.
|
|
382
|
+
if ('kind' in conditionalNode) {
|
|
383
|
+
flattenedSelectionNodes.push(conditionalNode);
|
|
384
|
+
continue;
|
|
376
385
|
}
|
|
377
|
-
|
|
378
|
-
|
|
386
|
+
for (const fragmentSpreadUsageSelectionNode of conditionalNode.selectionNodes) {
|
|
387
|
+
flattenedSelectionNodes.push(fragmentSpreadUsageSelectionNode);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
379
390
|
// Top-level INLINE_FRAGMENT / FRAGMENT_SPREAD nodes among the
|
|
380
391
|
// inlined selections cannot be consumed directly by
|
|
381
392
|
// `buildSelectionSet`, which only handles FIELD and DIRECTIVE
|
|
@@ -690,7 +701,17 @@ class SelectionSetToObject {
|
|
|
690
701
|
}
|
|
691
702
|
else if (this._config.inlineFragmentTypes === 'mask') {
|
|
692
703
|
fields.push(`{ ' $fragmentRefs'?: { ${fragmentsSpreadUsages
|
|
693
|
-
.map(name =>
|
|
704
|
+
.map(name => {
|
|
705
|
+
// A conditional (`@skip`/`@include`) masked spread may be absent,
|
|
706
|
+
// so its data is wrapped in `Partial`.
|
|
707
|
+
if (options.partialTypes) {
|
|
708
|
+
return `'${name}': Partial<${name}>`;
|
|
709
|
+
}
|
|
710
|
+
if (options.unsetTypes) {
|
|
711
|
+
return `'${name}': Incremental<${name}>`;
|
|
712
|
+
}
|
|
713
|
+
return `'${name}': ${name}`;
|
|
714
|
+
})
|
|
694
715
|
.join(`;`)} } }`);
|
|
695
716
|
}
|
|
696
717
|
}
|
|
@@ -356,22 +356,33 @@ export class SelectionSetToObject {
|
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
if (conditionalDirectivesFound) {
|
|
359
|
-
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
359
|
+
const flattenedSelectionNodes = [];
|
|
360
|
+
// A conditional FragmentSpreadUsage is handled one of two ways.
|
|
361
|
+
for (const conditionalNode of selectionNodes) {
|
|
362
|
+
// 1. Fragment masking: preserve the mask as an optional `Partial`
|
|
363
|
+
// ref rather than inlining the fragment's fields.
|
|
364
|
+
if (this._config.inlineFragmentTypes === 'mask' &&
|
|
365
|
+
'fragmentName' in conditionalNode) {
|
|
366
|
+
const { fields: partialFields, dependentTypes: partialDependentTypes } = this.buildSelectionSet(schemaType, [conditionalNode], {
|
|
367
|
+
partialTypes: true,
|
|
368
|
+
parentFieldName: parentName,
|
|
369
|
+
});
|
|
370
|
+
prev[typeName].push(this.selectionSetStringFromFields(partialFields));
|
|
371
|
+
dependentTypes.push(...partialDependentTypes);
|
|
372
|
+
continue;
|
|
366
373
|
}
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
//
|
|
370
|
-
|
|
371
|
-
|
|
374
|
+
// 2. Otherwise (`combine` / conditional inline-fragment fields):
|
|
375
|
+
// treat it like an Inline Fragment - inline the fields so
|
|
376
|
+
// `buildSelectionSet` can make each one optional. Note: each field
|
|
377
|
+
// carries `fragmentDirectives` containing `@skip`/`@include`.
|
|
378
|
+
if ('kind' in conditionalNode) {
|
|
379
|
+
flattenedSelectionNodes.push(conditionalNode);
|
|
380
|
+
continue;
|
|
372
381
|
}
|
|
373
|
-
|
|
374
|
-
|
|
382
|
+
for (const fragmentSpreadUsageSelectionNode of conditionalNode.selectionNodes) {
|
|
383
|
+
flattenedSelectionNodes.push(fragmentSpreadUsageSelectionNode);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
375
386
|
// Top-level INLINE_FRAGMENT / FRAGMENT_SPREAD nodes among the
|
|
376
387
|
// inlined selections cannot be consumed directly by
|
|
377
388
|
// `buildSelectionSet`, which only handles FIELD and DIRECTIVE
|
|
@@ -686,7 +697,17 @@ export class SelectionSetToObject {
|
|
|
686
697
|
}
|
|
687
698
|
else if (this._config.inlineFragmentTypes === 'mask') {
|
|
688
699
|
fields.push(`{ ' $fragmentRefs'?: { ${fragmentsSpreadUsages
|
|
689
|
-
.map(name =>
|
|
700
|
+
.map(name => {
|
|
701
|
+
// A conditional (`@skip`/`@include`) masked spread may be absent,
|
|
702
|
+
// so its data is wrapped in `Partial`.
|
|
703
|
+
if (options.partialTypes) {
|
|
704
|
+
return `'${name}': Partial<${name}>`;
|
|
705
|
+
}
|
|
706
|
+
if (options.unsetTypes) {
|
|
707
|
+
return `'${name}': Incremental<${name}>`;
|
|
708
|
+
}
|
|
709
|
+
return `'${name}': ${name}`;
|
|
710
|
+
})
|
|
690
711
|
.join(`;`)} } }`);
|
|
691
712
|
}
|
|
692
713
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3-alpha-20260727134316-0680bb167a9e79a645f8adf39f73f7cfe2044b4d",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
6
6
|
},
|
|
@@ -75,6 +75,7 @@ export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig =
|
|
|
75
75
|
protected selectionSetStringFromFields(fields: (string | NameAndType)[]): string | null;
|
|
76
76
|
protected buildSelectionSet(parentSchemaType: GraphQLObjectType, selectionNodes: Array<GroupedTypeNameNode>, options: {
|
|
77
77
|
unsetTypes?: boolean;
|
|
78
|
+
partialTypes?: boolean;
|
|
78
79
|
parentFieldName?: string;
|
|
79
80
|
}): {
|
|
80
81
|
typeInfo: {
|
|
@@ -75,6 +75,7 @@ export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig =
|
|
|
75
75
|
protected selectionSetStringFromFields(fields: (string | NameAndType)[]): string | null;
|
|
76
76
|
protected buildSelectionSet(parentSchemaType: GraphQLObjectType, selectionNodes: Array<GroupedTypeNameNode>, options: {
|
|
77
77
|
unsetTypes?: boolean;
|
|
78
|
+
partialTypes?: boolean;
|
|
78
79
|
parentFieldName?: string;
|
|
79
80
|
}): {
|
|
80
81
|
typeInfo: {
|