|
19 | 19 | import java.io.InputStream;
|
20 | 20 | import java.nio.charset.StandardCharsets;
|
21 | 21 | import java.util.*;
|
| 22 | +import java.util.stream.Collectors; |
22 | 23 |
|
23 | 24 | import javax.servlet.ServletException;
|
24 | 25 |
|
@@ -127,7 +128,38 @@ void shouldPassFile() throws Exception {
|
127 | 128 |
|
128 | 129 | assertThat(servletResponse.getContentAsString())
|
129 | 130 | .isEqualTo("{\"data\":{\"fileUpload\":\"foo.txt\"}}");
|
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + void shouldPassListOfFiles() throws Exception { |
| 135 | + GraphQlHttpHandler handler = GraphQlSetup.schemaContent( |
| 136 | + "type Query { ping: String } \n" + |
| 137 | + "scalar Upload\n" + |
| 138 | + "type Mutation {\n" + |
| 139 | + " multipleFilesUpload(multipleFileInputs: [Upload!]!): [String!]!\n" + |
| 140 | + "}") |
| 141 | + .mutationFetcher("multipleFilesUpload", (env) -> ((Collection<MultipartFile>) env.getVariables().get("multipleFileInputs")).stream().map(multipartFile -> multipartFile.getOriginalFilename()).collect(Collectors.toList())) |
| 142 | + .runtimeWiring(builder -> builder.scalar(GraphQLScalarType.newScalar() |
| 143 | + .name("Upload") |
| 144 | + .coercing(new UploadCoercing()) |
| 145 | + .build())) |
| 146 | + .toHttpHandler(); |
| 147 | + |
| 148 | + Collection<Resource> resources = new ArrayList<>(); |
| 149 | + resources.add(new ClassPathResource("/foo.txt")); |
| 150 | + resources.add(new ClassPathResource("/bar.txt")); |
130 | 151 |
|
| 152 | + MockHttpServletRequest servletRequest = createMultipartServletRequest( |
| 153 | + "mutation MultipleFilesUpload($multipleFileInputs: [Upload!]!) " + |
| 154 | + "{multipleFilesUpload(multipleFileInputs: $multipleFileInputs) }", |
| 155 | + MediaType.APPLICATION_GRAPHQL_VALUE, |
| 156 | + Collections.singletonMap("multipleFileInputs", resources) |
| 157 | + ); |
| 158 | + |
| 159 | + MockHttpServletResponse servletResponse = handleMultipartRequest(servletRequest, handler); |
| 160 | + |
| 161 | + assertThat(servletResponse.getContentAsString()) |
| 162 | + .isEqualTo("{\"data\":{\"multipleFilesUpload\":[\"foo.txt\",\"bar.txt\"]}}"); |
131 | 163 | }
|
132 | 164 |
|
133 | 165 | @Test
|
|
0 commit comments