Hi everyone! I'm using prisma with type-graphql. ...
# orm-help
m
Hi everyone! I'm using prisma with type-graphql. I'm looking for guidance on how to extend a generated model created by
prisma generate
I'm able to generate models / resolvers using
npx prisma generate
and all is working as expected. I've created a custom resolver and added it to the resolvers array in buildSchema:
Copy code
@Resolver((of) => Auction)
export default class AuctionResolver {
  @FieldResolver((returns) => Number, { nullable: true })
  async totalBids(
    @Root() auction: Auction,
    @Ctx() { prisma }: Context
  ): Promise<number> {
    const totalBids = await prisma.bid.aggregate({
      _count: {
        id: true,
      },
      where: {
        auctionId: auction.id,
      },
    });

    return totalBids._count.id;
  }
}
The field shows up in graphql playground, but it's not in the generated model class; so when using the model types, I'm getting warnings for
totalBids
Property 'totalBids' does not exist on type 'Auction'.ts(2339)
Is it possible to add a field to the .schema file that is not persisted in the DB model?