prisma-relay-cursor-connection icon indicating copy to clipboard operation
prisma-relay-cursor-connection copied to clipboard

Override Prisma TypeGraphQL generated array properties?

Open FezVrasta opened this issue 1 year ago • 2 comments

Hi, thanks for the library!

I have an auto generated ObjectType like the following:

@ObjectType()
export class Product {
  @Field()
  id!: string;

  @Field(() => Price[])
  prices!: Price[]
}

I would like to make prices a connection, but if I do the following TypeScript complains with Property 'prices' in type 'ProductNode' is not assignable to the same property in base type 'Product'.

@ObjectType()
export class ProductNode extends Product {
  @Field(() => ProductPriceConnection)
  prices!: ProductPriceConnection;
}

I also get the same error when I define the ResolverInterface.

Is there a canonical way to address this class of issues or the only way is to use implements rather than extends and re-define the whole object type manually?

Thanks.

FezVrasta avatar Apr 29 '24 09:04 FezVrasta

As far as I know, you will have to use either implements or something like mapped-types' OmitType for this.

queicherius avatar Apr 29 '24 18:04 queicherius

Thanks, I tried OmitType but the resulting schema ends up missing all the Product properties and only includes prices.

@ObjectType()
export class ProductNode extends OmitType(Product, ["prices"] as const) {
  @Field(() => ProductPriceConnection)
  prices!: ProductPriceConnection;
}

CleanShot 2024-05-01 at 1  28 41@2x

FezVrasta avatar May 01 '24 11:05 FezVrasta

I just wanted to say I managed to make this work using these utilities instead https://github.com/ChrisLahaye/type-graphql-utils

FezVrasta avatar Aug 10 '24 05:08 FezVrasta