Skip to content

fix: support new graphql context #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: support poorly formatted graphql queries fixes #385
  • Loading branch information
oliemansm committed Jan 23, 2022
commit 03c2fc01e1ff71e2cbf27db46a6cd8ddd9476c94
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import graphql.kickstart.servlet.input.GraphQLInvocationInputFactory;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand All @@ -27,12 +28,12 @@ class GraphQLPostInvocationInputParser extends AbstractGraphQLInvocationInputPar
public GraphQLInvocationInput getGraphQLInvocationInput(
HttpServletRequest request, HttpServletResponse response) throws IOException {
if (APPLICATION_GRAPHQL.equals(request.getContentType())) {
String query = request.getReader().lines().collect(joining());
String query = request.getReader().lines().collect(joining(" "));
GraphQLRequest graphqlRequest = GraphQLRequest.createQueryOnlyRequest(query);
return invocationInputFactory.create(graphqlRequest, request, response);
}

String body = request.getReader().lines().collect(joining());
String body = request.getReader().lines().collect(joining(" "));
if (isSingleQuery(body)) {
GraphQLRequest graphqlRequest = graphQLObjectMapper.readGraphQLRequest(body);
return invocationInputFactory.create(graphqlRequest, request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,25 @@ class AbstractGraphQLHttpServletSpec extends Specification {
getResponseContent().data.echo == "test"
}

def "query over HTTP POST multiline body returns data"() {
setup:
request.setContent("""
query { object {
a
b
} }""".bytes)
request.setMethod("POST")
request.contentType = "application/graphql"

when:
servlet.doPost(request, response)

then:
response.getStatus() == STATUS_OK
response.getContentType() == CONTENT_TYPE_JSON_UTF8
getResponseContent().data.object.b == null
}

def "disabling async support on request over HTTP POST does not start async request"() {
setup:
servlet = TestUtils.createDefaultServlet({ env -> env.arguments.arg }, { env -> env.arguments.arg }, { env ->
Expand Down