Skip to content

Commit

Permalink
Fix bare mode resolvers for Prefix and NamingConvention transforms (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
santino authored Dec 11, 2024
1 parent 3fbdeea commit b082565
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/short-fans-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/transform-naming-convention': patch
'@graphql-mesh/transform-prefix': patch
---

Fix bare mode resolvers for Prefix and NamingConvention transforms
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -223,7 +223,7 @@ export default class NamingConventionTransform implements MeshTransform {
fieldConfig.resolve = defaultResolverComposer(
fieldConfig.resolve,
fieldName,
argsMap,
Object.keys(argsMap).length ? argsMap : null,
resultMap,
);

Expand Down
4 changes: 3 additions & 1 deletion packages/legacy/transforms/prefix/src/barePrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b082565

Please sign in to comment.