简体   繁体   English

GraphQL Java - 变异

[英]GraphQL Java - Mutation

I'm trying to set up a mutation where I'm using the input type in my SDL schema我正在尝试设置一个突变,其中我在我的 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!
}

The query I'm passing is我传递的查询是

{
"query": "mutation { createCurrency(input: $input) { id name code } }",
"variables": { "input": {"name": "NewCurrency", "code": "NCY"} }
}

I'm passing in the query and variables as such我正在传递查询和变量

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();

However, I keep getting a validation error但是,我不断收到验证错误

{message=Validation error of type UndefinedVariable: Undefined variable input @ 'createCurrency', locations=[{line=1, column=34}], extensions={classification=ValidationError}}

Am I passing in the variables in the wrong format?我是否以错误的格式传递变量? Any help would be much appreciated!任何帮助将非常感激! :) :)

My request query was incorrect.我的请求查询不正确。 This is an example of a correct mutation query with variables这是一个带有变量的正确变异查询的例子

{
    "query": "mutation($input: CurrencyInput) { currency(input: $input) { id name code } }",
    "variables": {
        "input": {
            "name": "newName",
            "code": "NCY"
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM