prisma-relay-cursor-connection
prisma-relay-cursor-connection copied to clipboard
Override Prisma TypeGraphQL generated array properties?
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.
As far as I know, you will have to use either implements or something like mapped-types' OmitType for this.
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;
}
I just wanted to say I managed to make this work using these utilities instead https://github.com/ChrisLahaye/type-graphql-utils