Interface DgsReactiveQueryExecutor


public interface DgsReactiveQueryExecutor
Represents the core query executing capability of the framework. This is the reactive version of the interface, using Mono for its results. See DgsQueryExecutor for the blocking version of this interface. Use this interface to easily execute GraphQL queries, without using the HTTP endpoint. This is meant to be used in tests, and is also used internally in the framework.

The executeAnd* methods use the JsonPath library library to easily get specific fields out of a nested Json structure. The executeAndGetDocumentContext(String) method sets up a DocumentContext, which can then be reused to get multiple fields.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default reactor.core.publisher.Mono<graphql.ExecutionResult>
    execute(String query)
     
    default reactor.core.publisher.Mono<graphql.ExecutionResult>
    execute(String query, Map<String,Object> variables)
     
    default reactor.core.publisher.Mono<graphql.ExecutionResult>
    execute(String query, Map<String,Object> variables, String operationName)
     
    default reactor.core.publisher.Mono<graphql.ExecutionResult>
    execute(String query, Map<String,Object> variables, Map<String,Object> extensions, org.springframework.http.HttpHeaders headers)
     
    reactor.core.publisher.Mono<graphql.ExecutionResult>
    execute(String query, Map<String,Object> variables, Map<String,Object> extensions, org.springframework.http.HttpHeaders headers, String operationName, org.springframework.web.reactive.function.server.ServerRequest serverRequest)
    Executes a GraphQL query.
    default <T> reactor.core.publisher.Mono<T>
    Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
    default <T> reactor.core.publisher.Mono<T>
    executeAndExtractJsonPath(String query, String jsonPath, Map<String,Object> variables)
    Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
    <T> reactor.core.publisher.Mono<T>
    executeAndExtractJsonPath(String query, String jsonPath, Map<String,Object> variables, org.springframework.web.reactive.function.server.ServerRequest serverRequest)
    Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
    default <T> reactor.core.publisher.Mono<T>
    executeAndExtractJsonPath(String query, String jsonPath, org.springframework.web.reactive.function.server.ServerRequest serverRequest)
    Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data.
    default <T> reactor.core.publisher.Mono<T>
    executeAndExtractJsonPathAsObject(String query, String jsonPath, com.jayway.jsonpath.TypeRef<T> typeRef)
    Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
    default <T> reactor.core.publisher.Mono<T>
    Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
    <T> reactor.core.publisher.Mono<T>
    executeAndExtractJsonPathAsObject(String query, String jsonPath, Map<String,Object> variables, com.jayway.jsonpath.TypeRef<T> typeRef)
    Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
    <T> reactor.core.publisher.Mono<T>
    executeAndExtractJsonPathAsObject(String query, String jsonPath, Map<String,Object> variables, Class<T> clazz)
    Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type.
    default reactor.core.publisher.Mono<com.jayway.jsonpath.DocumentContext>
    Executes a GraphQL query, parses the returned data, and return a DocumentContext.
    reactor.core.publisher.Mono<com.jayway.jsonpath.DocumentContext>
    Executes a GraphQL query, parses the returned data, and return a DocumentContext.
  • Method Details

    • execute

      default reactor.core.publisher.Mono<graphql.ExecutionResult> execute(String query)
      Parameters:
      query - The query string
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
    • execute

      default reactor.core.publisher.Mono<graphql.ExecutionResult> execute(String query, Map<String,Object> variables)
      Parameters:
      query - The query string
      variables - A map of variables
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
      See Also:
    • execute

      default reactor.core.publisher.Mono<graphql.ExecutionResult> execute(String query, Map<String,Object> variables, String operationName)
      Parameters:
      query - The query string
      variables - A map of variables
      operationName - The operation name
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
      See Also:
    • execute

      default reactor.core.publisher.Mono<graphql.ExecutionResult> execute(String query, Map<String,Object> variables, Map<String,Object> extensions, org.springframework.http.HttpHeaders headers)
      Parameters:
      query - The query string
      variables - A map of variables
      extensions - A map representing GraphQL extensions. This is made available in the DgsRequestData object on DgsContext.
      headers - Request headers represented as a Spring Framework HttpHeaders
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
      See Also:
    • execute

      reactor.core.publisher.Mono<graphql.ExecutionResult> execute(String query, Map<String,Object> variables, Map<String,Object> extensions, org.springframework.http.HttpHeaders headers, String operationName, org.springframework.web.reactive.function.server.ServerRequest serverRequest)
      Executes a GraphQL query. This method is used internally by all other methods in this interface.
      Parameters:
      query - The query string
      variables - A map of variables
      extensions - A map representing GraphQL extensions. This is made available in the DgsRequestData object on DgsContext.
      headers - Request headers represented as a Spring Framework HttpHeaders
      operationName - Operation name
      serverRequest - A Spring ServerRequest giving access to request details.
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
      See Also:
    • executeAndExtractJsonPath

      default <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPath(String query, String jsonPath)
      Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data. The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use executeAndExtractJsonPathAsObject(String, String, TypeRef) instead.

      This only works for primitive types and map representations. Use executeAndExtractJsonPathAsObject(String, String, Class) for complex types and lists.

      Type Parameters:
      T - The type of primitive or map representation that should be returned.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      Returns:
      A Mono that might contain the resolved type.
      See Also:
    • executeAndExtractJsonPath

      <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPath(String query, String jsonPath, Map<String,Object> variables, org.springframework.web.reactive.function.server.ServerRequest serverRequest)
      Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data. The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use executeAndExtractJsonPathAsObject(String, String, TypeRef)instead.

      This only works for primitive types and map representations. Use executeAndExtractJsonPathAsObject(String, String, Class) for complex types and lists.*

      Type Parameters:
      T - The type of primitive or map representation that should be returned.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      variables - A Map of variables
      serverRequest - A Spring ServerRequest giving access to request details. *
      Returns:
      A Mono that might contain the resolved type.
      See Also:
    • executeAndExtractJsonPath

      default <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPath(String query, String jsonPath, Map<String,Object> variables)
      Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data. The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use executeAndExtractJsonPathAsObject(String, String, TypeRef)instead.

      This only works for primitive types and map representations. Use executeAndExtractJsonPathAsObject(String, String, Class) for complex types and lists.*

      Type Parameters:
      T - The type of primitive or map representation that should be returned.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      variables - A Map of variables
      Returns:
      A Mono that might contain the resolved type.
      See Also:
    • executeAndExtractJsonPath

      default <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPath(String query, String jsonPath, org.springframework.web.reactive.function.server.ServerRequest serverRequest)
      Executes a GraphQL query, parses the returned data, and uses a Json Path to extract specific elements out of the data. The method is generic, and tries to cast the result into the type you specify. This does NOT work on Lists. Use executeAndExtractJsonPathAsObject(String, String, TypeRef)instead.

      This only works for primitive types and map representations. Use executeAndExtractJsonPathAsObject(String, String, Class) for complex types and lists.*

      Type Parameters:
      T - The type of primitive or map representation that should be returned.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      serverRequest - A Spring ServerRequest giving access to request details.
      Returns:
      A Mono that might contain the resolved type.
      See Also:
    • executeAndGetDocumentContext

      default reactor.core.publisher.Mono<com.jayway.jsonpath.DocumentContext> executeAndGetDocumentContext(String query)
      Executes a GraphQL query, parses the returned data, and return a DocumentContext. A DocumentContext can be used to extract multiple values using JsonPath, without re-executing the query.
      Parameters:
      query - GraphQL query string
      Returns:
      DocumentContext is a JsonPath type used to extract values from.
    • executeAndGetDocumentContext

      reactor.core.publisher.Mono<com.jayway.jsonpath.DocumentContext> executeAndGetDocumentContext(String query, Map<String,Object> variables)
      Executes a GraphQL query, parses the returned data, and return a DocumentContext. A DocumentContext can be used to extract multiple values using JsonPath, without re-executing the query.
      Parameters:
      query - GraphQL query string
      variables - A Map of variables
      Returns:
      DocumentContext is a JsonPath type used to extract values from.
      See Also:
    • executeAndExtractJsonPathAsObject

      default <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPathAsObject(String query, String jsonPath, Class<T> clazz)
      Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type. Be aware that this method can't guarantee type safety.
      Type Parameters:
      T - The type that the extracted value should be converted to.
      Parameters:
      query - GraphQL query string
      jsonPath - JsonPath expression.
      clazz - The type to convert the extracted value to.
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPathAsObject

      <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPathAsObject(String query, String jsonPath, Map<String,Object> variables, Class<T> clazz)
      Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type. Be aware that this method can't guarantee type safety.
      Type Parameters:
      T - The type that the extracted value should be converted to.
      Parameters:
      query - GraphQL query string
      jsonPath - JsonPath expression.
      variables - A Map of variables
      clazz - The type to convert the extracted value to.
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPathAsObject

      default <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPathAsObject(String query, String jsonPath, com.jayway.jsonpath.TypeRef<T> typeRef)
      Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type. Uses a TypeRef to specify the expected type, which is useful for Lists and Maps. Be aware that this method can't guarantee type safety.
      Type Parameters:
      T - The type that the extracted value should be converted to.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      typeRef - A JsonPath [TypeRef] representing the expected result type.
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPathAsObject

      <T> reactor.core.publisher.Mono<T> executeAndExtractJsonPathAsObject(String query, String jsonPath, Map<String,Object> variables, com.jayway.jsonpath.TypeRef<T> typeRef)
      Executes a GraphQL query, parses the returned data, extracts a value using JsonPath, and converts that value into the given type. Uses a TypeRef to specify the expected type, which is useful for Lists and Maps. Be aware that this method can't guarantee type safety.
      Type Parameters:
      T - The type that the extracted value should be converted to.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      variables - A Map of variables
      typeRef - A JsonPath TypeRef representing the expected result type.
      Returns:
      The extracted value from the result, converted to type T
      See Also: