prisma-nestjs-graphql: Prisma 5 released - breaks generated types

It looks like the changes introduced in V5 of Prisma break the generated files from this. Lots of * is not assignable to type * type errors. I guess it’s because of the changes to carry shortcuts, but it might be something else. I’ve tried searching through, but I got in a bit of looping trying to find the exact reason.

https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-5#removal-of-array-shortcuts

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@unlight Unfortunately, I’m still getting errors in any WHere class with an AND etc., as they are self-references and, therefore, not wrapped with the Prisma.AtLeast. So we need to also add it to those.

export declare class SomeClassWhereUniqueInput {
    AND?: Array<SomeClassWhereUniqueInput>;
    OR?: Array<SomeClassWhereUniqueInput>;
    NOT?: Array<SomeClassWhereUniqueInput>;
}

I think the issue is that we are wrapping the where: Prisma.AtLeast<SomeCLasseUniqueInput, 'id'>; instead of the actual type like Prisma does.

 export type SomeClassWhereUniqueInput = Prisma.AtLeast<{
    id?: string
    AND?: SomeClassWhereUniqueInput | SomeClassWhereUniqueInput[]
    OR?: SomeClassWhereUniqueInput[]
    NOT?: SomeClassWhereUniqueInput | SomeClassWhereUniqueInput[]
    ...
}

@jasonmacdonald @magrinj @Siumauricio Please check version 19 (use next dist-tag) with prisma 5

npm i prisma-nestjs-graphql@next

It looks like they are now wrapping certain types in a Prisma.AtLeast<{...classProps}, "prop1" | "prop1"> function which makes certain properties required if they are, I assume, @id, @@id or @unique in the schema.

EDIT: Narrowed it down to any WhereUniqueInput class. they are all wrapped in this condition now.

@unlight Thx for you response. I’ll try type assertion, but it’s a bit messy in the code. I’m in for a switch in the configuration even if it is a bit unsafe.

Another idea - introduce new option in config to trick typescript and add exclamation mark for all unique fields for such WhereUniqueInput classes (unsafe, needs validation and coercing to valid type).

@InputType()
export class UserWhereUniqueInput {
  @Field(() => String, { nullable: true })
  id!: string;

  @Field(() => Scalars.GraphQLEmailAddress, { nullable: true })
  email!: string;
}

Can confirm that v19.0.0 works as expected.