Skip to content

Commit fccbe35

Browse files
andimarekbbakerman
andauthored
remove absolute graphql error (#1941)
* remove absolute graphql error and special relative error flag in DataFetcherResult * cleanup, fixing tests Co-authored-by: Brad Baker <bbaker@atlassian.com>
1 parent aa9a93d commit fccbe35

9 files changed

Lines changed: 73 additions & 629 deletions

src/main/java/graphql/execution/AbsoluteGraphQLError.java

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

src/main/java/graphql/execution/DataFetcherResult.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class DataFetcherResult<T> {
3030
private final T data;
3131
private final List<GraphQLError> errors;
3232
private final Object localContext;
33-
private final boolean mapRelativeErrors;
3433

3534
/**
3635
* Creates a data fetcher result
@@ -43,14 +42,13 @@ public class DataFetcherResult<T> {
4342
@Internal
4443
@Deprecated
4544
public DataFetcherResult(T data, List<GraphQLError> errors) {
46-
this(data, errors, null, false);
45+
this(data, errors, null);
4746
}
4847

49-
private DataFetcherResult(T data, List<GraphQLError> errors, Object localContext, boolean mapRelativeErrors) {
48+
private DataFetcherResult(T data, List<GraphQLError> errors, Object localContext) {
5049
this.data = data;
5150
this.errors = ImmutableList.copyOf(assertNotNull(errors));
5251
this.localContext = localContext;
53-
this.mapRelativeErrors = mapRelativeErrors;
5452
}
5553

5654
/**
@@ -83,20 +81,6 @@ public Object getLocalContext() {
8381
return localContext;
8482
}
8583

86-
/**
87-
* When this returns true, the data fetching code will map this error as being a relative error from the existing field.
88-
* <p>
89-
* This is useful when you are calling a down stream graphql system and you want to make the errors appear to be from a point
90-
* relative to the currently executing field.
91-
* <p>
92-
* By default this behavior is off
93-
*
94-
* @return true if relative error mapping should occur.
95-
*/
96-
public boolean isMapRelativeErrors() {
97-
return mapRelativeErrors;
98-
}
99-
10084
/**
10185
* This helps you transform the current DataFetcherResult into another one by starting a builder with all
10286
* the current values and allows you to transform it how you want.
@@ -126,13 +110,11 @@ public static class Builder<T> {
126110
private T data;
127111
private Object localContext;
128112
private final List<GraphQLError> errors = new ArrayList<>();
129-
private boolean mapRelativeErrors = false;
130113

131114
public Builder(DataFetcherResult<T> existing) {
132115
data = existing.getData();
133116
localContext = existing.getLocalContext();
134117
errors.addAll(existing.getErrors());
135-
mapRelativeErrors = existing.isMapRelativeErrors();
136118
}
137119

138120
public Builder(T data) {
@@ -157,11 +139,6 @@ public Builder<T> error(GraphQLError error) {
157139
return this;
158140
}
159141

160-
public Builder<T> mapRelativeErrors(boolean mapRelativeErrors) {
161-
this.mapRelativeErrors = mapRelativeErrors;
162-
return this;
163-
}
164-
165142
/**
166143
* @return true if there are any errors present
167144
*/
@@ -175,7 +152,7 @@ public Builder<T> localContext(Object localContext) {
175152
}
176153

177154
public DataFetcherResult<T> build() {
178-
return new DataFetcherResult<>(data, errors, localContext, mapRelativeErrors);
155+
return new DataFetcherResult<>(data, errors, localContext);
179156
}
180157
}
181158
}

src/main/java/graphql/execution/ExecutionStrategy.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,9 @@ protected FetchedValue unboxPossibleDataFetcherResult(ExecutionContext execution
301301
Object result) {
302302

303303
if (result instanceof DataFetcherResult) {
304-
DataFetcherResult<?> dataFetcherResult = (DataFetcherResult<?>) result;
305-
if (dataFetcherResult.isMapRelativeErrors()) {
306-
dataFetcherResult.getErrors().stream()
307-
.map(relError -> new AbsoluteGraphQLError(parameters, relError))
308-
.forEach(executionContext::addError);
309-
} else {
310-
dataFetcherResult.getErrors().forEach(executionContext::addError);
311-
}
304+
//noinspection unchecked
305+
DataFetcherResult<?> dataFetcherResult = (DataFetcherResult) result;
306+
dataFetcherResult.getErrors().forEach(executionContext::addError);
312307

313308
Object localContext = dataFetcherResult.getLocalContext();
314309
if (localContext == null) {

src/main/java/graphql/execution/nextgen/ValueFetcher.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import graphql.GraphQLError;
88
import graphql.Internal;
99
import graphql.collect.ImmutableKit;
10-
import graphql.execution.AbsoluteGraphQLError;
1110
import graphql.execution.Async;
1211
import graphql.execution.DataFetcherResult;
1312
import graphql.execution.DefaultValueUnboxer;
@@ -44,7 +43,6 @@
4443
import java.util.concurrent.CompletionStage;
4544
import java.util.function.Supplier;
4645

47-
import static graphql.collect.ImmutableKit.map;
4846
import static graphql.schema.DataFetchingEnvironmentImpl.newDataFetchingEnvironment;
4947
import static java.util.Collections.singletonList;
5048

@@ -211,13 +209,8 @@ private void handleFetchedValue(Object fetchedValue, CompletableFuture<Object> c
211209
private FetchedValue unboxPossibleDataFetcherResult(MergedField sameField, ResultPath resultPath, FetchedValue result, Object localContext) {
212210
if (result.getFetchedValue() instanceof DataFetcherResult) {
213211

214-
List<GraphQLError> addErrors;
215212
DataFetcherResult<?> dataFetcherResult = (DataFetcherResult) result.getFetchedValue();
216-
if (dataFetcherResult.isMapRelativeErrors()) {
217-
addErrors = map(dataFetcherResult.getErrors(), relError -> new AbsoluteGraphQLError(sameField, resultPath, relError));
218-
} else {
219-
addErrors = ImmutableList.copyOf(dataFetcherResult.getErrors());
220-
}
213+
List<GraphQLError> addErrors = ImmutableList.copyOf(dataFetcherResult.getErrors());
221214
List<GraphQLError> newErrors = ImmutableKit.concatLists(result.getErrors(), addErrors);
222215

223216
Object newLocalContext = dataFetcherResult.getLocalContext();

0 commit comments

Comments
 (0)