Reputation: 129
I get the error message "Cannot query field "available" on type "Query" when I try to fetch all products including the available property.
const res = await fetch(`graphql?query={products{
id
name
available
}}`);
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
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
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