Skip to content

Commit df19a4e

Browse files
authoredJul 13, 2021
Allow multiple {T} instances in defaultMapper (#6307)
1 parent 470336a commit df19a4e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed
 

‎.changeset/dry-nails-return.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-codegen/visitor-plugin-common': patch
3+
'@graphql-codegen/flow-resolvers': patch
4+
'@graphql-codegen/typescript-resolvers': patch
5+
---
6+
7+
Allow multiple `{T}` instances in defaultMapper

‎packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
868868
}
869869

870870
ListType(node: ListTypeNode): string {
871-
const asString = (node.type as any) as string;
871+
const asString = node.type as any as string;
872872

873873
return this.wrapWithArray(asString);
874874
}
@@ -878,7 +878,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
878878
}
879879

880880
NamedType(node: NamedTypeNode): string {
881-
const nameStr = (node.name as any) as string;
881+
const nameStr = node.name as any as string;
882882

883883
if (this.config.scalars[nameStr]) {
884884
return this._getScalar(nameStr);
@@ -888,7 +888,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
888888
}
889889

890890
NonNullType(node: NonNullTypeNode): string {
891-
const asString = (node.type as any) as string;
891+
const asString = node.type as any as string;
892892

893893
return asString;
894894
}
@@ -1022,7 +1022,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
10221022
const name = this.convertName(node, {
10231023
suffix: this.config.resolverTypeSuffix,
10241024
});
1025-
const typeName = (node.name as any) as string;
1025+
const typeName = node.name as any as string;
10261026
const parentType = this.getParentTypeToUse(typeName);
10271027
const isRootType = [
10281028
this.schema.getQueryType()?.name,
@@ -1065,7 +1065,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
10651065
.join(' | ');
10661066

10671067
this._collectedResolvers[node.name as any] = name + '<ContextType>';
1068-
const parentType = this.getParentTypeToUse((node.name as any) as string);
1068+
const parentType = this.getParentTypeToUse(node.name as any as string);
10691069

10701070
return new DeclarationBlock(this._declarationBlockConfig)
10711071
.export()
@@ -1081,7 +1081,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
10811081
}
10821082

10831083
ScalarTypeDefinition(node: ScalarTypeDefinitionNode): string {
1084-
const nameAsString = (node.name as any) as string;
1084+
const nameAsString = node.name as any as string;
10851085
const baseName = this.getTypeToUse(nameAsString);
10861086

10871087
if (this._federation.skipScalar(nameAsString)) {
@@ -1206,13 +1206,13 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
12061206
for (const graphqlType of Object.values(allTypesMap)) {
12071207
if (graphqlType instanceof GraphQLObjectType) {
12081208
const allInterfaces = graphqlType.getInterfaces();
1209-
if (allInterfaces.find(int => int.name === ((node.name as any) as string))) {
1209+
if (allInterfaces.find(int => int.name === (node.name as any as string))) {
12101210
implementingTypes.push(graphqlType.name);
12111211
}
12121212
}
12131213
}
12141214

1215-
const parentType = this.getParentTypeToUse((node.name as any) as string);
1215+
const parentType = this.getParentTypeToUse(node.name as any as string);
12161216
const possibleTypes = implementingTypes.map(name => `'${name}'`).join(' | ') || 'null';
12171217
const fields = this.config.onlyResolveTypeForInterfaces ? [] : node.fields || [];
12181218

@@ -1238,7 +1238,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
12381238
}
12391239

12401240
function replacePlaceholder(pattern: string, typename: string): string {
1241-
return pattern.replace('{T}', typename);
1241+
return pattern.replace(/\{T\}/g, typename);
12421242
}
12431243

12441244
function hasPlaceholder(pattern: string): boolean {

0 commit comments

Comments
 (0)
Please sign in to comment.