All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.auritylab.graphql.kotlin.toolkit.spring.controller.GetController.kt Maven / Gradle / Ivy

package com.auritylab.graphql.kotlin.toolkit.spring.controller

import com.auritylab.graphql.kotlin.toolkit.spring.api.GraphQLInvocation
import com.fasterxml.jackson.databind.ObjectMapper
import java.util.concurrent.CompletableFuture
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.context.request.WebRequest

@RestController
class GetController(
    objectMapper: ObjectMapper,
    invocation: GraphQLInvocation
) : AbstractController(objectMapper, invocation) {
    /**
     * Will accept GET requests. The [query] has to be preset, [operationName] and [variables] are optional.
     *
     * See:
     * - https://graphql.org/learn/serving-over-http/#get-request
     * - https://github.com/APIs-guru/graphql-over-http#get
     */
    @RequestMapping(
        value = ["\${graphql-kotlin-toolkit.spring.endpoint:graphql}"],
        method = [RequestMethod.GET],
        produces = [MediaType.APPLICATION_JSON_VALUE]
    )
    fun get(
        @RequestParam(value = "query") query: String,
        @RequestParam(value = "operationName", required = false) operationName: String?,
        @RequestParam(value = "variables", required = false) variables: String?,
        request: WebRequest
    ): CompletableFuture =
        execute(
            Operation(
                query,
                operationName,
                variables?.let { parse>(it) }), request
        )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy