line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.8k stars 914 forks source link

Add `armeria-graphql-kotlin` module #3785

Open ikhoon opened 3 years ago

ikhoon commented 3 years ago

Users can serve a graphql-kotlin service with armeria-graphql module. Because grpahql-kotlin is made on top of graphql-java. graphql-kotiln configurations could be converted into a GraphQLSchema of graphql-java. https://github.com/line/armeria/blob/433c2ad91f008cfa90b164d893d2c2548632dd44/examples/graphql-kotlin/src/main/kotlin/example/armeria/server/graphql/kotlin/Main.kt#L40-L43

But it has some drawbacks that do not fully leverage graphql-kotlin features. For example, we can not propagate a RequestContext through Kotlin's Coroutine scope. It should be nice to call the suspend endpoint function of graphql-kotlin with Armeria's Coroutine dispatchers as we did in ArmeriaCoroutineUtil.kt https://github.com/ExpediaGroup/graphql-kotlin/blob/b02efbd9bd6b4598b55cdc713797a5c99af8bbae/servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/execution/GraphQLServer.kt#L42 https://github.com/line/armeria/blob/61b80b39d4c0ed7599330606862ee4a1a9450c49/kotlin/src/main/kotlin/com/linecorp/armeria/internal/common/kotlin/ArmeriaCoroutineUtil.kt#L43-L51

tobias- commented 3 years ago

I think it'd also be nice to re-use the Armeria executor that can be set in GraphqlService.builder().useBlockingTaskExecutor(boolean) instead of the default GlobalScope.

ikhoon commented 3 years ago

As the GraphQL Kotlin relies on GraphQL Java built on top of CompletableFuture, it seems impossible to propagate a context to child fetcher at the moment.