Interface QueryExecutor

All Known Implementing Classes:
QueryExecutorImpl

public interface QueryExecutor
This class is the query executor : a generic class, reponsible for calling the GraphQL server, and return its response as POJOs.
Author:
EtienneSF
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static org.slf4j.Marker GRAPHQL_MARKER  
    static org.slf4j.Marker GRAPHQL_MUTATION_MARKER  
    static org.slf4j.Marker GRAPHQL_QUERY_MARKER  
    static org.slf4j.Marker GRAPHQL_SUBSCRIPTION_MARKER  
  • Method Summary

    Modifier and Type Method Description
    <T> T execute​(java.lang.String requestType, ObjectResponse objectResponse, java.util.Map<java.lang.String,​java.lang.Object> parameters, java.lang.Class<T> valueType)
    Execution of the given simple GraphQL query, and return its response mapped in the relevant POJO.
    <T> T execute​(java.lang.String graphqlQuery, java.lang.Class<T> valueType)
    Execution of the given simple GraphQL query, and return its response mapped in the relevant POJO.
  • Field Details

  • Method Details

    • execute

      <T> T execute​(java.lang.String requestType, ObjectResponse objectResponse, java.util.Map<java.lang.String,​java.lang.Object> parameters, java.lang.Class<T> valueType) throws GraphQLRequestExecutionException
      Execution of the given simple GraphQL query, and return its response mapped in the relevant POJO. This method execute a single GraphQL query, not a multi-operational request.
      The advantage of this method is that you can build all the ObjectResponse for your application in your constructor, or in whatever initialization code you have. Using this allows to be sure at startup that the syntax for all your GraphQL request is valid.
      Type Parameters:
      T -
      Parameters:
      requestType - One of "query", "mutation" or "subscription"
      objectResponse - Defines what response is expected from the server. The ObjectResponse.getFieldAlias() method returns the field of the query, that is: the query name.
      parameters - the input parameters for this query. If the query has no parameters, it may be null or an empty list.
      Returns:
      The response mapped to the code, generated from the GraphQl server. Or a wrapper for composite responses.
      Throws:
      GraphQLRequestExecutionException - When an error occurs during the request execution, typically a network error, an error from the GraphQL server or if the server response can't be parsed
      java.io.IOException
    • execute

      <T> T execute​(java.lang.String graphqlQuery, java.lang.Class<T> valueType) throws GraphQLRequestExecutionException, java.io.IOException
      Execution of the given simple GraphQL query, and return its response mapped in the relevant POJO. This method execute a single GraphQL query, not a multi-operational request.
      With this method, there is no check that the query is valid, before calling the server. And it's up to the caller of this method, to properly insert (that is: in compliance with GraphQL grammar) the parameters for the query, and for any field that would have parameters.
      Note: you can call this query directly. But the easiest way is to all the generated method from the generated QueryType relevant for you schema. This method will take care of the parameters for the query itself, in pure java.
      Type Parameters:
      T - The GraphQL type to map the response into
      Parameters:
      graphqlQuery - A string which contains the query, in the GraphQL language. For instance: "{ hero { name } }"
      queryName - The name of the query. In this sample: "hero"
      valueType - The GraphQL type to map the response into
      Returns:
      The response mapped to the code, generated from the GraphQl server. Or a wrapper for composite responses.
      Throws:
      GraphQLRequestExecutionException
      java.io.IOException