redwood: Prisma v3.9.1 Bug: Generated resolver causes error

Workaround

This is an upstream issue with Prisma v3.9.1. The currently workaround is to use Redwood v0.44.1, which has downgraded Prisma to v3.8.1


Using the default resolvers generated by scaffolding and the sdl generator I’m getting this error

image

Repro:

yarn create redwood-app my-app
cd my-app

Replace the content of schema.prisma with this

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

generator client {
  provider      = "prisma-client-js"
  binaryTargets = "native"
}

model Product {
  id                Int                 @id @default(autoincrement())
  createdAt         DateTime            @default(now())
  updatedAt         DateTime            @default(now()) @updatedAt
  name              String
  CategoryToProduct CategoryToProduct[]
}

model Category {
  id                 Int                 @id @default(autoincrement())
  name               String
  parent             Int?
  parentCategory     Category?           @relation("CategoryParent", fields: [parent], references: [id])
  childrenCategories Category[]          @relation("CategoryParent")
  CategoryToProduct  CategoryToProduct[]
}

model CategoryToProduct {
  id         Int      @id @default(autoincrement())
  product    Product  @relation(fields: [productId], references: [id])
  productId  Int
  category   Category @relation(fields: [categoryId], references: [id])
  categoryId Int

  @@unique([productId, categoryId])
}
yarn rw prisma migrate dev --name init
yarn rw g scaffold product
yarn rw g scaffold category
yarn rw g sdl categoryToProduct

Now launch the dev server and go create a new product. Maybe a Barcode Scanner image You’re taken to a list of your products image

Now go edit the ProductsCell code. Make the gql query also include the CategoryToProduct relation, like this

query FindProducts {
  products {
    id
    createdAt
    updatedAt
    name
    CategoryToProduct {
      categoryId
    }
  }
}

As soon as you save your changes you should see an error in the console as it rebuilds.

api | Invalid `db.product.findUnique()` invocation in
api | /Users/tobbe/tmp/mnresolver/api/src/services/products/products.js:34:55
api | 
api |   31 
api |   32 export const Product = {
api |   33   CategoryToProduct: (_obj, { root }) =>
api | → 34     db.product.findUnique({
api |            where: {
api |              id: 3
api |            },
api |            select: {
api |              categoryToProduct: true,
api |              ~~~~~~~~~~~~~~~~~
api |          ?   id?: true,
api |          ?   createdAt?: true,
api |          ?   updatedAt?: true,
api |          ?   name?: true,
api |          ?   CategoryToProduct?: true,
api |          ?   _count?: true
api |            }
api |          })
api | 
api | 
api | Unknown field `categoryToProduct` for select statement on model Product. Available options are listed in green. Did you mean `CategoryToProduct`?

It tries to include categoryToProduct, but there isn’t anything named that. Should be with a capital C. The code that’s executing is the resolver for CategoryToProduct at the end of products.js:

export const Product = {
  CategoryToProduct: (_obj, { root }) =>
    db.product.findUnique({ where: { id: root.id } }).CategoryToProduct(),
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Decided on zoom meeting to downgrade. I’ll create a PR

Found a related issue over at Prisma’s GitHub: https://github.com/prisma/prisma/issues/11641

This fixes it on RW .44

package.json:

  "resolutions": {
    "**/prisma": "3.8.1",
    "**/@prisma/sdk": "3.8.1",
    "**/@prisma/client": "3.8.1"
  },