@@ -5,10 +5,13 @@ import com.expedia.graphql.exceptions.CouldNotCastArgumentException
5
5
import graphql.schema.DataFetchingEnvironment
6
6
import io.mockk.every
7
7
import io.mockk.mockk
8
+ import kotlinx.coroutines.delay
8
9
import org.junit.jupiter.api.Test
10
+ import java.util.concurrent.CompletableFuture
9
11
import kotlin.test.assertEquals
10
12
import kotlin.test.assertFailsWith
11
13
import kotlin.test.assertNull
14
+ import kotlin.test.assertTrue
12
15
13
16
internal class FunctionDataFetcherTest {
14
17
@@ -22,6 +25,11 @@ internal class FunctionDataFetcherTest {
22
25
fun context (@GraphQLContext string : String ) = string
23
26
24
27
fun dataFetchingEnvironment (environment : DataFetchingEnvironment ) = environment.field.name
28
+
29
+ suspend fun suspendPrint (string : String ): String = kotlinx.coroutines.coroutineScope {
30
+ delay(10 )
31
+ string
32
+ }
25
33
}
26
34
27
35
@Test
@@ -105,4 +113,16 @@ internal class FunctionDataFetcherTest {
105
113
}
106
114
assertEquals(expected = " fooBarBaz" , actual = dataFetcher.get(mockEnvironmet))
107
115
}
116
+
117
+ @Test
118
+ fun `suspend functions return value wrapped in CompletableFuture` () {
119
+ val dataFetcher = FunctionDataFetcher (target = MyClass (), fn = MyClass ::suspendPrint)
120
+ val mockEnvironmet: DataFetchingEnvironment = mockk()
121
+ every { mockEnvironmet.arguments } returns mapOf (" string" to " hello" )
122
+
123
+ val result = dataFetcher.get(mockEnvironmet)
124
+
125
+ assertTrue(result is CompletableFuture <* >)
126
+ assertEquals(expected = " hello" , actual = result.get())
127
+ }
108
128
}
0 commit comments