question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExecutionResult does not follow spec

See original GitHub issue

The spec says

https://facebook.github.io/graphql/#sec-Response-Format

Response Format

A response to a GraphQL operation must be a map.

If the operation included execution, the response map must contain a first entry with key data. The value of this entry is described in the “Data” section. If the operation failed before execution, due to a syntax error, missing information, or validation error, this entry must not be present.

If the operation encountered any errors, the response map must contain a next entry with key errors. The value of this entry is described in the “Errors” section. If the operation completed without encountering any errors, this entry must not be present.

So ExecutionResult is a map like thing that should NOT have an error field if there are no errors and vice versa.

So for example this in invalid

{
  "errors": [],
  "data": {
    "hero": {
      "name": "R2-D2"
    }
  }
}

since it has data in it but no errors

But JSON serialisation libraries such as GSON and others WILL include these fields.

    private void returnAsJson(HttpServletResponse response, ExecutionResult executionResult) {
    response.setContentType("application/json");
    GSON.toJson(executionResult, response.getWriter());
}

I propose that we have a toMap() method on execution result that means its easy for HTTP service layers to implement the spec properly.

    private void returnAsJson(HttpServletResponse response, ExecutionResult executionResult) {
    response.setContentType("application/json");
    GSON.toJson(executionResult.toMap(), response.getWriter());
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bbakermancommented, May 31, 2017

So the spec says that if null is present and there are no errors then that is the result of the query

So graphql JSON encoder code is responsible for setting it up to encode nulls if it wants to follow spec

0reactions
bbakermancommented, Aug 24, 2017

Because the graphql-java library BY design does not want to get into the game of build JSON serialisation strategies

Would we would need one for Jackson / GSON / JSONP / Java 9 / SimpleJson …

Read more comments on GitHub >

github_iconTop Results From Across the Web

ExecutionResult (graphql-java 9.5 API) - javadoc.io
The graphql specification says that result of a call should be a map that follows certain rules on what items should be present....
Read more >
Execution - GraphQL Java
It will however assemble the results in order. The query result will follow the graphql specification and return object values assembled in query...
Read more >
RQM executionresult Rest API : Not able to get all the pages
I am using the switch "abbreviate=false" which is doing the trick. ... page is provided in the current page (see ATOM paging specification)....
Read more >
GraphQL java send custom error in json format - Stack Overflow
Once you get a hold of an ExecutionResult , you can create a map or ... But again, having a response that doesn't...
Read more >
PH28550: E-SIGNATURE POP UP DOES NOT DISPLAY WHEN ...
Steps to reproduce Prerequisite: The logged in user should have a Test Team Member ... E-Signature Required for Execution Result Formal Review -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found