20
20
import java .util .Map ;
21
21
import java .util .function .Supplier ;
22
22
23
+ import static java .util .stream .Collectors .toList ;
24
+
23
25
/**
24
26
* @author Andrew Potter
25
27
*/
26
28
public class GraphQLObjectMapper {
27
29
private static final TypeReference <Map <String , List <String >>>
28
- MULTIPART_MAP_TYPE_REFERENCE = new TypeReference <Map <String , List <String >>>() {
29
- };
30
+ MULTIPART_MAP_TYPE_REFERENCE = new TypeReference <Map <String , List <String >>>() {
31
+ };
30
32
private final ObjectMapperProvider objectMapperProvider ;
31
33
private final Supplier <GraphQLErrorHandler > graphQLErrorHandlerSupplier ;
32
34
@@ -41,7 +43,7 @@ protected GraphQLObjectMapper(ObjectMapperProvider objectMapperProvider, Supplie
41
43
public ObjectMapper getJacksonMapper () {
42
44
ObjectMapper result = mapper ;
43
45
if (result == null ) { // First check (no locking)
44
- synchronized (this ) {
46
+ synchronized (this ) {
45
47
result = mapper ;
46
48
if (result == null ) { // Second check (with locking)
47
49
mapper = result = objectMapperProvider .provide ();
@@ -107,7 +109,7 @@ public ExecutionResult sanitizeErrors(ExecutionResult executionResult) {
107
109
List <GraphQLError > errors = executionResult .getErrors ();
108
110
109
111
GraphQLErrorHandler errorHandler = graphQLErrorHandlerSupplier .get ();
110
- if (errorHandler .errorsPresent (errors )) {
112
+ if (errorHandler .errorsPresent (errors )) {
111
113
errors = errorHandler .processErrors (errors );
112
114
} else {
113
115
errors = null ;
@@ -128,14 +130,14 @@ public Map<String, Object> convertSanitizedExecutionResult(ExecutionResult execu
128
130
final Map <String , Object > result = new LinkedHashMap <>();
129
131
130
132
if (areErrorsPresent (executionResult )) {
131
- result .put ("errors" , executionResult .getErrors ());
133
+ result .put ("errors" , executionResult .getErrors (). stream (). map ( err -> err . toSpecification ()). collect ( toList ()) );
132
134
}
133
135
134
- if (executionResult .getExtensions () != null && !executionResult .getExtensions ().isEmpty ()){
136
+ if (executionResult .getExtensions () != null && !executionResult .getExtensions ().isEmpty ()) {
135
137
result .put ("extensions" , executionResult .getExtensions ());
136
138
}
137
139
138
- if (includeData ) {
140
+ if (includeData ) {
139
141
result .put ("data" , executionResult .getData ());
140
142
}
141
143
@@ -150,7 +152,7 @@ public Map<String, Object> deserializeVariables(String variables) {
150
152
}
151
153
}
152
154
153
- public Map <String ,List <String >> deserializeMultipartMap (Part part ) {
155
+ public Map <String , List <String >> deserializeMultipartMap (Part part ) {
154
156
try {
155
157
return getJacksonMapper ().readValue (part .getInputStream (), MULTIPART_MAP_TYPE_REFERENCE );
156
158
} catch (IOException e ) {
0 commit comments