Skip to content

Flow return type in Subscription causes an exception when booting up Spring Server  #1477

@serandel

Description

@serandel

I'm trying to use the support for Flow in subscriptions, to avoid having to convert them to publisher as a last step in my functions. (Which seems to work perfectly fine, btw.)

If I write my subscription like

class ProductSubscription(private val productRepository: ProductRepository) : Subscription {
    fun getAllLive(code: String? = null): Flow<List<Product>> = // whatever...
}

then I get this when executing bootRun:

[com/expediagroup/graphql/server/spring/NonFederatedSchemaAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'schema' threw exception; nested exception is com.expediagroup.graphql.generator.exceptions.InvalidSubscriptionTypeException: Schema requires all subscriptions to be public and return a valid type from the hooks. ProductSubscription has PUBLIC visibility modifier. **The function return type is Flow**

After reading the documentation, I reckon that the schema generation is using NoopSchemaGeneratorHooks. So I'm trying to enable FlowSubscriptionSchemaGeneratorHooks by creating this class:

package com.example

class ProductSchemaHooksProvider : SchemaGeneratorHooksProvider {
    override fun hooks(): SchemaGeneratorHooks = FlowSubscriptionSchemaGeneratorHooks()
}

and creating a src/main/resources/META-INF/services/com.expediagroup.graphql.plugin.schema.hooks.SchemaGeneratorHooksProvider file with this content:

com.example.ProductSchemaHooksProvider

Nevertheless, nothing seems to change, and I still get the same error. Am I even going the right way about enabling this? The documentation just says that:

graphql-kotlin-spring-server provides automatic support for Kotlin Flow through FlowSubscriptionExecutionStrategy that supports existing Publishers and relies on Kotlin reactive-streams interop to convert Flow to a Publisher.

Any help would be very appreciated! :)

GraphQL-Kotlin: 6.0.0-alpha5
Spring Boot: 2.7.1
Java: 17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions