override fun executeQuery()

in graphql-dgs-client/src/main/kotlin/com/netflix/graphql/dgs/client/RestClientGraphQLClient.kt [84:124]


    override fun executeQuery(
        @Language("graphql") query: String,
        variables: Map<String, Any>,
    ): GraphQLResponse = executeQuery(query, variables, null)

    /**
     * @param query The query string. Note that you can use [code generation](https://netflix.github.io/dgs/generating-code-from-schema/#generating-query-apis-for-external-services) for a type safe query!
     * @param variables A map of input variables
     * @param operationName Operation name
     * @return A [GraphQLResponse]. [GraphQLResponse] parses the response and gives easy access to data and errors.
     */
    override fun executeQuery(
        @Language("graphql") query: String,
        variables: Map<String, Any>,
        operationName: String?,
    ): GraphQLResponse {
        val serializedRequest =
            mapper.writeValueAsString(
                GraphQLClients.toRequestMap(query = query, operationName = operationName, variables = variables),
            )

        val responseEntity =
            restClient
                .post()
                .headers { headers -> headers.addAll(GraphQLClients.defaultHeaders) }
                .headers(this.headersConsumer)
                .body(serializedRequest)
                .retrieve()
                .toEntity(String::class.java)

        if (!responseEntity.statusCode.is2xxSuccessful) {
            throw GraphQLClientException(
                statusCode = responseEntity.statusCode.value(),
                url = "",
                response = responseEntity.body ?: "",
                request = serializedRequest,
            )
        }

        return GraphQLResponse(json = responseEntity.body ?: "", headers = responseEntity.headers, options)
    }