@graphql-codegen/visitor-plugin-common 5.6.1-alpha-20250105053549-084c750c69037c605fdcf600c20527dc5c74326e → 6.0.0-alpha-20250109122810-aa191e7ac94facb19d577e2fb0b27967d3590cbb
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.
|
@@ -440,6 +440,23 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
440
440
|
.map(([typeName, value]) => (0, utils_js_1.indent)(`${typeName}: ${value}${this.getPunctuation(declarationKind)}`))
|
|
441
441
|
.join('\n')).string;
|
|
442
442
|
}
|
|
443
|
+
buildFederationTypes() {
|
|
444
|
+
const federationMeta = this._federation.getMeta();
|
|
445
|
+
if (Object.keys(federationMeta).length === 0) {
|
|
446
|
+
return '';
|
|
447
|
+
}
|
|
448
|
+
const declarationKind = 'type';
|
|
449
|
+
return new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
450
|
+
.export()
|
|
451
|
+
.asKind(declarationKind)
|
|
452
|
+
.withName(this.convertName('FederationTypes'))
|
|
453
|
+
.withComment('Mapping of federation types')
|
|
454
|
+
.withBlock(Object.keys(federationMeta)
|
|
455
|
+
.map(typeName => {
|
|
456
|
+
return (0, utils_js_1.indent)(`${typeName}: ${this.convertName(typeName)}${this.getPunctuation(declarationKind)}`);
|
|
457
|
+
})
|
|
458
|
+
.join('\n')).string;
|
|
459
|
+
}
|
|
443
460
|
get schema() {
|
|
444
461
|
return this._schema;
|
|
445
462
|
}
|
|
@@ -646,6 +663,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
646
663
|
fieldNode: original,
|
|
647
664
|
parentType,
|
|
648
665
|
parentTypeSignature: this.getParentTypeForSignature(node),
|
|
666
|
+
federationTypeSignature: 'FederationType',
|
|
649
667
|
});
|
|
650
668
|
const mappedTypeKey = isSubscriptionType ? `${mappedType}, "${node.name}"` : mappedType;
|
|
651
669
|
const directiveMappings = node.directives
|
|
@@ -665,6 +683,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
665
683
|
if (!federationDetails || federationDetails.resolvableKeyDirectives.length === 0) {
|
|
666
684
|
return '';
|
|
667
685
|
}
|
|
686
|
+
signature.modifier = ''; // if a federation type has resolvable @key, then it should be required
|
|
668
687
|
}
|
|
669
688
|
this._federation.setMeta(parentType.name, { hasResolveReference: true });
|
|
670
689
|
signature.type = 'ReferenceResolver';
|
|
@@ -727,10 +746,18 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
727
746
|
if (!rootType) {
|
|
728
747
|
fieldsContent.push((0, utils_js_1.indent)(`${this.config.internalResolversPrefix}isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>${this.getPunctuation(declarationKind)}`));
|
|
729
748
|
}
|
|
749
|
+
const genericTypes = [
|
|
750
|
+
`ContextType = ${this.config.contextType.type}`,
|
|
751
|
+
this.transformParentGenericType(parentType),
|
|
752
|
+
];
|
|
753
|
+
if (this._federation.getMeta()[typeName]) {
|
|
754
|
+
const typeRef = `${this.convertName('FederationTypes')}['${typeName}']`;
|
|
755
|
+
genericTypes.push(`FederationType extends ${typeRef} = ${typeRef}`);
|
|
756
|
+
}
|
|
730
757
|
const block = new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
731
758
|
.export()
|
|
732
759
|
.asKind(declarationKind)
|
|
733
|
-
.withName(name,
|
|
760
|
+
.withName(name, `<${genericTypes.join(', ')}>`)
|
|
734
761
|
.withBlock(fieldsContent.join('\n'));
|
|
735
762
|
this._collectedResolvers[node.name] = {
|
|
736
763
|
typename: name + '<ContextType>',
|
|
@@ -436,6 +436,23 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
436
436
|
.map(([typeName, value]) => indent(`${typeName}: ${value}${this.getPunctuation(declarationKind)}`))
|
|
437
437
|
.join('\n')).string;
|
|
438
438
|
}
|
|
439
|
+
buildFederationTypes() {
|
|
440
|
+
const federationMeta = this._federation.getMeta();
|
|
441
|
+
if (Object.keys(federationMeta).length === 0) {
|
|
442
|
+
return '';
|
|
443
|
+
}
|
|
444
|
+
const declarationKind = 'type';
|
|
445
|
+
return new DeclarationBlock(this._declarationBlockConfig)
|
|
446
|
+
.export()
|
|
447
|
+
.asKind(declarationKind)
|
|
448
|
+
.withName(this.convertName('FederationTypes'))
|
|
449
|
+
.withComment('Mapping of federation types')
|
|
450
|
+
.withBlock(Object.keys(federationMeta)
|
|
451
|
+
.map(typeName => {
|
|
452
|
+
return indent(`${typeName}: ${this.convertName(typeName)}${this.getPunctuation(declarationKind)}`);
|
|
453
|
+
})
|
|
454
|
+
.join('\n')).string;
|
|
455
|
+
}
|
|
439
456
|
get schema() {
|
|
440
457
|
return this._schema;
|
|
441
458
|
}
|
|
@@ -642,6 +659,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
642
659
|
fieldNode: original,
|
|
643
660
|
parentType,
|
|
644
661
|
parentTypeSignature: this.getParentTypeForSignature(node),
|
|
662
|
+
federationTypeSignature: 'FederationType',
|
|
645
663
|
});
|
|
646
664
|
const mappedTypeKey = isSubscriptionType ? `${mappedType}, "${node.name}"` : mappedType;
|
|
647
665
|
const directiveMappings = node.directives
|
|
@@ -661,6 +679,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
661
679
|
if (!federationDetails || federationDetails.resolvableKeyDirectives.length === 0) {
|
|
662
680
|
return '';
|
|
663
681
|
}
|
|
682
|
+
signature.modifier = ''; // if a federation type has resolvable @key, then it should be required
|
|
664
683
|
}
|
|
665
684
|
this._federation.setMeta(parentType.name, { hasResolveReference: true });
|
|
666
685
|
signature.type = 'ReferenceResolver';
|
|
@@ -723,10 +742,18 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
723
742
|
if (!rootType) {
|
|
724
743
|
fieldsContent.push(indent(`${this.config.internalResolversPrefix}isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>${this.getPunctuation(declarationKind)}`));
|
|
725
744
|
}
|
|
745
|
+
const genericTypes = [
|
|
746
|
+
`ContextType = ${this.config.contextType.type}`,
|
|
747
|
+
this.transformParentGenericType(parentType),
|
|
748
|
+
];
|
|
749
|
+
if (this._federation.getMeta()[typeName]) {
|
|
750
|
+
const typeRef = `${this.convertName('FederationTypes')}['${typeName}']`;
|
|
751
|
+
genericTypes.push(`FederationType extends ${typeRef} = ${typeRef}`);
|
|
752
|
+
}
|
|
726
753
|
const block = new DeclarationBlock(this._declarationBlockConfig)
|
|
727
754
|
.export()
|
|
728
755
|
.asKind(declarationKind)
|
|
729
|
-
.withName(name,
|
|
756
|
+
.withName(name, `<${genericTypes.join(', ')}>`)
|
|
730
757
|
.withBlock(fieldsContent.join('\n'));
|
|
731
758
|
this._collectedResolvers[node.name] = {
|
|
732
759
|
typename: name + '<ContextType>',
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha-20250109122810-aa191e7ac94facb19d577e2fb0b27967d3590cbb",
|
|
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": "
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250109122810-aa191e7ac94facb19d577e2fb0b27967d3590cbb",
|
|
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",
|
|
@@ -693,6 +693,7 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
693
693
|
buildResolversParentTypes(): string;
|
|
694
694
|
buildResolversUnionTypes(): string;
|
|
695
695
|
buildResolversInterfaceTypes(): string;
|
|
696
|
+
buildFederationTypes(): string;
|
|
696
697
|
get schema(): GraphQLSchema;
|
|
697
698
|
get defaultMapperType(): string;
|
|
698
699
|
get unusedMappers(): string[];
|
|
@@ -693,6 +693,7 @@ export declare class BaseResolversVisitor<TRawConfig extends RawResolversConfig
|
|
|
693
693
|
buildResolversParentTypes(): string;
|
|
694
694
|
buildResolversUnionTypes(): string;
|
|
695
695
|
buildResolversInterfaceTypes(): string;
|
|
696
|
+
buildFederationTypes(): string;
|
|
696
697
|
get schema(): GraphQLSchema;
|
|
697
698
|
get defaultMapperType(): string;
|
|
698
699
|
get unusedMappers(): string[];
|