smallrye / smallrye-graphql

Implementation for MicroProfile GraphQL
Apache License 2.0
160 stars 92 forks source link

Support kotlin coroutines #1024

Open nenros opened 3 years ago

nenros commented 3 years ago

Hi! Using quarkus I've tried to create resource using code like this:

@GraphQLApi
@RequestScoped
class SomethingResource(
    private val somethingService: SomethingService,
) {

    @Query("getSomething")
    suspend fun getSomething(): SomethingResponse {
        val something = somethingService.getUserCalendar().awaitSuspending()

        return something?.toSomthingResponse()
    }
}

but I get error about:

[error]: Build step io.quarkus.smallrye.graphql.deployment.SmallRyeGraphQLProcessor#buildExecutionService threw an exception: java.lang.IllegalArgumentException: Invalid parameter type [kotlin.coroutines.Continuation]
    at io.smallrye.graphql.schema.creator.ReferenceCreator.getNonIndexedReference(ReferenceCreator.java:462)
    at io.smallrye.graphql.schema.creator.ReferenceCreator.getReference(ReferenceCreator.java:331)
    at io.smallrye.graphql.schema.creator.ReferenceCreator.getReference(ReferenceCreator.java:259)
    at io.smallrye.graphql.schema.creator.ReferenceCreator.createReferenceForOperationArgument(ReferenceCreator.java:107)
    at io.smallrye.graphql.schema.creator.ArgumentCreator.createArgument(ArgumentCreator.java:68)
    at io.smallrye.graphql.schema.creator.OperationCreator.createOperation(OperationCreator.java:80)
    at io.smallrye.graphql.schema.SchemaBuilder.addOperations(SchemaBuilder.java:252)
    at io.smallrye.graphql.schema.SchemaBuilder.generateSchema(SchemaBuilder.java:117)
    at io.smallrye.graphql.schema.SchemaBuilder.build(SchemaBuilder.java:86)
    at io.quarkus.smallrye.graphql.deployment.SmallRyeGraphQLProcessor.buildExecutionService(SmallRyeGraphQLProcessor.java:175)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
    at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
    at java.base/java.lang.Thread.run(Thread.java:831)
    at org.jboss.threads.JBossThread.run(JBossThread.java:501)

As I checked main problem is probably here: https://github.com/smallrye/smallrye-graphql/blob/4845dc96733c373bd6c921acdb867abec8d837d8/common/schema-builder/src/main/java/io/smallrye/graphql/schema/Classes.java#L147 as it is not added as async type. Of course it is probably little bit more complicated, because you need to run in coroutine context but I'm not expert. I just want to say that it would be nice to have this way.

mschorsch commented 2 years ago

+1

msameer commented 4 months ago

+1

cpoyatos1 commented 1 week ago

+1