dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

DgsQuery that returns a Kotlin Flow failed to execute

Open hantsy opened this issue 3 years ago • 7 comments

In these days, I tried to update Dgs/Kotlin Coroutines example, when I updated the QueryTests.

And run it, and got the following exception.

Can't resolve value (/allPosts) : type mismatch error, expected type LIST got class kotlinx.coroutines.flow.FlowKt__BuildersKt$flowOf$$inlined$unsafeFlow$1

The query component is:

@DgsComponent
class PostsDataFetcher(val postService: PostService) {
    @DgsQuery
    fun allPosts(): Flow<Post> = postService.allPosts()
...
}

The testing codes is here, https://github.com/hantsy/spring-graphql-sample/blob/master/dgs-kotlin-co/src/test/kotlin/com/example/demo/QueryTests.kt

I got the similar errors when executing the allPosts query in the /graphiql web interfaces.

{
  "errors": [
    {
      "message": "Can't resolve value (/allPosts) : type mismatch error, expected type LIST",
      "path": [
        "allPosts"
      ],
      "extensions": {
        "classification": "DataFetchingException"
      }
    }
  ],
  "data": null
}

Originally posted by @hantsy in https://github.com/Netflix/dgs-framework/discussions/1075

hantsy avatar May 27 '22 17:05 hantsy

I'm guessing it is latest 4.x or 5.x?

berngp avatar May 27 '22 21:05 berngp

I am using 4.10.4, https://github.com/hantsy/spring-graphql-sample/blob/master/dgs-kotlin-co/build.gradle.kts#L23

I remember the basic Kotlin Coroutines support was already added https://github.com/Netflix/dgs-framework/issues/413

hantsy avatar May 28 '22 02:05 hantsy

Updated to 5.0.1, still failed.

hantsy avatar Jun 05 '22 12:06 hantsy

5.0.2 failed

hantsy avatar Jun 06 '22 11:06 hantsy

This hasn't been addressed yet. We will look at this for the next release.

berngp avatar Jun 06 '22 14:06 berngp

Any update for this? The Spring official GraphQL module has the same problem.

hantsy avatar Jun 26 '22 14:06 hantsy

Not yet @hantsy , hopefully soon we can have a better answer.

berngp avatar Jun 27 '22 03:06 berngp