-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.17.0 relation _count type errors #204
Comments
You can see from their tests that they are expecting there to be no _count property when the include option isn't added |
It only applies to the generated resolvers of course. There are known issues with Prisma and GraphQL types interoperability - see #107. |
Dammm that's a shame, guess I have to either not type the return function or omit the _count property everywhere |
In order to avoid separate Prisma call, the |
Have resorted to creating my own model classes for now, not ideal but can still use all the generated inputs/args etc Happy to close this issue as it's basically a dupe of #107 |
export type XYZType = Omit<XYZ, "_count">; |
Hmm yeah, but also need an actual class right? to use in the return types for the resolvers? Example below // user.model.ts
import { User as TUser } from "@generated"
export type User = Omit<TUser, "_count">
// user.resolver.ts
// FIND USER
@UseAuth([Role.SUPER_ADMIN])
@Query(() => User, { nullable: true }) // ERROR: 'User' only refers to a type, but is being used as a value here.
async user(@Args() args: FindFirstUserArgs): Promise<User | null> {
return await prisma.user.findFirst(args)
} So I would have to create a class that extends the generated User, but then that errors.. export class User extends TUser {
_count: undefined // Property '_count' in type 'User' is not assignable to the same property in base type 'User'.
} Not sure if I'm doing something stupid, but can't seem to make TS happy |
I think we would need a generator option to not emit Prisma approach does not play well with GraphQL, especially with the custom resolvers. |
Yeahhh, that would be great haha :) I do feel like the default exported model should be _count: undefined, and for all the generated resolvers you can use an internal non-exported model with _count: UserCount. This means the generated resolvers would still work, and if I wanted to add _count to my User type I could manually extend it. Would this work? |
No, we need to use the same class, otherwise it would end up with duplicated names and types being not interoperable. So users will need to choose:
|
Yep! Gotcha Thanks for explaining! |
Forgot about the third option 🤦 Nullable It should be the default option, as it worked like that before the "upgrade". |
I'm also facing this issue and have had to rollback to 0.16.6 to avoid having to fix a lot of issues with type inconsistencies, are you saying you will be making the count field generate like |
looks like @MichalLytek fixed this (❤️) in 0.18.2 if you want to check it out @JClackett |
Yep! All sorted! but in our team we actually decided to still create the custom model files anyway. I have some concerns with security when using the generated models as it enables the fields by default. Meaning the developer has to remember to add any security checks (I know typegraphql-prisma provides a way to add the checks). Using a custom model means the developer has to actively select which fields they want to expose. Less error prone in our opinion :) |
Hi @MichalLytek , is there now a generator option to disable the _count field entirely in the generated models for custom resolvers? |
Describe the Bug
With the change in 0.17.0 regarding the _count field, all my fluent api relations types are now giving type errors
In your release notes you mention that the _count property is now non-nullable, but isn't this just for the case when you pass in the option to select the _count property i.e
Related prisma issue
Basically, there's now a mis match between what prisma is providing and what typegraphql-prisma is saying will exist, typegraphql-prisma is now always expecting a _count property, but I'm pretty sure this isn't true?
The text was updated successfully, but these errors were encountered: