Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
GraphQL JSON-Http request towards Spring Boot parse failure why?

So, I'm using GraphQL in Java (Spring Boot) and running with Datafetchers. I'm trying to do a fetch with JSON but it seems like i never get it right. I can do a fetch in the client with Content-type: text/plain but not with 'application/json'.

WHY i use Java is because I'm doing school work based on Java and curious about graphql.

My query which works in postman and client with text/plain and been trying to add 'query' before 'GetAllUsers' and so on..

Query:

This is the request:

(I've been trying with axios also, with having no query type in body and just the query itself.. it runs the same error)

const PostData = () => {
  fetch('http://localhost:8080/api/allusersdata', {
    method: 'POST',
    credentials: 'include',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(testquery),
  })
    .then(res => {
      return res.json();
    })
    .then(data => console.log(data));

I get this error,

 notprivacysafe.graphql.GraphQL           : Query failed to parse : '{"query":"\n{\n    GetAllUsers\n         { \n             username \n             } \n}\n"}'
ExecutionResultImpl{errors=[InvalidSyntaxError{ message=Invalid Syntax : offending token '"query"' at line 1 column 2 ,offendingToken="query" ,locations=[SourceLocation{line=1, column=2}] ,sourcePreview={"query":"\n{\n    GetAllUsers\n         { \n             username \n             } \n}\n"}
}], data=null, dataPresent=false, extensions=null}

This is the endpoint:

@PostMapping("/allusersdata")
    public ResponseEntity<Object> allusers(@RequestBody String query) {
        try {
            ExecutionResult execute = graphQLService.getGraphQL().execute(query);
            System.out.println(query);
            return new ResponseEntity<>(execute,HttpStatus.OK);
        } catch(Exception e) {
            System.out.print(e);
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
    }

POSTMAN-request enter image description here

Headers in postman enter image description here

What do I miss?

Thank you in advance!

Different queries, different fetching-techniques.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda