Reactjs Apollo Graphql查询与输入值一起响应
我在回答阿波罗的问题时遇到了麻烦。我知道如何在操场上和React中的基本查询中执行此操作,但我不知道如何在查询中动态传递输入值。查询应该是这样的。这在操场上起作用Reactjs Apollo Graphql查询与输入值一起响应,reactjs,graphql,apollo-client,Reactjs,Graphql,Apollo Client,我在回答阿波罗的问题时遇到了麻烦。我知道如何在操场上和React中的基本查询中执行此操作,但我不知道如何在查询中动态传递输入值。查询应该是这样的。这在操场上起作用 getCityByName(name: "London", country: "GB", config:{units:metric, lang: sp}) { id name weather { summary { description } te
getCityByName(name: "London", country: "GB", config:{units:metric, lang: sp}) {
id
name
weather {
summary {
description
}
temperature {
actual
}
}
}
单位和语言为enum。在React中,我只能以友好的方式传递名称和国家,但不能传递配置选项,我只会收到错误,而且我尝试了很多不同的语法。
我唯一能做的就是这样硬编码:
const GET_DATA = gql`
query getCity($name: String!, $country: String) {
getCityByName(
name: $name
country: $country
config: { units: metric, lang: sp }
) {
id
name
country
weather {
summary {
description
}
temperature {
actual
}
}
}
}
`;
如何使units和lang成为动态的?定义$config变量(从API文档读取类型),传递objectYes,我已经尝试过了,但units和lang是enum类型。units指向枚举单位{metric imperial kelvin},lang指向枚举语言。-作为字符串传递的枚举值应被识别为枚举。。。首先在操场上测试我终于在这里找到了解决办法
const { loading, data, error } = useQuery(GET_DATA, {
variables: {
name: 'London',
country: 'GB',
},
});