Skip to content

Using different schema for authorized/unauthorized requests #1850

@JajaComp

Description

@JajaComp

Hi! In 7 version can i use different schema for authorized/unauthorized requests? In previous version i use it over:

suspend fun handle(applicationCall: ApplicationCall) {
        val result = when {
            applicationCall.containHeader("ADMIN_HEADER") -> {
                if (applicationCall.request.hasCorrectAdminHeader()) {
                    fullGraphQLServer.execute(applicationCall.request)
                } else {
                    delay(2_000)
                    applicationCall.response.call.respond(HttpStatusCode.Unauthorized, "No access")
                    return
                }
            }

            applicationCall.containHeader("AUTH_HEADER") -> {
                fullGraphQLServer.execute(applicationCall.request)
            }

            else -> {
                guestGraphqlServer.execute(applicationCall.request)
            }
        }
        if (result != null) {
            val json = mapper.writeValueAsString(result)
            applicationCall.response.call.respondText(contentType = ContentType.Application.Json, text = json)
        } else {
            applicationCall.response.call.respond(HttpStatusCode.BadRequest, "Invalid request")
        }
    }

How can now i do this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions