Skip to content

GraphQLContextFactory.generateContext does not support coroutine. #1050

@LEECHHE

Description

@LEECHHE

Hi, I'm trying to build spring server with version 4.0.0-alpha13 and it seems the guide is unable to be applied on GraphQLContextFactory.

interface GraphQLContextFactory<out Context : GraphQLContext, Request> {
    fun generateContext(request: Request): Context?
}

Now GraphQLContextFactory does not support suspend modifier. I tried to load user entity from DB on ContextFactory as the guide has referred, but the implementation is different.

@Component
class MyGraphQLContextFactory: GraphQLContextFactory<MyGraphQLContext> {
    override suspend fun generateContext(
        request: ServerHttpRequest,
        response: ServerHttpResponse
    ): MyGraphQLContext = MyGraphQLContext(
        myCustomValue = request.headers.getFirst("MyHeader") ?: "defaultValue"
    )
}

Can I know workaround to do it?

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