Skip to content

Commit 36c5647

Browse files
committed
Add support for arrays as return types (fix #239)
1 parent 5d8d873 commit 36c5647

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<java.version>1.8</java.version>
25-
<graphql-spring-boot-starter.version>5.2</graphql-spring-boot-starter.version>
26-
<graphql-java-tools.version>5.4.0</graphql-java-tools.version>
25+
<graphql-spring-boot-starter.version>5.5.0</graphql-spring-boot-starter.version>
26+
<graphql-java-tools.version>5.5.0</graphql-java-tools.version>
2727
<kotlin.version>1.3.10</kotlin.version>
2828
</properties>
2929

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.graphql-java-kickstart</groupId>
66
<artifactId>graphql-java-tools</artifactId>
7-
<version>5.5.0-SNAPSHOT</version>
7+
<version>5.5.1-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>GraphQL Java Tools</name>

src/main/kotlin/com/coxautodev/graphql/tools/TypeClassMatcher.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
7878
is ListType -> {
7979
if (realType is ParameterizedType && isListType(realType, potentialMatch)) {
8080
match(potentialMatch, graphQLType.type, realType.actualTypeArguments.first())
81+
} else if ((realType as Class<*>).isArray) {
82+
match(potentialMatch, graphQLType.type, realType.componentType)
8183
} else {
8284
throw error(potentialMatch, "Java class is not a List or generic type information was lost: $realType")
8385
}

src/test/groovy/com/coxautodev/graphql/tools/EndToEndSpec.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,4 +634,20 @@ class EndToEndSpec extends Specification {
634634
subscriber.requestNextElement().data.get("onItemCreatedCoroutineChannelAndSuspendFunction").id == 1
635635
subscriber.expectCompletion()
636636
}
637+
638+
def "generated schema supports arrays"() {
639+
when:
640+
def data = Utils.assertNoGraphQlErrors(gql) {
641+
'''
642+
{
643+
arrayItems {
644+
name
645+
}
646+
}
647+
'''
648+
}
649+
650+
then:
651+
data.arrayItems.collect { it.name } == ['item1', 'item2']
652+
}
637653
}

src/test/java/com/coxautodev/graphql/tools/ReactiveTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
import graphql.execution.AsyncExecutionStrategy;
55
import graphql.schema.GraphQLSchema;
66
import groovy.lang.Closure;
7-
import io.reactivex.Single;
8-
import io.reactivex.internal.operators.single.SingleJust;
7+
//import io.reactivex.Single;
8+
//import io.reactivex.internal.operators.single.SingleJust;
99
import org.junit.Test;
1010

1111
import java.util.HashMap;
1212
import java.util.Optional;
1313
import java.util.concurrent.CompletableFuture;
1414
import java.util.concurrent.Future;
1515

16-
import static io.reactivex.Maybe.just;
16+
//import static io.reactivex.Maybe.just;
1717

1818
public class ReactiveTest {
1919

2020
@Test
2121
public void futureSucceeds() {
2222
SchemaParserOptions options = SchemaParserOptions.newOptions()
23-
.genericWrappers(
24-
new SchemaParserOptions.GenericWrapper(Single.class, 0),
25-
new SchemaParserOptions.GenericWrapper(SingleJust.class, 0)
26-
)
23+
// .genericWrappers(
24+
// new SchemaParserOptions.GenericWrapper(Single.class, 0),
25+
// new SchemaParserOptions.GenericWrapper(SingleJust.class, 0)
26+
// )
2727
.build();
2828
GraphQLSchema schema = SchemaParser.newParser().file("Reactive.graphqls")
2929
.resolvers(new Query())

src/test/kotlin/com/coxautodev/graphql/tools/EndToEndSpec.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type Query {
7979
dataFetcherResult: Item!
8080
8181
coroutineItems: [Item!]!
82+
83+
arrayItems: [Item!]!
8284
}
8385
8486
type ExtendedType {
@@ -288,6 +290,8 @@ class Query: GraphQLQueryResolver, ListListResolver<String>() {
288290
}
289291

290292
suspend fun coroutineItems(): List<Item> = CompletableDeferred(items).await()
293+
294+
fun arrayItems() = items.toTypedArray()
291295
}
292296

293297
class UnusedRootResolver: GraphQLQueryResolver

0 commit comments

Comments
 (0)