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
A
There are two types of
How to use the
You'll first get a
On this
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 theBuilderfor this query, and the method wich actually do the call to the GraphQL server for this query. - Sub-object
ObjectResponse: such aObjectResponseallow 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 aObjectResponse, you'll use theBuilder#withSubObject(String, ObjectResponse)or theBuilder#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 thisObjectResponse, you'll create aBuilderwith one of the newSubObjectResponseDefBuilder methods.
- Author:
- EtienneSF
-
Method Summary
Modifier and Type Method Description voidaddInputParameter(InputParameter inputParameter)Add anInputParameterto this object.voidaddInputParameters(java.util.List<InputParameter> inputParameters)Add a list ofInputParameters to this object.voidappendResponseQuery(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.StringgetFieldAlias()Retrieves the alias for the field, which response is defined by this instancejava.lang.Class<?>getFieldClass()Retrieves the class for the field, which response is defined by this instancejava.lang.StringgetFieldName()Retrieves the name for the field, which response is defined by this instancejava.util.List<InputParameter>getInputParameters()Retrieves theInputParameterfor the field, which response is defined by this instancejava.lang.Class<?>getOwningClass()Retrieves the GraphQL type that owns the field, which response is defined by this instance
-
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
Retrieves theInputParameterfor 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 GraphQLRequestExecutionExceptionRetrieves 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- TheStringBuilderwhere the response must be appended- Throws:
GraphQLRequestExecutionException- When there is an issue during execution, typically while managing the bind variables.
-
addInputParameter
Add anInputParameterto this object.- Parameters:
inputParameter-
-
addInputParameters
Add a list ofInputParameters to this object.- Parameters:
inputParameters-
-