MichalLytek / MichalLytek/typegraphql-prisma
mismatches between generated typescript and typescript prisma (_count and cursor)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 918
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Description
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 {
const { _count } = transformInfoIntoPrismaArgs(info);
return (getPrismaFromContext(ctx) as PrismaClient).listing.findUniqueOrThrow({
where: {
id: listing.id,
},
}).category({
...(_count && transformCountFieldIntoSelectRelationsCount(_count)),
});
}
}
```
#204
So i use Promise 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated ListingRelationsResolver.ts and the TypeScript PrismaClient definitions, focusing on relation resolver return types, _count, and cursor. Compare the generated types with Prisma's types and issue #204; done means the generated resolver types are compatible without casts or overrides.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100