spring-boot-graphql-query-example icon indicating copy to clipboard operation
spring-boot-graphql-query-example copied to clipboard

GraphiQL

Open ronen1malka opened this issue 6 years ago • 1 comments

How can I use GraphiQL to query? I can query using Postman, but GraphiQL show and error:

{
  "errors": [
    {
      "message": "Invalid Syntax",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ],
      "errorType": "InvalidSyntax"
    }
  ],
  "data": null,
  "extensions": null
}

And in the app console I can see the following error: graphql.GraphQL : Executing request. operation name: null. Request: {"query":"{\n\n\n\tbook (id: \"111\"){\n\t\tisn\n\t\ttitle\n\t\tauthors\n\t}\n\n\n}","variables":null,"operationName":null}

It seems that GraphiQL add "query" at the top of the request.

ronen1malka avatar Mar 25 '19 09:03 ronen1malka

Here is the graphQL documentation -

image

In order to support "application/graphql" content type header, it needs to treat the HTTP POST body contents as the GraphQL query string.

https://github.com/TechPrimers/spring-boot-graphql-query-example/blob/f7fc933d4d95107cbd1a5763c071223c160cc7ad/src/main/java/com/techprimers/graphql/springbootgrapqlexample/resource/BookResource.java#L21

It looks like, "query" is treated as JSON instead of GraphQL query.

Checkout - https://stackoverflow.com/a/56615072/2500390

MacNale avatar Feb 09 '21 04:02 MacNale