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
8 changes: 6 additions & 2 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.stream.IntStream;

import static graphql.execution.ExecutionTypeInfo.newTypeInfo;
import static graphql.execution.FieldCollectorParameters.newParameters;
Expand All @@ -45,6 +46,7 @@
import static graphql.introspection.Introspection.TypeNameMetaFieldDef;
import static graphql.schema.DataFetchingEnvironmentBuilder.newDataFetchingEnvironment;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.stream.Collectors.toList;

/**
* An execution strategy is give a list of fields from the graphql query to execute and find values for using a recursive strategy.
Expand Down Expand Up @@ -401,7 +403,9 @@ private Object unboxPossibleOptional(Object result) {

private Iterable<Object> toIterable(Object result) {
if (result.getClass().isArray()) {
result = Arrays.asList((Object[]) result);
return IntStream.range(0, Array.getLength(result))
.mapToObj(i -> Array.get(result, i))
.collect(toList());
}
//noinspection unchecked
return (Iterable<Object>) result;
Expand Down
19 changes: 19 additions & 0 deletions src/test/groovy/graphql/execution/ExecutionStrategyTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ExecutionStrategyTest extends Specification {
new ExecutionContext(NoOpInstrumentation.INSTANCE, executionId, schema, null, executionStrategy, executionStrategy, executionStrategy, null, null, variables, "context", "root")
}

@SuppressWarnings("GroovyAssignabilityCheck")
def "complete values always calls query strategy to execute more"() {
given:
def dataFetcher = Mock(DataFetcher)
Expand Down Expand Up @@ -479,6 +480,24 @@ class ExecutionStrategyTest extends Specification {
thrown(CompletionException)
executionContext.errors.size() == 1 // only 1 error
executionContext.errors[0] instanceof ExceptionWhileDataFetching
}

def "#163 completes value for an primitive type array"() {
given:
ExecutionContext executionContext = buildContext()
long[] result = [1L,2L,3L]

def parameters = newParameters()
.typeInfo(ExecutionTypeInfo.newTypeInfo().type(new GraphQLList(Scalars.GraphQLLong)))
.source(result)
.fields(["fld": [new Field()]])
.field([new Field()])
.build()

when:
def executionResult = executionStrategy.completeValue(executionContext, parameters)

then:
executionResult.get().data == [1L,2L,3L]
}
}