Class ObjectResponse

java.lang.Object
com.graphql_java_generator.client.request.ObjectResponse

public class ObjectResponse
extends java.lang.Object
This class describes what response is expected from the GraphQL server. That is: the fields and sub-objects that the response from the GraphQL server should contain, for one GraphQL type.
The structure is recursive: a ObjectResponse itsled contains one or more ObjectResponse, to describe the Sub-object(s) that should be returned.
A ObjectResponse can not be created directly. You must use an Builder to create a ObjectResponse. This Builder allows to easily add fields, which can be scalars or sub-objects. And it validates for each the GraphQL schema is respected.
There are two types of ObjectResponse:
  • Query ObjectResponse: a query ResponsDef is returned by the generated code. For instance, if your schema contains a QueryType type, a QueryType object will be generated. For each query in the GraphQL schema, this QueryType object contains two methods: a getter which returns the Builder for this query, and the method wich actually do the call to the GraphQL server for this query.
  • Sub-object ObjectResponse: such a ObjectResponse allow you to define what's expected for a field that is actually an object. This field is a sub-object of the object owning this field. To link such a ObjectResponse, you'll use the Builder#withSubObject(String, ObjectResponse) or the Builder#withSubObject(String, String, ObjectResponse) method.


How to use the Builder


You'll first get a ObjectResponse from the generated QueryType (or whatever name you have in your GraphQL schema for the query object), and its method getXxxxResponseDef, where Xxxx is the name of the query into the QueryType.
On this Builder, you can call:
  • One of the withField methods to add a scalar field to the expected response
  • One of the withEntity methods to add a field whose type is not scalar. That is, to add a field whose type is an object defined in the GraphQL schema. The withEntity methods needs a ObjectResponse. To get this ObjectResponse, you'll create a Builder with one of the newSubObjectResponseDefBuilder methods.
Author:
EtienneSF
  • Method Summary

    Modifier and Type Method Description
    void addInputParameter​(InputParameter inputParameter)
    Add an InputParameter to this object.
    void addInputParameters​(java.util.List<InputParameter> inputParameters)
    Add a list of InputParameters to this object.
    void appendResponseQuery​(java.lang.StringBuilder sb, java.util.Map<java.lang.String,​java.lang.Object> parameters, boolean appendSpaceParam)
    Retrieves the part of the query, which describes the fields that the GraphQL server should return.
    For instance, for the query: {hero(episode: NEWHOPE) {id name}}, the response definition is {id name}
    java.lang.String getFieldAlias()
    Retrieves the alias for the field, which response is defined by this instance
    java.lang.Class<?> getFieldClass()
    Retrieves the class for the field, which response is defined by this instance
    java.lang.String getFieldName()
    Retrieves the name for the field, which response is defined by this instance
    java.util.List<InputParameter> getInputParameters()
    Retrieves the InputParameter for the field, which response is defined by this instance
    java.lang.Class<?> getOwningClass()
    Retrieves the GraphQL type that owns the field, which response is defined by this instance

    Methods inherited from class java.lang.Object

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

    • getFieldAlias

      public java.lang.String getFieldAlias()
      Retrieves the alias for the field, which response is defined by this instance
      Returns:
    • getOwningClass

      public java.lang.Class<?> getOwningClass()
      Retrieves the GraphQL type that owns the field, which response is defined by this instance
      Returns:
    • getFieldClass

      public java.lang.Class<?> getFieldClass()
      Retrieves the class for the field, which response is defined by this instance
      Returns:
    • getFieldName

      public java.lang.String getFieldName()
      Retrieves the name for the field, which response is defined by this instance
      Returns:
    • getInputParameters

      public java.util.List<InputParameter> getInputParameters()
      Retrieves the InputParameter for the field, which response is defined by this instance
      Returns:
    • appendResponseQuery

      public void appendResponseQuery​(java.lang.StringBuilder sb, java.util.Map<java.lang.String,​java.lang.Object> parameters, boolean appendSpaceParam) throws GraphQLRequestExecutionException
      Retrieves the part of the query, which describes the fields that the GraphQL server should return.
      For instance, for the query: {hero(episode: NEWHOPE) {id name}}, the response definition is {id name}
      Parameters:
      sb - The StringBuilder where the response must be appended
      Throws:
      GraphQLRequestExecutionException - When there is an issue during execution, typically while managing the bind variables.
    • addInputParameter

      public void addInputParameter​(InputParameter inputParameter)
      Add an InputParameter to this object.
      Parameters:
      inputParameter -
    • addInputParameters

      public void addInputParameters​(java.util.List<InputParameter> inputParameters)
      Add a list of InputParameters to this object.
      Parameters:
      inputParameters -