Skip to content

Commit

Permalink
Allow multiple {T} instances in defaultMapper (#6307)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Jul 13, 2021
1 parent 470336a commit df19a4e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/dry-nails-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-codegen/visitor-plugin-common': patch
'@graphql-codegen/flow-resolvers': patch
'@graphql-codegen/typescript-resolvers': patch
---

Allow multiple `{T}` instances in defaultMapper
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
}

ListType(node: ListTypeNode): string {
const asString = (node.type as any) as string;
const asString = node.type as any as string;

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

NamedType(node: NamedTypeNode): string {
const nameStr = (node.name as any) as string;
const nameStr = node.name as any as string;

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

NonNullType(node: NonNullTypeNode): string {
const asString = (node.type as any) as string;
const asString = node.type as any as string;

return asString;
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
const name = this.convertName(node, {
suffix: this.config.resolverTypeSuffix,
});
const typeName = (node.name as any) as string;
const typeName = node.name as any as string;
const parentType = this.getParentTypeToUse(typeName);
const isRootType = [
this.schema.getQueryType()?.name,
Expand Down Expand Up @@ -1065,7 +1065,7 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
.join(' | ');

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

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

ScalarTypeDefinition(node: ScalarTypeDefinitionNode): string {
const nameAsString = (node.name as any) as string;
const nameAsString = node.name as any as string;
const baseName = this.getTypeToUse(nameAsString);

if (this._federation.skipScalar(nameAsString)) {
Expand Down Expand Up @@ -1206,13 +1206,13 @@ export type IDirectiveResolvers${contextType} = ${name}<ContextType>;`
for (const graphqlType of Object.values(allTypesMap)) {
if (graphqlType instanceof GraphQLObjectType) {
const allInterfaces = graphqlType.getInterfaces();
if (allInterfaces.find(int => int.name === ((node.name as any) as string))) {
if (allInterfaces.find(int => int.name === (node.name as any as string))) {
implementingTypes.push(graphqlType.name);
}
}
}

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

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

function replacePlaceholder(pattern: string, typename: string): string {
return pattern.replace('{T}', typename);
return pattern.replace(/\{T\}/g, typename);
}

function hasPlaceholder(pattern: string): boolean {
Expand Down

0 comments on commit df19a4e

Please sign in to comment.