Interface DgsQueryExecutor


public interface DgsQueryExecutor
Represents the core query executing capability of the framework. 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 Details

    • execute

      default graphql.ExecutionResult execute(String query)
      Parameters:
      query - The query string
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
    • execute

      default 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 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 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 com.netflix.graphql.dgs.context.DgsContext}.
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
      See Also:
    • execute

      graphql.ExecutionResult execute(String query, Map<String,Object> variables, Map<String,Object> extensions, org.springframework.http.HttpHeaders headers, String operationName, org.springframework.web.context.request.WebRequest webRequest)
      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
      webRequest - A Spring WebRequest giving access to request details. Can cast to an environment specific class such as ServletWebRequest.
      Returns:
      Returns a GraphQL ExecutionResult. This includes data and errors.
      See Also:
    • executeAndExtractJsonPath

      default <T> 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.
      Type Parameters:
      T - The type of primitive or map representation that should be returned.
      Parameters:
      query - Query string
      jsonPath - JsonPath expression.
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPath

      <T> 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:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPath

      <T> T executeAndExtractJsonPath(String query, String jsonPath, org.springframework.http.HttpHeaders headers)
      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.
      headers - Spring HttpHeaders
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPath

      <T> T executeAndExtractJsonPath(String query, String jsonPath, org.springframework.web.context.request.ServletWebRequest servletWebRequest)
      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.
      servletWebRequest - Spring ServletWebRequest
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndGetDocumentContext

      default 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 - Query string
      Returns:
      DocumentContext is a JsonPath type used to extract values from.
    • executeAndGetDocumentContext

      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 - Query string
      variables - A Map of variables
      Returns:
      DocumentContext is a JsonPath type used to extract values from.
      See Also:
    • executeAndGetDocumentContext

      com.jayway.jsonpath.DocumentContext executeAndGetDocumentContext(String query, Map<String,Object> variables, org.springframework.http.HttpHeaders headers)
      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 - Query string
      variables - A Map of variables
      headers - Spring HttpHeaders
      Returns:
      DocumentContext is a JsonPath type used to extract values from.
      See Also:
    • executeAndExtractJsonPathAsObject

      default <T> 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 - 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

      default <T> 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 - 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

      <T> T executeAndExtractJsonPathAsObject(String query, String jsonPath, Map<String,Object> variables, Class<T> clazz, org.springframework.http.HttpHeaders headers)
      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 - Query string
      jsonPath - JsonPath expression.
      variables - A Map of variables
      clazz - The type to convert the extracted value to.
      headers - Request headers represented as a Spring Framework HttpHeaders
      Returns:
      The extracted value from the result, converted to type T
      See Also:
    • executeAndExtractJsonPathAsObject

      default <T> 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

      default <T> 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:
    • executeAndExtractJsonPathAsObject

      <T> T executeAndExtractJsonPathAsObject(String query, String jsonPath, Map<String,Object> variables, com.jayway.jsonpath.TypeRef<T> typeRef, org.springframework.http.HttpHeaders headers)
      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.
      headers - Request headers represented as a Spring Framework HttpHeaders
      Returns:
      The extracted value from the result, converted to type T
      See Also: