Class Builder
java.lang.Object
com.graphql_java_generator.client.request.Builder
public class Builder
extends java.lang.Object
This class is a Builder that'll help to build a
ObjectResponse
, which defines what should appear in the
response from the GraphQL server.- Author:
- EtienneSF
-
Constructor Summary
Constructors Constructor Description Builder(java.lang.Class<?> owningClass, java.lang.String fieldName)
Creates a Builder, for a field without aliasBuilder(java.lang.Class<?> owningClass, java.lang.String fieldName, boolean queryLevel)
Creates a Builder, for a field without aliasBuilder(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias)
Creates a BuilderBuilder(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias, boolean queryLevel)
Creates a Builder -
Method Summary
Modifier and Type Method Description ObjectResponse
build()
Returns the builtObjectResponse
.static java.lang.String
getCamelCase(java.lang.String name)
Convert the given name, to a camel case name.Builder
withDirectives(java.util.List<Directive> directives)
Add a list ofDirective
s to the current Object Response definition.Builder
withField(java.lang.String fieldName)
Adds a scalar field with no alias, to theObjectResponse
we are buildingBuilder
withField(java.lang.String fieldName, java.lang.String alias)
Adds a scalar field with an alias, to theObjectResponse
we are building.Builder
withField(java.lang.String fieldName, java.lang.String alias, java.util.List<InputParameter> inputParameters, java.util.List<Directive> directives)
Adds a scalar field with an alias, to theObjectResponse
we are building.Builder
withInputParameter(InputParameter inputParameter)
Deprecated.Builder
withInputParameter(java.lang.String name, java.lang.String bindParameterName, boolean mandatory)
Add anInputParameter
to the current Object Response definition.Builder
withInputParameterHardCoded(java.lang.String name, java.lang.Object value)
Add anInputParameter
to the current Object Response definition.Builder
withInputParameters(java.util.List<InputParameter> inputParameters)
Add a list ofInputParameter
s to the current Object Response definition.Builder
withQueryResponseDef(java.lang.String queryResponseDef)
Builds aObjectResponse
from a part of a GraphQL query.Builder
withSubObject(ObjectResponse subobjetResponseDef)
Adds a non scalar field (a sub-object), to theObjectResponse
we are building.
-
Constructor Details
-
Builder
public Builder(java.lang.Class<?> owningClass, java.lang.String fieldName) throws GraphQLRequestPreparationExceptionCreates a Builder, for a field without alias- Parameters:
owningClass
- The class that contains this fieldfieldName
- The field for which we must build an ObjectResponse- Throws:
GraphQLRequestPreparationException
-
Builder
public Builder(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias) throws GraphQLRequestPreparationExceptionCreates a Builder- Parameters:
owningClass
- The class that contains this fieldfieldName
- The field for which we must build an ObjectResponsefieldAlias
- Its optional alias (may be null)- Throws:
GraphQLRequestPreparationException
-
Builder
public Builder(java.lang.Class<?> owningClass, java.lang.String fieldName, boolean queryLevel) throws GraphQLRequestPreparationExceptionCreates a Builder, for a field without alias- Parameters:
owningClass
- The class that contains this fieldfieldName
- The field for which we must build an ObjectResponsequeryLevel
- true if thisObjectResponse
contains the response definition from the query level. This is used in theQueryExecutorImpl.execute(String, ObjectResponse, Map, Class)
method, to properly build the request.- Throws:
GraphQLRequestPreparationException
-
Builder
public Builder(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias, boolean queryLevel) throws GraphQLRequestPreparationExceptionCreates a Builder- Parameters:
owningClass
- The class that contains this fieldfieldName
- The field for which we must build an ObjectResponsefieldAlias
- Its optional alias (may be null)queryLevel
- true if thisObjectResponse
contains the response definition from the query level. This is used in theQueryExecutorImpl.execute(String, ObjectResponse, Map, Class)
method, to properly build the request.- Throws:
GraphQLRequestPreparationException
-
-
Method Details
-
withField
Adds a scalar field with no alias, to theObjectResponse
we are building- Parameters:
fieldName
-- Returns:
- The current builder, to allow the standard builder construction chain
- Throws:
java.lang.NullPointerException
- If the fieldName is nullGraphQLRequestPreparationException
- If the fieldName or the fieldAlias is not valid
-
withField
public Builder withField(java.lang.String fieldName, java.lang.String alias) throws GraphQLRequestPreparationExceptionAdds a scalar field with an alias, to theObjectResponse
we are building. This field has no input parameters. To add a field with Input parameters, please use- Parameters:
fieldName
-alias
-- Returns:
- The current builder, to allow the standard builder construction chain
- Throws:
java.lang.NullPointerException
- If the fieldName is nullGraphQLRequestPreparationException
- If the fieldName or the fieldAlias is not valid
-
withField
public Builder withField(java.lang.String fieldName, java.lang.String alias, java.util.List<InputParameter> inputParameters, java.util.List<Directive> directives) throws GraphQLRequestPreparationExceptionAdds a scalar field with an alias, to theObjectResponse
we are building. This field has no input parameters. To add a field with Input parameters, please use- Parameters:
fieldName
-alias
-- Returns:
- The current builder, to allow the standard builder construction chain
- Throws:
java.lang.NullPointerException
- If the fieldName is nullGraphQLRequestPreparationException
- If the fieldName or the fieldAlias is not valid
-
withInputParameter
Deprecated.Add anInputParameter
to the current Object Response definition.- Parameters:
inputParameter
-- Returns:
- The current
Builder
-
withInputParameterHardCoded
Add anInputParameter
to the current Object Response definition.- Parameters:
name
- name of the field parameter, as defined in the GraphQL schemavalue
- The value to be sent to the server. If a String, it will be surroundered by double quotes, to be JSON compatible. Otherwise, the toString() method is called to write the result in the GraphQL query.- Returns:
- The current
Builder
-
withInputParameter
public Builder withInputParameter(java.lang.String name, java.lang.String bindParameterName, boolean mandatory) throws GraphQLRequestPreparationExceptionAdd anInputParameter
to the current Object Response definition.- Parameters:
name
- name of the field parameter, as defined in the GraphQL schemabindParameterName
- The name of the parameter, as it will be provided later for the request execution: it's up to the client application to provide (or not) a value associated with this parameterName.mandatory
- true if this parameter must be provided for request execution. If mandatory is true, and no value is provided for request execution, aGraphQLRequestExecutionException
exception will be thrown, instead of sending the request to the GraphQL server. Of course, parameter that are mandatory in the GraphQL schema should be declared as mandatory here. But, depending on your client use case, you may declare other parameter to be mandatory.- Returns:
- The current
Builder
- Throws:
GraphQLRequestPreparationException
-
withInputParameters
Add a list ofInputParameter
s to the current Object Response definition.- Parameters:
inputParameters
-- Returns:
- The current
Builder
-
withDirectives
Add a list ofDirective
s to the current Object Response definition.- Parameters:
directives
-- Returns:
- The current
Builder
-
withSubObject
public Builder withSubObject(ObjectResponse subobjetResponseDef) throws GraphQLRequestPreparationExceptionAdds a non scalar field (a sub-object), to theObjectResponse
we are building. The given objectResponse contains the field name and its optional alias.- Parameters:
subobjetResponseDef
- TheObjectResponse
for this sub-object- Returns:
- The current builder, to allow the standard builder construction chain
- Throws:
java.lang.NullPointerException
- If the fieldName is nullGraphQLRequestPreparationException
- If the subobjetResponseDef can't be added. For instance: the fieldName or the fieldAlias is not valid, or if the field of this subobjetResponseDef doesn't exist in the current owningClass...
-
build
Returns the builtObjectResponse
. If no field (either scalar or suboject) has been added, then all scalar fields are added.- Returns:
- Throws:
GraphQLRequestPreparationException
-
withQueryResponseDef
public Builder withQueryResponseDef(java.lang.String queryResponseDef) throws GraphQLRequestPreparationExceptionBuilds aObjectResponse
from a part of a GraphQL query. This part define what's expected as a response for the field of the currentObjectResponse
for this builder.- Parameters:
queryResponseDef
- A part of a response, for instance (for the hero query of the Star Wars GraphQL schema): "{ id name friends{name}}"
No special character are allowed (linefeed...).
This parameter can be a null or an empty string. In this case, all scalar fields are added.episode
-- Returns:
- Throws:
GraphQLRequestPreparationException
-
getCamelCase
public static java.lang.String getCamelCase(java.lang.String name)Convert the given name, to a camel case name. Currenly very simple : it puts the first character in lower case.- Returns:
-