图形QL查询:获取错误"Expected value of type ..., found ..."



假设我有以下对象类型:

type Price {
currency: Currency!,
amount: Float!
}
type Attribute {
displayValue: String,
value: String,
id: String!
}
type AttributeSet {
id: String!,
name: String,
type: String,
items: [Attribute]
}
type Product {
id: String!,
name: String!,
inStock: Boolean,
gallery: [String],
description: String!,
category: String!,
attributes: [AttributeSet]
prices: [Price!]!,
brand: String!
}
type Category {
name: String,
products: [Product]!
}
type Currency {
label: String!,
symbol: String!
}
input CategoryInput {
title: String!
}
type Query {
categories: [Category],
category(input: CategoryInput): Category,
product(id: String!): Product,
currencies: [Currency]
}

这些是Category:的类型

export enum Category {
all = 'all',
clothes = 'clothes',
tech = 'tech'
};

在graphQL Playground中,我试图进行一个查询,以显示类别为all的元素的所有名称和products/id。这是我的尝试:

{
category(input: "all") {
name
products {
id
}
}
}

但我收到以下错误消息:

"message": "Expected value of type "CategoryInput", found "all".",

由于all是一个有效的类型,我需要帮助来理解出了什么问题。提前谢谢。

刚刚发现我的错误

CategoryInput为型

input CategoryInput {
title: String!
}

因此,一个合适的查询应该是:

{
category(input: { title: "all" }) {
name
products {
id
}
}
}

相关内容

最新更新