4

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
}
`;

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

if you look at the schema part of the code you see there is a field of available there
yeah, now there is .. :)
0

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
    }
  }}`);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.