【问题标题】:Mule4# Valid DWL to format graphQL requestMule4# 有效的 DWL 来格式化 graphQL 请求
【发布时间】:2021-04-09 21:03:33
【问题描述】:

我想使用 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    }  }}"
}

它的工作。 我想使用上述格式。都是无效请求。 请分享您的知识或指导我到正确的博客进行参考。

【问题讨论】:

  • 在编码之前使用“查询变量”在操场上测试查询...分别定义$id$name$products 变量...在API 中没有input,没有机会工作

标签: graphql dataweave mule4


【解决方案1】:
output application/json
---
{
  query: "mutation(\$id:Int!,\$name:String!,\$products:[Int]!) { addCategory(id:\$id, name:\$name, products:\$products) { name products { name } } }",
  variables: {
    id: 6,
    name: "Green Fruits",
    products: [8]
  }
}

您的问题似乎更多地与您的 GraphQL 有关。 Products 在架构中定义为 [Int]!,您需要传入单独的参数 - 我没有看到架构中任何地方定义了 addCategoryInput,而 addCategory 需要单独的参数。

【讨论】:

    猜你喜欢
    • 2022-12-26
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多