2021-08-07 09:21:08 +07:00
|
|
|
package com.cubetiqs.graphql.demo
|
|
|
|
|
2021-08-07 19:56:39 +07:00
|
|
|
import com.cubetiqs.graphql.demo.resolver.subscription.HelloSubscriptionResolver
|
|
|
|
import com.netflix.graphql.dgs.DgsQueryExecutor
|
|
|
|
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration
|
|
|
|
import graphql.ExecutionResult
|
2021-08-07 09:21:08 +07:00
|
|
|
import org.junit.jupiter.api.Test
|
2021-08-07 19:56:39 +07:00
|
|
|
import org.reactivestreams.Publisher
|
|
|
|
import org.reactivestreams.Subscriber
|
|
|
|
import org.reactivestreams.Subscription
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
2021-08-07 09:21:08 +07:00
|
|
|
import org.springframework.boot.test.context.SpringBootTest
|
|
|
|
|
2021-08-07 19:56:39 +07:00
|
|
|
@SpringBootTest(
|
|
|
|
classes = [
|
|
|
|
DgsAutoConfiguration::class,
|
|
|
|
HelloSubscriptionResolver::class,
|
|
|
|
]
|
|
|
|
)
|
2021-08-07 09:21:08 +07:00
|
|
|
class GraphqlDemoApplicationTests {
|
2021-08-07 19:56:39 +07:00
|
|
|
@Autowired
|
|
|
|
lateinit var dgsQueryExecutor: DgsQueryExecutor
|
2021-08-07 09:21:08 +07:00
|
|
|
|
2021-08-07 19:56:39 +07:00
|
|
|
@Test
|
|
|
|
fun helloSubscription() {
|
|
|
|
dgsQueryExecutor.execute(
|
|
|
|
"""
|
|
|
|
subscription {
|
|
|
|
hello
|
|
|
|
}
|
|
|
|
""".trimIndent()
|
|
|
|
)
|
|
|
|
.getData<Publisher<ExecutionResult>>()
|
|
|
|
.subscribe(object : Subscriber<ExecutionResult> {
|
|
|
|
override fun onSubscribe(s: Subscription) {
|
|
|
|
s.request(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onNext(t: ExecutionResult) {
|
|
|
|
println(t.getData<Any?>())
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onError(t: Throwable?) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onComplete() {
|
|
|
|
println("Hello World")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
2021-08-07 09:21:08 +07:00
|
|
|
|
|
|
|
}
|