使用Mule 4中的graphQL API



我想消费graphQl API。我知道我们需要使用http请求程序来调用graphQl。我需要一些关于使用dwl形成突变请求的信息。我试着打这个服务https://www.predic8.de/fruit-shop-graphql使用低于

%dw2.0
outputapplication/json
---
{
"query": "mutation($input:addCategoryInput!) { addCategory(input:$input) { name products { name}} }",
"variables": {
"input": {
"id": 6,
"name": "Green Fruits",
"products": 8
}
}
}

它抛出的请求不正确但当使用低于时

%dw 2.0
output application/json
---
{
"query": "mutation {  addCategory(id: 6, name: "Green Fruits", products: 8) {    name    products {      name    }  }}"
}

它正在发挥作用。我想使用上面的格式。都不是有效的请求。请分享你的知识或引导我到右边的博客参考。

由于GraphQL目前不是DataWeave支持的格式,因此您必须将查询自己编写为字符串。但是,您可以使用DataWeave为查询创建POST请求的主体。

示例:

%dw 2.0
output application/json
---
{
"query": "mutation($schedule:PipelineScheduleCreateInput!) { pipelineScheduleCreate(input:$schedule) { pipelineScheduleEdge { node { label nextBuildAt cronline } } } }",
"variables": {
"schedule": {
"pipelineID": "UGlwZWxpbmUtLS02MzliNWJjOC0wMGZmLT",
"cronline": "@midnight",
"label": "Nightly build"
}
}
}

最新更新