Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/graphql/ExecutionResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface ExecutionResult {

List<GraphQLError> getErrors();

ExecutionResult toSpecification();
}
32 changes: 32 additions & 0 deletions src/main/java/graphql/ExecutionResultImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,36 @@ public List<GraphQLError> getErrors() {
return new ArrayList<>(errors);
}

@Override
public ExecutionResult toSpecification() {
return (errors == null || errors.isEmpty()) ? new ExecutionResultWithoutErrors(data) : this;
}


private static class ExecutionResultWithoutErrors implements ExecutionResult {

private Object data;
private final transient List<GraphQLError> errors = new ArrayList<>();

ExecutionResultWithoutErrors(Object data) {
this.data = data;
}

@Override
public <T> T getData() {
//noinspection unchecked
return (T) data;
}

@Override
public List<GraphQLError> getErrors() {
return errors;
}

@Override
public ExecutionResult toSpecification() {
return this;
}
}

}
9 changes: 4 additions & 5 deletions src/main/java/graphql/schema/StaticDataFetcher.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package graphql.schema;


public class StaticDataFetcher implements DataFetcher {
public class StaticDataFetcher<T> implements DataFetcher<T> {

private final T value;

private final Object value;

public StaticDataFetcher(Object value) {
public StaticDataFetcher(T value) {
this.value = value;
}

@Override
public Object get(DataFetchingEnvironment environment) {
public T get(DataFetchingEnvironment environment) {
return value;
}
}