From b082565272362412c27226e66365f34df2e6b548 Mon Sep 17 00:00:00 2001 From: Santino Puleio Date: Wed, 11 Dec 2024 14:12:12 +0100 Subject: [PATCH] Fix bare mode resolvers for Prefix and NamingConvention transforms (#6217) --- .changeset/short-fans-change.md | 6 ++++++ .../naming-convention/src/bareNamingConvention.ts | 6 +++--- packages/legacy/transforms/prefix/src/barePrefix.ts | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 .changeset/short-fans-change.md diff --git a/.changeset/short-fans-change.md b/.changeset/short-fans-change.md new file mode 100644 index 0000000000000..840a28dbb7267 --- /dev/null +++ b/.changeset/short-fans-change.md @@ -0,0 +1,6 @@ +--- +'@graphql-mesh/transform-naming-convention': patch +'@graphql-mesh/transform-prefix': patch +--- + +Fix bare mode resolvers for Prefix and NamingConvention transforms diff --git a/packages/legacy/transforms/naming-convention/src/bareNamingConvention.ts b/packages/legacy/transforms/naming-convention/src/bareNamingConvention.ts index 86209d016f3e5..b9f09a7637565 100644 --- a/packages/legacy/transforms/naming-convention/src/bareNamingConvention.ts +++ b/packages/legacy/transforms/naming-convention/src/bareNamingConvention.ts @@ -65,7 +65,7 @@ const defaultResolverComposer = // map result values from original value to new renamed value return resultMap ? Array.isArray(originalResult) - ? originalResult.map(result => resultMap[result as string] || originalResult) + ? originalResult.map(result => resultMap[result as string] || result) : resultMap[originalResult as string] || originalResult : originalResult; }; @@ -161,7 +161,7 @@ export default class NamingConventionTransform implements MeshTransform { ]; }, }), - ...((this.config.fieldNames || this.config.fieldArgumentNames) && { + ...((this.config.enumValues || this.config.fieldNames || this.config.fieldArgumentNames) && { [MapperKind.COMPOSITE_FIELD]: (fieldConfig, fieldName) => { const enumNamingConventionFn = NAMING_CONVENTIONS[this.config.enumValues]; const fieldNamingConventionFn = @@ -223,7 +223,7 @@ export default class NamingConventionTransform implements MeshTransform { fieldConfig.resolve = defaultResolverComposer( fieldConfig.resolve, fieldName, - argsMap, + Object.keys(argsMap).length ? argsMap : null, resultMap, ); diff --git a/packages/legacy/transforms/prefix/src/barePrefix.ts b/packages/legacy/transforms/prefix/src/barePrefix.ts index 22b57eca1bb3d..7e89f797230e9 100644 --- a/packages/legacy/transforms/prefix/src/barePrefix.ts +++ b/packages/legacy/transforms/prefix/src/barePrefix.ts @@ -52,7 +52,9 @@ export default class BarePrefix implements MeshTransform { const existingResolver = type.resolveType; type.resolveType = async (data, context, info, abstractType) => { const typeName = await existingResolver(data, context, info, abstractType); - return this.prefix + typeName; + // an extended type might already implement the resolver of a previously + // transformed type, hence prefix would have already been applied + return typeName.startsWith(this.prefix) ? typeName : this.prefix + typeName; }; const currentName = type.name; return renameType(type, this.prefix + currentName) as GraphQLAbstractType;