Currently, my development stack consists of TypeGraphql, Prisma 2, an Apollo Express server, and a PostgreSQL database.
To facilitate the generation of TypeScript types, I utilized Prisma to introspect my database and generate types from the schema.prisma
file.
Additionally, I have defined my @ObjectType
model classes using TypeGraphQL.
However, I am encountering type conflicts between my TypeGraphQL classes and the Prisma-generated types. For instance, I have a TypeGraphQL class named Course
structured as follows:
@ObjectType()
export class Course {
@Field(() => Int)
id: number;
@Field()
title: string;
.......
@Field(() => User)
creator: User;
}
On the other hand, Prisma generates a type for Course
that looks like this:
/**
* Model Course
*/
export type Course = {
id: number
title: string
.......
creator_id: number
}
When attempting to create a Course
in my custom resolvers, I encounter a discrepancy in the types. The mismatch is causing TypeScript to flag an error indicating that the creator is missing in one Course
type but required in another. This inconsistency has left me uncertain about the optimal resolution approach.
Is there a method to effectively merge my TypeGraphQL classes with the Prisma types or pursue an alternative strategy?