-2

I want to consumer graphQl API. I know we need to use http requester to call graphQl. I need some info on forming mutation request using dwl. I was trying to hit this service https://www.predic8.de/fruit-shop-graphql using below

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

its throwing bad request But when using below

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

its working. I want to use above format. Are both not valid requests. Please share me your knowledge or guide me to right blog to refer.

Prudhvi B
  • 144
  • 2
  • 13

1 Answers1

1

Since GraphQL is not a supported format for DataWeave at this time, you have to write the query yourself as a string. You can however use DataWeave to create the body of a POST request for a query.

Example:

%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"
      }
    }
}
aled
  • 21,330
  • 3
  • 27
  • 34