ZenKurd
ZenKurd

Reputation: 129

"Cannot query field "available" on type "Query"

I get the error message "Cannot query field "available" on type "Query" when I try to fetch all products including the available property.

Query call

const res = await fetch(`graphql?query={products{
    id
    name
    available
  }}`);

Schema

export default `
type Product {
  id: ID!
  name: String! 
  available: [Available]
}

type Available  {
  stock: String
  size: String
}

input AvailableInput {
  stock: String
  size: String
}

type Query {
  product(name: String!): Product
  products: [Product] 
}

type Mutation {
  addProduct(name: String! available:[AvailableInput] ): Product
}
`;

Upvotes: 4

Views: 26482

Answers (2)

Scott Agirs
Scott Agirs

Reputation: 679

Your available field returns object of type Available, so the first error is that you have no subfields in your query string.

Gives this a try:

const res = await fetch(`graphql?query={products{
    id
    name
    available {
        stock
        size
    }
  }}`);

Upvotes: 0

Scott Agirs
Scott Agirs

Reputation: 679

what does your type Product look like in Schema? perhaps you're missing a field on that as you're querying the available field as a subfield of Product

Upvotes: 1

Related Questions