Skip to content

Commit fb7cc8c

Browse files
committed
Deprecated getFiles and added clearer replacements
1 parent bca69e6 commit fb7cc8c

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies {
4141
testRuntime "cglib:cglib-nodep:3.2.4"
4242
testRuntime "org.objenesis:objenesis:2.5.1"
4343
testCompile 'org.slf4j:slf4j-simple:1.7.24'
44-
testCompile 'org.springframework:spring-test:4.3.7.RELEASE' // MockHttpServletRequest, MockHttpServletResponse
44+
testCompile 'org.springframework:spring-test:4.3.7.RELEASE'
4545
testRuntime 'org.springframework:spring-web:4.3.7.RELEASE'
4646

4747
// OSGi

src/main/java/graphql/servlet/AbstractGraphQLHttpServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
142142
variablesMap.ifPresent(map -> graphQLRequests.forEach(r -> mapMultipartVariables(r, map, fileItems)));
143143
GraphQLBatchedInvocationInput invocationInput =
144144
invocationInputFactory.create(graphQLRequests, request, response);
145-
invocationInput.getContext().setFiles(fileItems);
145+
invocationInput.getContext().setParts(fileItems);
146146
queryBatched(queryInvoker, graphQLObjectMapper, invocationInput, response);
147147
return;
148148
} else {
@@ -156,7 +156,7 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
156156
variablesMap.ifPresent(m -> mapMultipartVariables(graphQLRequest, m, fileItems));
157157
GraphQLSingleInvocationInput invocationInput =
158158
invocationInputFactory.create(graphQLRequest, request, response);
159-
invocationInput.getContext().setFiles(fileItems);
159+
invocationInput.getContext().setParts(fileItems);
160160
query(queryInvoker, graphQLObjectMapper, invocationInput, response);
161161
return;
162162
}

src/main/java/graphql/servlet/GraphQLContext.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import javax.servlet.http.Part;
99
import javax.websocket.Session;
1010
import javax.websocket.server.HandshakeRequest;
11+
import java.util.Collection;
12+
import java.util.HashMap;
1113
import java.util.List;
1214
import java.util.Map;
1315
import java.util.Optional;
16+
import java.util.stream.Collectors;
1417

1518
public class GraphQLContext {
1619

@@ -20,7 +23,7 @@ public class GraphQLContext {
2023
private HandshakeRequest handshakeRequest;
2124

2225
private Subject subject;
23-
private Map<String, List<Part>> files;
26+
private Map<String, List<Part>> parts;
2427

2528
private DataLoaderRegistry dataLoaderRegistry;
2629

@@ -75,12 +78,31 @@ public Optional<HandshakeRequest> getHandshakeRequest() {
7578
return Optional.ofNullable(handshakeRequest);
7679
}
7780

81+
public List<Part> getFileParts() {
82+
return getParts().values()
83+
.stream()
84+
.flatMap(Collection::stream)
85+
.filter(part -> part.getContentType() != null)
86+
.collect(Collectors.toList());
87+
}
88+
89+
/**
90+
* Contrary what the name implies this method returns all parts and not just the ones that represent actual files.
91+
* That's why this method has been deprecated in favor of the ones that communicate their intent more clearly.
92+
*
93+
* @deprecated use {@link #getParts()} or {@link #getFileParts()} instead
94+
*/
95+
@Deprecated
7896
public Optional<Map<String, List<Part>>> getFiles() {
79-
return Optional.ofNullable(files);
97+
return Optional.ofNullable(parts);
98+
}
99+
100+
public Map<String, List<Part>> getParts() {
101+
return parts != null ? parts : new HashMap<>();
80102
}
81103

82-
public void setFiles(Map<String, List<Part>> files) {
83-
this.files = files;
104+
public void setParts(Map<String, List<Part>> parts) {
105+
this.parts = parts;
84106
}
85107

86108
public Optional<DataLoaderRegistry> getDataLoaderRegistry() {

0 commit comments

Comments
 (0)