Skip to content

Commit

Permalink
Revert "Fix: naming of imported enums (#10185)"
Browse files Browse the repository at this point in the history
This reverts commit 09cb7d3.
  • Loading branch information
gilgardosh authored Nov 7, 2024
1 parent 09cb7d3 commit 3092f5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,13 +873,9 @@ export class BaseResolversVisitor<
this.markMapperAsUsed(typeName);
prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
} else if (isEnumType(schemaType) && this.config.enumValues[typeName]) {
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;
prev[typeName] =
this.config.enumValues[typeName].sourceIdentifier ||
this.convertName(this.config.enumValues[typeName].typeIdentifier);
} else if (hasDefaultMapper && !hasPlaceholder(this.config.defaultMapper.type)) {
prev[typeName] = applyWrapper(this.config.defaultMapper.type);
} else if (isScalar) {
Expand Down
20 changes: 3 additions & 17 deletions packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ __isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
const testSchema = buildSchema(/* GraphQL */ `
type Query {
a: A
c: C
}
enum A {
Expand All @@ -607,17 +606,11 @@ __isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
type B {
a: String
}
enum C {
Y
Z
}
`);

const config = {
enumValues: {
A: 'MyA',
C: '../enums.js#MyC',
},
typesPrefix: 'GQL_',
};
Expand All @@ -629,13 +622,9 @@ __isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;

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 () => {
Expand Down Expand Up @@ -2271,7 +2260,7 @@ export type ResolverFn<TResult, TParent, TContext, TArgs> = (
ProjectRoleDetail: '../entities#ProjectRole',
},
enumValues: {
ProjectRole: '../entities#AnotherProjectRole',
ProjectRole: '../entities#ProjectRole',
},
};

Expand All @@ -2283,11 +2272,8 @@ export type ResolverFn<TResult, TParent, TContext, TArgs> = (
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(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();
expect(tsContent.prepend.includes(`import { ProjectRole } from '../entities';`)).toBeTruthy();
expect(output.prepend.includes(`import { ProjectRole } from '../entities';`)).toBeFalsy();
});

it('#3264 - enumValues is not being applied to directive resolver', async () => {
Expand Down

0 comments on commit 3092f5b

Please sign in to comment.