Hello I can't seem to find an answer on my questio...
# orm-help
g
Hello I can't seem to find an answer on my question so I'll give it a shot here: I'm trying to fetch some data from a product table using:
Copy code
const response = await prisma.product.findUnique({
          where: {
            name: name,
          },
        });
and it's complaining about the name type when I try to build, please look at the attached image. Now it's complaining about the type, the name was originally a string but I changed it to any, but I still can't seem to get it to work. My model for the product table is:
Copy code
model Product {
  id         Int         @id @default(autoincrement())
  name       String      @unique
  price      Int
  orderItems OrderItem[]
}
and the error message is: Type error: Type '{ name: any; }' is not assignable to type 'ProductWhereUniqueInput'. I'm assuming it has something to do with the @unique part in the table and the type around it. If anyone know how to solve this, feel free to contact me! 🙂 Thanks //Gustav
Ñ‚
is name a custom field from your resolver, had similar errors when using graphql nexus.
g
Copy code
orders.map(async (name: any) => {
        const response = await   prisma.product.findUnique({
          where: {
            name: name,
          },
        });

        if (response?.id) {
          await prisma.orderItem.create({
            data: {
              amount: bodyData.order.length,
              productId: response.id,
              orderId: order.id,
            },
          });
        }
      });
It's inside a map function.
l
Did you regenerate after changing the model? This kind of stuff usually works in prisma 1 at least. Try looking at your ProductWhereUniqueInput type - it should show name there in addition to id
r
@Gustav Walter 👋 Could you setup a sample reproduction repo so that I can check?