typegraphql-prisma
typegraphql-prisma copied to clipboard
mismatches between generated typescript and typescript prisma (_count and cursor)
I found the issue when i started to create a custom resolver
my custom resolver use prisma from context attached to the generated typescript prismaClient To see the typescript mismatches from any relationresolver.ts file output: you can change getPrismaFromContext(ctx). to (getPrismaFromContext(ctx) as PrismaClient).
The original code use ctx.prisma in any so typescript is not working here
_count is not supported by the current generated typescript (completly different from the ts prisma code ) also cursor is not same (and need to be overriden to any )
my file ListingRelationsResolver.ts with error typescript on return
@TypeGraphQL.Resolver(_of => Listing)
export class ListingRelationsResolver {
@TypeGraphQL.FieldResolver(_type => Category, {
nullable: false
})
async category(@TypeGraphQL.Root() listing: Listing, @TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo): Promise<Category> {
const { _count } = transformInfoIntoPrismaArgs(info);
return (getPrismaFromContext(ctx) as PrismaClient).listing.findUniqueOrThrow({
where: {
id: listing.id,
},
}).category({
...(_count && transformCountFieldIntoSelectRelationsCount(_count)),
});
}
}
#204 So i use Promise<Omit<Category,"_count"> as a turnaround for the type output of this resolver.
for me this change turnaround typescript problems, also i tested _count and it s still working From there it seems there is still some improvement todo to set the code fully compatible with prisma.