|
6 | 6 | import com.fasterxml.jackson.databind.*; |
7 | 7 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
8 | 8 | import com.google.common.io.ByteStreams; |
| 9 | +import com.google.common.io.CharStreams; |
9 | 10 | import graphql.ExecutionInput; |
10 | 11 | import graphql.ExecutionResult; |
11 | 12 | import graphql.GraphQL; |
@@ -43,6 +44,7 @@ public abstract class GraphQLServlet extends HttpServlet implements Servlet, Gra |
43 | 44 | public static final Logger log = LoggerFactory.getLogger(GraphQLServlet.class); |
44 | 45 |
|
45 | 46 | public static final String APPLICATION_JSON_UTF8 = "application/json;charset=UTF-8"; |
| 47 | + public static final String APPLICATION_GRAPHQL = "application/graphql"; |
46 | 48 | public static final int STATUS_OK = 200; |
47 | 49 | public static final int STATUS_BAD_REQUEST = 400; |
48 | 50 |
|
@@ -114,12 +116,16 @@ public GraphQLServlet(ObjectMapperConfigurer objectMapperConfigurer, List<GraphQ |
114 | 116 | final Object rootObject = createRootObject(Optional.of(request), Optional.of(response)); |
115 | 117 |
|
116 | 118 | try { |
117 | | - if (request.getContentType() != null && request.getContentType().startsWith("multipart/form-data") && !request.getParts().isEmpty()) { |
| 119 | + if (APPLICATION_GRAPHQL.equals(request.getContentType())) { |
| 120 | + String query = CharStreams.toString(request.getReader()); |
| 121 | + doQuery(query, null, null, getSchemaProvider().getSchema(request), context, rootObject, request, response); |
| 122 | + } else if (request.getContentType() != null && request.getContentType().startsWith("multipart/form-data") && !request.getParts().isEmpty()) { |
118 | 123 | final Map<String, List<Part>> fileItems = request.getParts().stream() |
119 | 124 | .collect(Collectors.toMap( |
120 | 125 | Part::getName, |
121 | 126 | Collections::singletonList, |
122 | 127 | (l1, l2) -> Stream.concat(l1.stream(), l2.stream()).collect(Collectors.toList()))); |
| 128 | + |
123 | 129 | context.setFiles(Optional.of(fileItems)); |
124 | 130 |
|
125 | 131 | if (fileItems.containsKey("graphql")) { |
|
0 commit comments