X Tutup
Skip to content
Merged
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
27 changes: 0 additions & 27 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,33 +339,6 @@ DeferredExecutionSupport createDeferredExecutionSupport(ExecutionContext executi
return futures;
}

/**
* Called to fetch a value for a field and resolve it further in terms of the graphql query. This will call
* #fetchField followed by #completeField and the completed Object is returned.
* <p>
* An execution strategy can iterate the fields to be executed and call this method for each one
* <p>
* Graphql fragments mean that for any give logical field can have one or more {@link Field} values associated with it
* in the query, hence the fieldList. However, the first entry is representative of the field for most purposes.
*
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
*
* @return a {@link CompletableFuture} promise to an {@link Object} or the materialized {@link Object}
*
* @throws NonNullableFieldWasNullException in the future if a non-null field resolved to a null value
*/
@SuppressWarnings("unchecked")
@DuckTyped(shape = " CompletableFuture<Object> | Object")
protected Object resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
Object fieldWithInfo = resolveFieldWithInfo(executionContext, parameters);
if (fieldWithInfo instanceof CompletableFuture) {
return ((CompletableFuture<FieldValueInfo>) fieldWithInfo).thenCompose(FieldValueInfo::getFieldValueFuture);
} else {
return ((FieldValueInfo) fieldWithInfo).getFieldValueObject();
}
}

/**
* Called to fetch a value for a field and its extra runtime info and resolve it further in terms of the graphql query. This will call
* #fetchField followed by #completeField and the completed {@link graphql.execution.FieldValueInfo} is returned.
Expand Down
32 changes: 5 additions & 27 deletions src/test/groovy/graphql/execution/ExecutionStrategyTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class ExecutionStrategyTest extends Specification {
DataFetchingEnvironment environment

when:
executionStrategy.resolveField(executionContext, parameters)
executionStrategy.resolveFieldWithInfo(executionContext, parameters)

then:
1 * dataFetcher.get(_,_,_) >> { environment = (it[2] as Supplier<DataFetchingEnvironment>).get() }
Expand Down Expand Up @@ -636,7 +636,7 @@ class ExecutionStrategyTest extends Specification {
}

when:
overridingStrategy.resolveField(executionContext, parameters)
overridingStrategy.resolveFieldWithInfo(executionContext, parameters)

then:
handlerCalled == true
Expand All @@ -646,29 +646,6 @@ class ExecutionStrategyTest extends Specification {
exceptionWhileDataFetching.getMessage().contains('This is the exception you are looking for')
}

def "test that the old legacy method is still useful for those who derive new execution strategies"() {

def expectedException = new UnsupportedOperationException("This is the exception you are looking for")

//noinspection GroovyAssignabilityCheck,GroovyUnusedAssignment
def (ExecutionContext executionContext, GraphQLFieldDefinition fieldDefinition, ResultPath expectedPath, ExecutionStrategyParameters parameters, Field field, SourceLocation sourceLocation) = exceptionSetupFixture(expectedException)


ExecutionStrategy overridingStrategy = new ExecutionStrategy() {
@Override
CompletableFuture<ExecutionResult> execute(ExecutionContext ec, ExecutionStrategyParameters p) throws NonNullableFieldWasNullException {
null
}
}

when:
overridingStrategy.resolveField(executionContext, parameters)

then:
executionContext.errors.size() == 1
def exceptionWhileDataFetching = executionContext.errors[0] as ExceptionWhileDataFetching
exceptionWhileDataFetching.getMessage().contains('This is the exception you are looking for')
}

def "#2519 data fetcher errors for a given field appear in FetchedResult within instrumentation"() {
def expectedException = new UnsupportedOperationException("This is the exception you are looking for")
Expand Down Expand Up @@ -700,7 +677,7 @@ class ExecutionStrategyTest extends Specification {
}

when:
overridingStrategy.resolveField(instrumentedExecutionContext, params)
overridingStrategy.resolveFieldWithInfo(instrumentedExecutionContext, params)

then:
FetchedValue fetchedValue = instrumentation.fetchedValues.get("someField")
Expand Down Expand Up @@ -761,7 +738,8 @@ class ExecutionStrategyTest extends Specification {
.build()

when:
executionStrategy.resolveField(executionContext, parameters).join()
FieldValueInfo fieldValueInfo = (executionStrategy.resolveFieldWithInfo(executionContext, parameters) as CompletableFuture).join()
(fieldValueInfo.fieldValueObject as CompletableFuture).join()

then:
thrown(CompletionException)
Expand Down
Loading
X Tutup