Class QueryExecutorImpl

java.lang.Object
com.graphql_java_generator.client.QueryExecutorImpl
All Implemented Interfaces:
QueryExecutor

public class QueryExecutorImpl
extends java.lang.Object
implements QueryExecutor
This class is the query executor : a generic class, reponsible for calling the GraphQL server, for query, mutation and subscription.
It has one major parameter: the GraphQL endpoint. See the QueryExecutorImpl(String) for more information.
Author:
etienne-sf
  • Field Summary

    Fields inherited from interface com.graphql_java_generator.client.QueryExecutor

    GRAPHQL_MARKER, GRAPHQL_MUTATION_MARKER, GRAPHQL_QUERY_MARKER, GRAPHQL_SUBSCRIPTION_MARKER
  • Constructor Summary

    Constructors 
    Constructor Description
    QueryExecutorImpl​(java.lang.String graphqlEndpoint)
    This constructor expects the URI of the GraphQL server
    For example: http://my.server.com/graphql or https://my.server.com/graphql
    QueryExecutorImpl​(java.lang.String graphqlEndpoint, javax.net.ssl.SSLContext sslContext, javax.net.ssl.HostnameVerifier hostnameVerifier)
    This constructor expects the URI of the GraphQL server.
    QueryExecutorImpl​(java.lang.String graphqlEndpoint, javax.ws.rs.client.Client client, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    This constructor expects the URI of the GraphQL server and a configured JAX-RS client that gives the opportunity to customise the REST request
    For example: http://my.server.com/graphql
  • Method Summary

    Modifier and Type Method Description
    <T> T execute​(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 query, java.lang.Class<T> valueType)
    Execution of the given simple GraphQL query, and return its response mapped in the relevant POJO.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • QueryExecutorImpl

      public QueryExecutorImpl​(java.lang.String graphqlEndpoint)
      This constructor expects the URI of the GraphQL server
      For example: http://my.server.com/graphql or https://my.server.com/graphql
      Parameters:
      graphqlEndpoint - the http URI for the GraphQL endpoint
    • QueryExecutorImpl

      public QueryExecutorImpl​(java.lang.String graphqlEndpoint, javax.net.ssl.SSLContext sslContext, javax.net.ssl.HostnameVerifier hostnameVerifier)
      This constructor expects the URI of the GraphQL server. This constructor works only for https servers, not for http ones.
      For example: https://my.server.com/graphql
      It allows to specify the SSLContext and the HostnameVerifier. It is used in the integration test... to remove most of the control on https protocol, and allow connection to an https with a self-signed certificate.
      Parameters:
      graphqlEndpoint - the https URI for the GraphQL endpoint
      sslContext -
      hostnameVerifier -
    • QueryExecutorImpl

      public QueryExecutorImpl​(java.lang.String graphqlEndpoint, javax.ws.rs.client.Client client, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      This constructor expects the URI of the GraphQL server and a configured JAX-RS client that gives the opportunity to customise the REST request
      For example: http://my.server.com/graphql
      Parameters:
      graphqlEndpoint - the http URI for the GraphQL endpoint
      client - Client javax.ws.rs.client.Client to support customization of the rest request
      objectMapper - ObjectMapper com.fasterxml.jackson.databind.ObjectMapper to support configurable mapping
  • Method Details

    • execute

      public <T> T execute​(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.
      Specified by:
      execute in interface QueryExecutor
      Parameters:
      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
    • execute

      public <T> T execute​(java.lang.String query, 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.
      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.
      Specified by:
      execute in interface QueryExecutor
      Type Parameters:
      T - The GraphQL type to map the response into
      Parameters:
      query - A string which contains the query, in the GraphQL language. For instance: "{ hero { name } }"
      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