Couldn't find type ProductWhereUniqueInput in any of the schemas


#1

Hi There :slight_smile:

I’ve been trying (without success) to create a query to find a single product based on its Id.
I just keep having this build error:

Field where: Couldn’t find type ProductWhereUniqueInput in any of the schemas.

This is my datamodel.prisma:

type Product {
  id: ID! @unique
  name: String!
  description: String!
  image: String
  largeImage: String
  price: Int!
}

My schema.graphql:

type Query {
  products: [Product!]
  product(where: ProductWhereUniqueInput!): Product
}

type Product {
  id: ID!
  name: String!
  description: String!
  image: String
  largeImage: String
  price: Int!
}

I have already deployed and generate my Prisma schema, which do have the:

product(where: ProductWhereUniqueInput!): Product

I’ve also created a resolver:

async product(root, args, context, info) {

const product = await context.prisma.product()
return product

console.log(product)
},

On my Prisma Server Playground (demo), I’ve been able to return a single product without any issue with the following:

query{
  product(where: {
    id: "cjrxlxtxd19xv0a45beggd420"
  }){
    id
    name
    description
    price
  }
}

Why my graphql-yoga server can’t find the ProductWhereUniqueInput in my schema?
Any help would be much appreciated!

Thank you :slight_smile:


#2

As stated in the error, you are missing your ProductWhereUniqueInput

You can either redefine it, or import it using graphql import:

# schema.graphql
# import ProductWhereUniqueInput from './path/to/prisma/schema.graphql'

type Query {
  products: [Product!]
  product(where: ProductWhereUniqueInput!): Product
}

type Product {
  id: ID!
  name: String!
  description: String!
  image: String
  largeImage: String
  price: Int!
}

#3

#4

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.