We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There seems to be a bug in the generation of automatic resolvers for many-to-many relationships.
Given the following schema:
model Ready { id String @id @map("_id") destinazioneId String? destinazione Standstills? @relation("ReadyToDestinazione", fields: [destinazioneId], references: [id]) intermedi ReadyIntermedi[] @relation("ReadyToIntermedi") partenzaId String partenza Standstills? @relation("ReadyToPartenza", fields: [partenzaId], references: [id]) } model Standstills { id String @id @map("_id") indirizzo String readyPartenza Ready[] @relation("ReadyToPartenza") readyDestinazione Ready[] @relation("ReadyToDestinazione") readyIntermediStandstill ReadyIntermedi[] @relation("IntermediToStandstill") } model ReadyIntermedi { id String @id @map("_id") readyId String ready Ready @relation("ReadyToIntermedi", fields: [readyId], references: [id]) standstillId String standstill Standstills @relation("IntermediToStandstill", fields: [standstillId], references: [id]) order Int // To maintain the order of intermediaries @@unique([readyId, standstillId]) }
If I query:
query Readies($take: Int) { readies(take: $take) { id partenza { indirizzo } intermedi { order readyId standstillId } } }
It works fine with the correct relation on partenza.
However, if I modify the query and add:
standstill { indirizzo }
at intermedi and obtain this query:
query Readies($take: Int) { readies(take: $take) { id partenza { indirizzo } intermedi { order readyId standstillId standstill { indirizzo } } } }
I get the following error:
"code": "INTERNAL_SERVER_ERROR", "stacktrace": [ "NotFoundError: No ReadyIntermedi found", ]
In the generated TypeScript resolvers, I found:
@TypeGraphQL.Resolver(_of => ReadyIntermedi) export class ReadyIntermediRelationsResolver { @TypeGraphQL.FieldResolver(_type => Ready, { nullable: false }) async ready(@TypeGraphQL.Root() readyIntermedi: ReadyIntermedi, @TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo): Promise<Ready> { const { _count } = transformInfoIntoPrismaArgs(info); return getPrismaFromContext(ctx).readyIntermedi.findUniqueOrThrow({ where: { id: readyIntermedi.id, }, }).ready({ ...(_count && transformCountFieldIntoSelectRelationsCount(_count)), }); } @TypeGraphQL.FieldResolver(_type => Standstills, { nullable: false }) async standstill(@TypeGraphQL.Root() readyIntermedi: ReadyIntermedi, @TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo): Promise<Standstills> { const { _count } = transformInfoIntoPrismaArgs(info); return getPrismaFromContext(ctx).readyIntermedi.findUniqueOrThrow({ where: { id: readyIntermedi.id, }, }).standstill({ ...(_count && transformCountFieldIntoSelectRelationsCount(_count)), }); } }
This is incorrect. The correct resolvers should be:
@TypeGraphQL.Resolver(_of => ReadyIntermedi) export class ReadyIntermediRelationsResolver { @TypeGraphQL.FieldResolver(_type => Ready, { nullable: false }) async ready( @TypeGraphQL.Root() readyIntermedi: ReadyIntermedi, @TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo ): Promise<Ready> { const { _count } = transformInfoIntoPrismaArgs(info); return getPrismaFromContext(ctx).ready.findUniqueOrThrow({ where: { id: readyIntermedi.readyId, // Correct access via readyId }, ...(_count && transformCountFieldIntoSelectRelationsCount(_count)), }); } @TypeGraphQL.FieldResolver(_type => Standstills, { nullable: false }) async standstill( @TypeGraphQL.Root() readyIntermedi: ReadyIntermedi, @TypeGraphQL.Ctx() ctx: any, @TypeGraphQL.Info() info: GraphQLResolveInfo ): Promise<Standstills> { const { _count } = transformInfoIntoPrismaArgs(info); return getPrismaFromContext(ctx).standstills.findUniqueOrThrow({ where: { id: readyIntermedi.standstillId, // Correct access via standstillId }, ...(_count && transformCountFieldIntoSelectRelationsCount(_count)), }); } }
{ "dependencies": { "@prisma/client": "^5.18.0", }, "devDependencies": { "@types/node": "^20.12.10", "prisma": "^5.18.0", "typegraphql-prisma": "^0.28.0", "typescript": "^5.4.5" } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Issue Description
There seems to be a bug in the generation of automatic resolvers for many-to-many relationships.
Details:
Example:
Given the following schema:
If I query:
It works fine with the correct relation on partenza.
However, if I modify the query and add:
at intermedi and obtain this query:
I get the following error:
Analysis
In the generated TypeScript resolvers, I found:
This is incorrect. The correct resolvers should be:
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: