Reputation: 154
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.
Upvotes: 0
Views: 153
Reputation: 1910
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]
}
}
Your issue would appear to be more with your GraphQL. Products is defined as [Int]!
in the schema, and you need to pass in the individual arguments - I don't see an addCategoryInput
defined anywhere in the schema, and addCategory
is expecting individual arguments.
Upvotes: 1