I am trying to accept an array of objects as input from the client, but graphql rejects it because of format.
{"query': "mutation{updateDetails(input: [{\"firstname\": \"Pradeep\",\"last\":\"G\"}, {\"firstname\": \"sandeep\",\"last\":\"G\"}])}}
Grqphql throws an error like Expected Name but got String. It's because the first name is encoded in Quotes. But my client is using python code and not able to send keys without quotes. How do I solve this?
There seems to be a small typo in your JSON. You open the string with double quotes, but after the first attribute query, then you close it with a single quote.
Then keep in mind, that a graphql query is not JSON. GraphQL defines its own language. In GraphQL Strings must be quoted with double quotes. Single quotes are not allowed.
And variables (e.g. for mutations as in your example) must be posted without any quotes around them. http://spec.graphql.org/June2018/#sec-Language.Variables
What I do: I create the value of the GraphQL query, ie. the value of the query attribute manually. And only then do I wrap this in JSON.
This is my HTTP POST entity: mime type = application/json
String graphQLQueryString = "{ ... }" // this is not JSON!
String jsonPayload = JSONObject().put("query", graphQLQueryString)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With