I'm trying to read some parameters passed down through variables on my backend, lets see:
(this method is inside AuthenticationService
, injected in my graphql controller, see bellow)
@GraphQLMutation(name = "getSessionToken")
public AuthReturn getSessionToken(@GraphQLArgument(name = "user") String u, @GraphQLArgument(name = "password") String p) {...}
And here is my graphQL request:
mutation ($user: String!, $password: String!) {
getSessionToken(user: $user, password: $password) {
status
payload
}
}
and my variables:
{ "user": "myuser", "password": "mypass"}
but when I try to run this sample codes, the following error is showed:
{"timestamp":"2019-07-29T17:18:32.753+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 162] (through reference chain: java.util.LinkedHashMap[\"variables\"])","path":"/graphql"}
[Edit] And here is my Controller:
@RestController
public class GraphQLController {
private final GraphQL graphQL;
public GraphQLController(AgendamentoService agendamentos, ConfiguracaoService config, ProcessoService processos, ParametroService parametros, AuthenticationService autenticacao) {
GraphQLSchema schema = new GraphQLSchemaGenerator()
.withResolverBuilders(
//Resolve by annotations
new AnnotatedResolverBuilder())
.withOperationsFromSingletons(agendamentos, config, processos, parametros, autenticacao)
.withValueMapperFactory(new JacksonValueMapperFactory())
.generate();
graphQL = GraphQL.newGraphQL(schema).build();
}
@CrossOrigin
@PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public Map<String, Object> graphql(@RequestBody Map<String, String> request, HttpServletRequest raw) {
// em context estamos passando o Request, usamos para fazer as verificacoes de autenticacao com GraphQl
ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput()
.query(request.get("query"))
.operationName(request.get("operationName"))
.context(raw)
.build());
return executionResult.toSpecification();
}
}
but if I run this mutation without passing parameters as variables
on request, every thing works properly. What can I do to pass variables to my graphQl requests? Thanks in advance.