88import javax .servlet .http .Part ;
99import javax .websocket .Session ;
1010import javax .websocket .server .HandshakeRequest ;
11+ import java .util .Collection ;
12+ import java .util .HashMap ;
1113import java .util .List ;
1214import java .util .Map ;
1315import java .util .Optional ;
16+ import java .util .stream .Collectors ;
1417
1518public 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