diff --git a/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts b/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts index a5132c3a54a..19351915e15 100644 --- a/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts +++ b/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts @@ -873,9 +873,13 @@ export class BaseResolversVisitor< this.markMapperAsUsed(typeName); prev[typeName] = applyWrapper(this.config.mappers[typeName].type); } else if (isEnumType(schemaType) && this.config.enumValues[typeName]) { - prev[typeName] = - this.config.enumValues[typeName].sourceIdentifier || - this.convertName(this.config.enumValues[typeName].typeIdentifier); + const isExternalFile = !!this.config.enumValues[typeName].sourceFile; + prev[typeName] = isExternalFile + ? this.convertName(this.config.enumValues[typeName].typeIdentifier, { + useTypesPrefix: false, + useTypesSuffix: false, + }) + : this.config.enumValues[typeName].sourceIdentifier; } else if (hasDefaultMapper && !hasPlaceholder(this.config.defaultMapper.type)) { prev[typeName] = applyWrapper(this.config.defaultMapper.type); } else if (isScalar) { diff --git a/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts b/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts index 595a548d0f3..a1d13fe829e 100644 --- a/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts +++ b/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts @@ -590,6 +590,7 @@ __isTypeOf?: IsTypeOfResolverFn; const testSchema = buildSchema(/* GraphQL */ ` type Query { a: A + c: C } enum A { @@ -606,11 +607,17 @@ __isTypeOf?: IsTypeOfResolverFn; type B { a: String } + + enum C { + Y + Z + } `); const config = { enumValues: { A: 'MyA', + C: '../enums.js#MyC', }, typesPrefix: 'GQL_', }; @@ -622,9 +629,13 @@ __isTypeOf?: IsTypeOfResolverFn; expect(mergedOutputs).not.toContain(`A: A;`); expect(mergedOutputs).not.toContain(`A: GQL_A;`); + expect(mergedOutputs).not.toContain(`C: GQL_MyC;`); expect(mergedOutputs).toContain(`NotMapped: GQL_NotMapped;`); expect(mergedOutputs).not.toContain(`NotMapped: NotMapped;`); + expect(mergedOutputs).toContain(`A: MyA;`); expect(mergedOutputs).toContain(`B: GQL_B;`); + expect(mergedOutputs).toContain(`C: C;`); + expect(mergedOutputs).toContain(`import { MyC as C } from '../enums.js';`); }); it('Should allow to generate optional __resolveType', async () => { @@ -2260,7 +2271,7 @@ export type ResolverFn = ( ProjectRoleDetail: '../entities#ProjectRole', }, enumValues: { - ProjectRole: '../entities#ProjectRole', + ProjectRole: '../entities#AnotherProjectRole', }, }; @@ -2272,8 +2283,11 @@ export type ResolverFn = ( expect(output.prepend.filter(t => t.includes('import')).length).toBe(2); expect(output.prepend.filter(t => t.includes('ProjectRole')).length).toBe(0); expect(tsContent.prepend.filter(t => t.includes('ProjectRole')).length).toBe(1); - expect(tsContent.prepend.includes(`import { ProjectRole } from '../entities';`)).toBeTruthy(); - expect(output.prepend.includes(`import { ProjectRole } from '../entities';`)).toBeFalsy(); + expect(output.content.includes('AnotherProjectRole')).toBeFalsy(); + expect( + tsContent.prepend.includes(`import { AnotherProjectRole as ProjectRole } from '../entities';`) + ).toBeTruthy(); + expect(output.prepend.includes(`import { AnotherProjectRole as ProjectRole } from '../entities';`)).toBeFalsy(); }); it('#3264 - enumValues is not being applied to directive resolver', async () => {