graphql2rest icon indicating copy to clipboard operation
graphql2rest copied to clipboard

Always return JSON responses

Open thecodeboss opened this issue 4 years ago • 1 comments

When a GraphQL resolver that is hooked up to a REST endpoint returns null, graphql2rest returns a response with no body, and no Content-Type header.

The expected behavior in my opinion would be that the REST endpoint returns a JSON response containing the JSON null. By specifying res.json instead of res.send, the response will always contain a valid JSON response.

thecodeboss avatar Apr 20 '21 06:04 thecodeboss

@thecodeboss: after your change, what does graphql2rest return when the manifest defines a 204 No Content success status code (for, say, a DELETE operation)?

GraphQL will of course always return a JSON response, but even an empty JSON may be seen as violating the "No Content" standard for 204 HTTP code.

roy-mor avatar Apr 20 '21 16:04 roy-mor

Since an empty JSON object may be seen as violating the "No Content" standard for 204 HTTP code, we should not ALWAYS return JSON responses. Therefore closing this PR without merging.

roy-mor avatar Mar 08 '23 21:03 roy-mor