devoxa / prisma-relay-cursor-connection

Extend Prisma's `findMany` method to support Relay Cursor Connections.
262 stars 19 forks source link

Override Prisma TypeGraphQL generated array properties? #892

Open FezVrasta opened 3 months ago

FezVrasta commented 3 months ago

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.

queicherius commented 3 months ago

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

FezVrasta commented 2 months ago

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