【发布时间】:2021-04-02 02:58:36
【问题描述】:
我必须进行查询,并且必须传递一个嵌套变量。 以下是我使用 apollo graphql 客户端界面时的工作查询。它给了我预期的结果。以下是工作查询
query($input: MyProductInput!){
MyProductCategories(input: $input){
id,
name
}
}
我要传递的变量
{
"input": {
"locale": "ENG"
}
}
MyProductInput 类型在 SERVER 上看起来像这样
type MyProductInput {
locale: Locale!
}
enum Locale {
IND
AUS
ENG
}
当我尝试从我的 React 应用程序调用相同的查询时,它给了我错误,它说 400 bad request。我的 React 查询如下所示。
const PRODUCT_LIST = gql`
query ($locale: String!) {
MyProductCategories(input: {locale: $locale}){
id,
name
}
}
`;
const { loading, error, data } = useQuery(PRODUCT_LIST, {
variables: {
"input": {
"locale": "ENG"
}
},
});
如何转换我的反应查询以适应自定义类型?
注意:我在前端使用的是 JavaScipt 而不是 Typescript
【问题讨论】:
-
你签入graphiql了吗?
-
Nisharg shah,是的,我签入了 graphiql,我在
its working fine in apollo graphql client interface的问题中也提到了这一点 -
请去掉
id, name之间的逗号
标签: javascript reactjs graphql react-apollo