【发布时间】:2021-01-04 08:50:43
【问题描述】:
我正在尝试设置一个突变,我在我的 SDL 架构中使用输入类型
schema {
query: QueryType
mutation: MutationType
}
....
type Currency {
id: ID!,
name: String
code: String
...
}
type MutationType {
createCurrency(input: CurrencyInput): Currency
}
input currencyInput {
name: String!
code: String!
}
我通过的查询是
{
"query": "mutation { createCurrency(input: $input) { id name code } }",
"variables": { "input": {"name": "NewCurrency", "code": "NCY"} }
}
我正在传递查询和变量
Map<String, Object> variables = new HashMap<String, Object>();
....
// Data is a com.fasterxml.jackson.databind.JsonNode
variables.put("input", data.get("variables").get("input"));
ExecutionInput executionInput = ExecutionInput.newExecutionInput()
.query(query)
.variables(variables)
.build();
但是,我不断收到验证错误
{message=Validation error of type UndefinedVariable: Undefined variable input @ 'createCurrency', locations=[{line=1, column=34}], extensions={classification=ValidationError}}
我是否以错误的格式传递变量? 任何帮助将非常感激! :)
【问题讨论】:
-
错误的查询/变异语法...graphql.org/learn/queries/#variables
-
@xadm 你有他们的例子的 SDL 模式的例子吗?或者你能具体说明什么问题吗? :)
-
$input: inputType ... input: $input- 两个“步骤” -
@xadm 所以基本上我需要像这样构建我的查询? “查询”:突变 { createCurrency($input currencyInput) { createCurrency(input $input) { id name code } } }
-
几乎,关闭,不必要的括号...阅读文档,在 graphiql/playground 中尝试,它会提示正确的语法并突出显示错误