-
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
compatibility issue in generated code for prisma v5 not assignable to type #445
Comments
@simonjoom "Fixing" the type only hides the bug. GraphQL runtime does not perform "at least one" check. So you may end up in runtime error where Prisma yells about missing fields for unique. So I would recommend check in resolver manually and TS should infer the values are checked and you can use spread to set where fields in prisma query properly without type issues. |
This is aim to resolve the typings issue,.. which is shame to have a typescript generator if we cannot properly use typescript.. , i don't think i will have any runtime error after my change though, read the solution, this workaround allow to not see a typings issue on something not relevant anyway.. thks |
This is a workaround, not a solution. With your "fix" you can bypass the typescript type check, as this check takes place only in compile time. In runtime you would then be able to send no data (as graphql definitions alows to do so), your code would have no errors passing those args into prisma client query, but you would end up with error thrown into face 😛 So yeah, while I agree there should be no type issues in generated code, I can't agree with the proposed solution. If you don't care about runtime errors and just want to silence the compiler, just place |
well maybe to show that the workaround work pretty good for me i share below the code that i do use.. I want to say also that nestjs use the same workaround... i m not the only one. here below a simplified version of a resolver code i use.. As you can see the mutation here contains lot of complicated nested upsert ...etc and it s work, the query work in my tests and also in studio apollo. If i dont apply this workaround then i could not use typescript to check my code is correctly written,..
it s just a pain in the ass to repatch all the generated code as soon i need to change my schema |
Sure! 😉 /// @@TypeGraphQL.type(name: "MainUser")
model User {
id Int @id @default(autoincrement())
email String @unique
age Int
} @Query(returns => MainUser)
async uniqueMainUser(
@Ctx() { prismaClient }: Context,
@Args() args: FindUniqueMainUserArgs,
): Promise<Prisma.User> {
return await prismaClient.user.findUniqueOrThrow(args);
} query UniqueArgsFailing {
uniqueMainUser(where: {age: {gte: 18}}) {
id
email
}
} Explanation: Why your workaround is just about supressing the error? Because when we put A proper solution would be to include a runtime check. GraphQL does not support input unions, there's some work on |
i dont see again where my code can be wrong.. Yes i do understand when you say GraphQL does not support input unions.. then maybe prisma have to remove this "Prisma.atleast " ... if you dont want to follow their signature afterall prisma work with graphql right? what you just wrote: "Much complex but better solution would be to include those checks in generated resolvers, so that they will also work properly, without crashing Prisma." it s exactly what i did, there is as well one change that your generated code should do... if there is not any unique in the schema (other than id of course) then in any whereUniqueinput
should not be optional but instead:
of course to follow prisma typescript happy |
I sustain my claim and I'm sorry that you don't understand the root issue. |
Describe the Bug
compatibility issue in generated code for prisma v5
Environment (please complete the following information):
typegraphql-prisma
last current version[see isssue] (unlight/prisma-nestjs-graphql#177 (comment))
at the end one solution
The text was updated successfully, but these errors were encountered: