Skip to content

Commit 44b3e79

Browse files
committed
breaking changes: ExecutionResult is now an interface and contains generic GraphQLError's
1 parent 1939a41 commit 44b3e79

File tree

8 files changed

+71
-46
lines changed

8 files changed

+71
-46
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package graphql;
2+
3+
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
public interface ExecutionResult {
8+
9+
Map<String, Object> getResult();
10+
11+
List<GraphQLError> getErrors();
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package graphql;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public class ExecutionResultImpl implements ExecutionResult {
9+
10+
private Map<String, Object> result;
11+
12+
private final List<GraphQLError> errors = new ArrayList<>();
13+
14+
public void addErrors(List<? extends GraphQLError> errors) {
15+
this.errors.addAll(errors);
16+
}
17+
18+
public ExecutionResultImpl(List<? extends GraphQLError> errors) {
19+
this.errors.addAll(errors);
20+
}
21+
22+
public ExecutionResultImpl(Map<String, Object> result) {
23+
this.result = result;
24+
}
25+
26+
27+
public void setResult(Map<String, Object> result) {
28+
this.result = result;
29+
}
30+
31+
32+
@Override
33+
public Map<String, Object> getResult() {
34+
return result;
35+
}
36+
37+
@Override
38+
public List<GraphQLError> getErrors() {
39+
return new ArrayList<>(errors);
40+
}
41+
42+
43+
}

src/main/java/graphql/GraphQL.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import graphql.execution.Execution;
5-
import graphql.execution.ExecutionResult;
65
import graphql.language.Document;
76
import graphql.parser.Parser;
87
import graphql.schema.GraphQLSchema;
@@ -59,13 +58,13 @@ public ExecutionResult execute(String requestString, String operationName, Objec
5958
document = parser.parseDocument(requestString);
6059
} catch (RecognitionException e) {
6160
ValidationError validationError = new ValidationError(ValidationErrorType.InvalidSyntax);
62-
return new ExecutionResult(Arrays.asList(validationError));
61+
return new ExecutionResultImpl(Arrays.asList(validationError));
6362
}
6463

6564
Validator validator = new Validator();
6665
List<ValidationError> validationErrors = validator.validateDocument(graphQLSchema, document);
6766
if (validationErrors.size() > 0) {
68-
ExecutionResult result = new ExecutionResult(validationErrors);
67+
ExecutionResult result = new ExecutionResultImpl(validationErrors);
6968
return result;
7069
}
7170
Execution execution = new Execution(executorService);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package graphql;
2+
3+
4+
public interface GraphQLError {
5+
}

src/main/java/graphql/execution/Execution.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graphql.execution;
22

33

4+
import graphql.ExecutionResult;
5+
import graphql.ExecutionResultImpl;
46
import graphql.GraphQLException;
57
import graphql.language.Document;
68
import graphql.language.Field;
@@ -67,8 +69,8 @@ private ExecutionResult executeOperation(
6769
) {
6870
executeFieldsSerially(executionContext, operationRootType, root, fields);
6971
}
70-
Object result = executeFieldsParallel(executionContext, operationRootType, root, fields);
71-
return new ExecutionResult(result);
72+
Map<String,Object> result = executeFieldsParallel(executionContext, operationRootType, root, fields);
73+
return new ExecutionResultImpl(result);
7274
}
7375

7476
private Map<String, Object> executeFieldsSerially(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, Map<String, List<Field>> fields) {

src/main/java/graphql/execution/ExecutionResult.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/main/java/graphql/validation/ValidationError.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package graphql.validation;
22

33

4-
public class ValidationError {
4+
import graphql.GraphQLError;
5+
6+
public class ValidationError implements GraphQLError {
57

68
private final ValidationErrorType errorType;
79

src/test/groovy/graphql/GraphQLTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class GraphQLTest extends Specification {
8888
).build()
8989

9090
when:
91-
def errors = new GraphQL(schema).execute( '{ hello(arg:11) }').validationErrors
91+
def errors = new GraphQL(schema).execute( '{ hello(arg:11) }').errors
9292

9393
then:
9494
errors.size() == 1
@@ -103,7 +103,7 @@ class GraphQLTest extends Specification {
103103
).build()
104104

105105
when:
106-
def errors = new GraphQL(schema).execute( '{ hello(() }').validationErrors
106+
def errors = new GraphQL(schema).execute( '{ hello(() }').errors
107107

108108
then:
109109
errors.size() == 1

0 commit comments

Comments
 (0)