【发布时间】:2019-12-28 11:30:35
【问题描述】:
我是 GraphQL 的新手。我知道这是一个基本问题,但希望有人可以帮助我在我的查询中添加变量,因为我尝试了很多次但都失败了:(
在我的查询中,使用了以下架构:
type Query {
ContinentInfo(id: ID): Continent
}
type Continent {
id : ID
name: String
countries: [Country]
}
type Country {
id : ID
name : String
population: Float
}
以下查询执行成功:
{
ContinentInfo(id: "continent01") {
name
countries {
name
population
}
}
}
然后我想在查询中添加更多条件,例如添加一个变量“populationMoreThan”来过滤结果。因此查询可能如下所示:
{
ContinentInfo(id: "continent01") {
name
countries(populationMoreThan: $populationMoreThan) {
name
population
}
}
}
但当我尝试在架构和查询中添加此变量时,它总是失败。 谁能给我一个在我的情况下添加变量的例子? 另外,看起来我需要将参数值传递给查询?现在我使用 graphql.GraphQL.execute(queryString) 来传递查询字符串。这里如何传递变量值?
【问题讨论】:
标签: graphql graphql-java