Skip to content

Commit 4838538

Browse files
authored
Merge pull request #488 from ooga/list-of-datafetcherresult
Remove error when DataFetcherResult is not the root type
2 parents 580475b + 0bb2853 commit 4838538

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/main/kotlin/graphql/kickstart/tools/TypeClassMatcher.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
3232
throw error(potentialMatch, "${DataFetcherResult::class.java.name} can only be used as a return type")
3333
}
3434

35-
if (!root) {
36-
throw error(potentialMatch, "${DataFetcherResult::class.java.name} can only be used at the top level of a return type")
37-
}
38-
3935
realType = potentialMatch.generic.unwrapGenericType(realType.actualTypeArguments.first())
4036

4137
if (realType is ParameterizedType && potentialMatch.generic.isTypeAssignableFromRawClass(realType, DataFetcherResult::class.java)) {

src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type Query {
7676
7777
propertyField: String!
7878
dataFetcherResult: Item!
79+
dataFetcherResultItems: [Item!]!
7980
8081
coroutineItems: [Item!]!
8182
@@ -302,6 +303,10 @@ class Query : GraphQLQueryResolver, ListListResolver<String>() {
302303
return DataFetcherResult.newResult<Item>().data(items.first()).build()
303304
}
304305

306+
fun dataFetcherResultItems(): List<DataFetcherResult<Item>> {
307+
return listOf(DataFetcherResult.newResult<Item>().data(items.first()).build())
308+
}
309+
305310
suspend fun coroutineItems(): List<Item> = CompletableDeferred(items).await()
306311

307312
fun arrayItems() = items.toTypedArray()
@@ -329,7 +334,7 @@ class Mutation : GraphQLMutationResolver {
329334
}
330335

331336
fun saveUser(userInput: UserInput): String {
332-
return userInput.name + "/" + userInput.password;
337+
return userInput.name + "/" + userInput.password
333338
}
334339

335340
class UserInput {

src/test/kotlin/graphql/kickstart/tools/EndToEndTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,21 @@ class EndToEndTest {
532532
assertEquals(data["dataFetcherResult"], mapOf("name" to "item1"))
533533
}
534534

535+
@Test
536+
fun `generated schema supports list of DataFetcherResult`() {
537+
val data = assertNoGraphQlErrors(gql) {
538+
"""
539+
{
540+
dataFetcherResultItems {
541+
name
542+
}
543+
}
544+
"""
545+
}
546+
547+
assertEquals(data["dataFetcherResultItems"], listOf(mapOf("name" to "item1")))
548+
}
549+
535550
@Test
536551
fun `generated schema supports Kotlin suspend functions`() {
537552
val data = assertNoGraphQlErrors(gql) {

0 commit comments

Comments
 (0)