I have endpoint where my request works when it is:
query {
getItem(dictionaryType: "test1") {
code
name
description
}
}
It works fine, see:
I want to test variable - so i want to change it to sth like:
query {
getItem($dictionaryType: String) {
code
name
description
}
}
variables {
dictionaryType: "test1"
}
I do not want to use any other tool than postman, or i would rather not use other format than text. When executing the second ouput i get following error:
"errors": [
{
"message": "Invalid Syntax",
"locations": [
{
"line": 2,
"column": 9,
"sourceName": null
}
],
How to fix the syntax of the request?
Edit:
I have even problem with request with syntax like here: https://stackoverflow.com/a/50043390/4983983
query { getDataTypes }
To translate it to json For example:
{"query": "{getDataTypes}"}
Does not work and gives JSON parse error:
Cannot deserialize instance of
java.lang.Stringout of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
java.lang.Stringout of START_OBJECT token\n at [Source: (PushbackInputStream
error.
Currently the code
for Posts
endpoints looks like:
@PostMapping("graphql")
public ResponseEntity<Object> getResource(@RequestBody String query) {
ExecutionResult result = graphQL.execute(query);
return new ResponseEntity<Object>(result, HttpStatus.OK);
}
If i change it to:
@PostMapping("graphql")
public ResponseEntity<Object> getResource(@RequestBody Object query) { // String query
ExecutionResult result;
if (query instanceof String) {
result = graphQL.execute(query.toString());
} else{
Map b = (HashMap) query;
result = graphQL.execute(b.get("query").toString());
}
return new ResponseEntity<Object>(result, HttpStatus.OK);
}
Now it seems only json
versions works. Cause when i use text i get:
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'text/plain;charset=UTF-8' not supported",
"path": "/graphql"
Is there other config option for that matter?? I don't know if the variables
will be well handled in the last example.