-
Notifications
You must be signed in to change notification settings - Fork 423
Description
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
If I have a User
database entity, a User
GQL schema object, and perhaps even some more User
interfaces, it's easy to mistake one with another.
When a file relies on both (e.g. a user resolver that fetches User db entity in order to resolve with a User GQL schema object), import aliases need to be used such as Import { User as UserSchema } from '...'
, which often need to be written manually by the developer, and are prone to typos and lack of consistency in the codebase.
Describe the solution you'd like
Could we make the generated type names configurable? For example, we could add a typeName?(name: string): string
option to the GraphQLDefinitionsFactory
:
const definitionsFactory = new GraphQLDefinitionsFactory();
definitionsFactory.generate({
typePaths: ['./src/**/*.graphql'],
path: join(process.cwd(), 'src/api/schema.d.ts'),
typeName: (name: string) => `${name}Schema` // new option!
});
This would result in following schema be created:
export interface UserSchema {
id: string;
name: string;
}
export interface IQuery {
users(): UserSchema[] | Promise<UserSchema[]>;
}
instead of this one:
export interface User {
id: string;
name: string;
}
export interface IQuery {
users(): User[] | Promise<User[]>;
}
@kamilmysliwiec I'd be happy to create a PR for this, just let me know if you'd be open to merging it.
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
I like to give a prefix or suffix to all classnames in my repository, e.g.:
- suffix all resolvers with
*Resolver
(something that is suggested by nestjs docs already), - suffix all db entity classes with
*Entity
- suffix all input/DTOs with
*Input
or*Dto
or*InputDto
- suffix all schema objects with
*Schema
However, currently I'm using schema-first approach, and thus TS type definitions of GQL schema interfaces are generated automatically, and the generated type names can't be customized.