@graphql-codegen/visitor-plugin-common 6.0.0-alpha-20250608134954-abd8276c8c3ea60547bf2b0dabfd58c20bc69065 → 6.0.0-alpha-20250609130245-016484a10b6d41d848d7b0967ce8929c5b0ccdc8
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.
|
@@ -96,12 +96,9 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
96
96
|
shouldInclude: namedType => !(0, graphql_1.isEnumType)(namedType),
|
|
97
97
|
onNotMappedObjectType: ({ typeName, initialType }) => {
|
|
98
98
|
let result = initialType;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
if (federationReferenceTypes) {
|
|
104
|
-
result += ` | ${federationReferenceTypes}`;
|
|
99
|
+
const referenceSelectionSetsString = this._federation.getMeta()[typeName]?.referenceSelectionSetsString;
|
|
100
|
+
if (referenceSelectionSetsString) {
|
|
101
|
+
result += ` | ${this.convertName('FederationReferenceTypes')}['${typeName}']`;
|
|
105
102
|
}
|
|
106
103
|
return result;
|
|
107
104
|
},
|
|
@@ -474,6 +471,27 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
474
471
|
})
|
|
475
472
|
.join('\n')).string;
|
|
476
473
|
}
|
|
474
|
+
buildFederationReferenceTypes() {
|
|
475
|
+
const federationMeta = this._federation.getMeta();
|
|
476
|
+
if (Object.keys(federationMeta).length === 0) {
|
|
477
|
+
return '';
|
|
478
|
+
}
|
|
479
|
+
const declarationKind = 'type';
|
|
480
|
+
return new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
481
|
+
.export()
|
|
482
|
+
.asKind(declarationKind)
|
|
483
|
+
.withName(this.convertName('FederationReferenceTypes'))
|
|
484
|
+
.withComment('Mapping of federation reference types')
|
|
485
|
+
.withBlock(Object.entries(federationMeta)
|
|
486
|
+
.map(([typeName, { referenceSelectionSetsString }]) => {
|
|
487
|
+
if (!referenceSelectionSetsString) {
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
return (0, utils_js_1.indent)(`${typeName}: ${referenceSelectionSetsString}${this.getPunctuation(declarationKind)}`);
|
|
491
|
+
})
|
|
492
|
+
.filter(v => v)
|
|
493
|
+
.join('\n')).string;
|
|
494
|
+
}
|
|
477
495
|
get schema() {
|
|
478
496
|
return this._schema;
|
|
479
497
|
}
|
|
@@ -683,12 +701,6 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
683
701
|
argsType = this.applyOptionalFields(argsType, original.arguments);
|
|
684
702
|
}
|
|
685
703
|
}
|
|
686
|
-
const parentTypeSignature = this._federation.transformFieldParentType({
|
|
687
|
-
fieldNode: original,
|
|
688
|
-
parentType,
|
|
689
|
-
parentTypeSignature: this.getParentTypeForSignature(node),
|
|
690
|
-
federationTypeSignature: 'FederationType',
|
|
691
|
-
});
|
|
692
704
|
const { mappedTypeKey, resolverType } = (() => {
|
|
693
705
|
const baseType = (0, utils_js_1.getBaseTypeNode)(original.type);
|
|
694
706
|
const realType = baseType.name.value;
|
|
@@ -722,15 +734,16 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
722
734
|
name: typeName,
|
|
723
735
|
modifier: avoidResolverOptionals ? '' : '?',
|
|
724
736
|
type: resolverType,
|
|
725
|
-
genericTypes: [mappedTypeKey,
|
|
737
|
+
genericTypes: [mappedTypeKey, this.getParentTypeForSignature(node), contextType, argsType].filter(f => f),
|
|
726
738
|
};
|
|
727
739
|
if (this._federation.isResolveReferenceField(node)) {
|
|
728
740
|
if (!this._federation.getMeta()[parentType.name].hasResolveReference) {
|
|
729
741
|
return { value: '', meta };
|
|
730
742
|
}
|
|
743
|
+
const resultType = `${mappedTypeKey} | FederationReferenceType`;
|
|
744
|
+
const referenceType = 'FederationReferenceType';
|
|
731
745
|
signature.type = 'ReferenceResolver';
|
|
732
|
-
signature.genericTypes = [
|
|
733
|
-
meta.federation = { isResolveReference: true };
|
|
746
|
+
signature.genericTypes = [resultType, referenceType, contextType];
|
|
734
747
|
}
|
|
735
748
|
return {
|
|
736
749
|
value: (0, utils_js_1.indent)(`${signature.name}${signature.modifier}: ${signature.type}<${signature.genericTypes.join(', ')}>${this.getPunctuation(declarationKind)}`),
|
|
@@ -839,7 +852,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
839
852
|
];
|
|
840
853
|
this._federation.addFederationTypeGenericIfApplicable({
|
|
841
854
|
genericTypes,
|
|
842
|
-
federationTypesType: this.convertName('
|
|
855
|
+
federationTypesType: this.convertName('FederationReferenceTypes'),
|
|
843
856
|
typeName,
|
|
844
857
|
});
|
|
845
858
|
const block = new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
@@ -92,12 +92,9 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
92
92
|
shouldInclude: namedType => !isEnumType(namedType),
|
|
93
93
|
onNotMappedObjectType: ({ typeName, initialType }) => {
|
|
94
94
|
let result = initialType;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
if (federationReferenceTypes) {
|
|
100
|
-
result += ` | ${federationReferenceTypes}`;
|
|
95
|
+
const referenceSelectionSetsString = this._federation.getMeta()[typeName]?.referenceSelectionSetsString;
|
|
96
|
+
if (referenceSelectionSetsString) {
|
|
97
|
+
result += ` | ${this.convertName('FederationReferenceTypes')}['${typeName}']`;
|
|
101
98
|
}
|
|
102
99
|
return result;
|
|
103
100
|
},
|
|
@@ -470,6 +467,27 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
470
467
|
})
|
|
471
468
|
.join('\n')).string;
|
|
472
469
|
}
|
|
470
|
+
buildFederationReferenceTypes() {
|
|
471
|
+
const federationMeta = this._federation.getMeta();
|
|
472
|
+
if (Object.keys(federationMeta).length === 0) {
|
|
473
|
+
return '';
|
|
474
|
+
}
|
|
475
|
+
const declarationKind = 'type';
|
|
476
|
+
return new DeclarationBlock(this._declarationBlockConfig)
|
|
477
|
+
.export()
|
|
478
|
+
.asKind(declarationKind)
|
|
479
|
+
.withName(this.convertName('FederationReferenceTypes'))
|
|
480
|
+
.withComment('Mapping of federation reference types')
|
|
481
|
+
.withBlock(Object.entries(federationMeta)
|
|
482
|
+
.map(([typeName, { referenceSelectionSetsString }]) => {
|
|
483
|
+
if (!referenceSelectionSetsString) {
|
|
484
|
+
return undefined;
|
|
485
|
+
}
|
|
486
|
+
return indent(`${typeName}: ${referenceSelectionSetsString}${this.getPunctuation(declarationKind)}`);
|
|
487
|
+
})
|
|
488
|
+
.filter(v => v)
|
|
489
|
+
.join('\n')).string;
|
|
490
|
+
}
|
|
473
491
|
get schema() {
|
|
474
492
|
return this._schema;
|
|
475
493
|
}
|
|
@@ -679,12 +697,6 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
679
697
|
argsType = this.applyOptionalFields(argsType, original.arguments);
|
|
680
698
|
}
|
|
681
699
|
}
|
|
682
|
-
const parentTypeSignature = this._federation.transformFieldParentType({
|
|
683
|
-
fieldNode: original,
|
|
684
|
-
parentType,
|
|
685
|
-
parentTypeSignature: this.getParentTypeForSignature(node),
|
|
686
|
-
federationTypeSignature: 'FederationType',
|
|
687
|
-
});
|
|
688
700
|
const { mappedTypeKey, resolverType } = (() => {
|
|
689
701
|
const baseType = getBaseTypeNode(original.type);
|
|
690
702
|
const realType = baseType.name.value;
|
|
@@ -718,15 +730,16 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
718
730
|
name: typeName,
|
|
719
731
|
modifier: avoidResolverOptionals ? '' : '?',
|
|
720
732
|
type: resolverType,
|
|
721
|
-
genericTypes: [mappedTypeKey,
|
|
733
|
+
genericTypes: [mappedTypeKey, this.getParentTypeForSignature(node), contextType, argsType].filter(f => f),
|
|
722
734
|
};
|
|
723
735
|
if (this._federation.isResolveReferenceField(node)) {
|
|
724
736
|
if (!this._federation.getMeta()[parentType.name].hasResolveReference) {
|
|
725
737
|
return { value: '', meta };
|
|
726
738
|
}
|
|
739
|
+
const resultType = `${mappedTypeKey} | FederationReferenceType`;
|
|
740
|
+
const referenceType = 'FederationReferenceType';
|
|
727
741
|
signature.type = 'ReferenceResolver';
|
|
728
|
-
signature.genericTypes = [
|
|
729
|
-
meta.federation = { isResolveReference: true };
|
|
742
|
+
signature.genericTypes = [resultType, referenceType, contextType];
|
|
730
743
|
}
|
|
731
744
|
return {
|
|
732
745
|
value: indent(`${signature.name}${signature.modifier}: ${signature.type}<${signature.genericTypes.join(', ')}>${this.getPunctuation(declarationKind)}`),
|
|
@@ -835,7 +848,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
835
848
|
];
|
|
836
849
|
this._federation.addFederationTypeGenericIfApplicable({
|
|
837
850
|
genericTypes,
|
|
838
|
-
federationTypesType: this.convertName('
|
|
851
|
+
federationTypesType: this.convertName('FederationReferenceTypes'),
|
|
839
852
|
typeName,
|
|
840
853
|
});
|
|
841
854
|
const block = new DeclarationBlock(this._declarationBlockConfig)
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "6.0.0-alpha-
|
|
3
|
+
"version": "6.0.0-alpha-20250609130245-016484a10b6d41d848d7b0967ce8929c5b0ccdc8",
|
|
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"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@graphql-tools/optimize": "^2.0.0",
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250609130245-016484a10b6d41d848d7b0967ce8929c5b0ccdc8",
|
|
10
10
|
"@graphql-tools/relay-operation-optimizer": "^7.0.0",
|
|
11
11
|
"@graphql-tools/utils": "^10.0.0",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
@@ -737,6 +737,7 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
737
737
|
buildResolversUnionTypes(): string;
|
|
738
738
|
buildResolversInterfaceTypes(): string;
|
|
739
739
|
buildFederationTypes(): string;
|
|
740
|
+
buildFederationReferenceTypes(): string;
|
|
740
741
|
get schema(): GraphQLSchema;
|
|
741
742
|
get defaultMapperType(): string;
|
|
742
743
|
get unusedMappers(): string[];
|
|
@@ -737,6 +737,7 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
737
737
|
buildResolversUnionTypes(): string;
|
|
738
738
|
buildResolversInterfaceTypes(): string;
|
|
739
739
|
buildFederationTypes(): string;
|
|
740
|
+
buildFederationReferenceTypes(): string;
|
|
740
741
|
get schema(): GraphQLSchema;
|
|
741
742
|
get defaultMapperType(): string;
|
|
742
743
|
get unusedMappers(): string[];
|