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 Details

  • Method Details

    • withField

      public Builder withField​(java.lang.String fieldName) throws GraphQLRequestPreparationException
      Adds a scalar field with no alias, to the ObjectResponse we are building
      Parameters:
      fieldName -
      Returns:
      The current builder, to allow the standard builder construction chain
      Throws:
      java.lang.NullPointerException - If the fieldName is null
      GraphQLRequestPreparationException - If the fieldName or the fieldAlias is not valid
    • withField

      public Builder withField​(java.lang.String fieldName, java.lang.String alias) throws GraphQLRequestPreparationException
      Adds a scalar field with an alias, to the ObjectResponse 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 null
      GraphQLRequestPreparationException - 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 GraphQLRequestPreparationException
      Adds a scalar field with an alias, to the ObjectResponse 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 null
      GraphQLRequestPreparationException - If the fieldName or the fieldAlias is not valid
    • withInputParameter

      @Deprecated public Builder withInputParameter​(InputParameter inputParameter)
      Deprecated.
      Add an InputParameter to the current Object Response definition.
      Parameters:
      inputParameter -
      Returns:
      The current Builder
    • withInputParameterHardCoded

      public Builder withInputParameterHardCoded​(java.lang.String name, java.lang.Object value)
      Add an InputParameter to the current Object Response definition.
      Parameters:
      name - name of the field parameter, as defined in the GraphQL schema
      value - 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 GraphQLRequestPreparationException
      Add an InputParameter to the current Object Response definition.
      Parameters:
      name - name of the field parameter, as defined in the GraphQL schema
      bindParameterName - 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, a GraphQLRequestExecutionException 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

      public Builder withInputParameters​(java.util.List<InputParameter> inputParameters)
      Add a list of InputParameters to the current Object Response definition.
      Parameters:
      inputParameters -
      Returns:
      The current Builder
    • withDirectives

      public Builder withDirectives​(java.util.List<Directive> directives)
      Add a list of Directives to the current Object Response definition.
      Parameters:
      directives -
      Returns:
      The current Builder
    • withSubObject

      public Builder withSubObject​(ObjectResponse subobjetResponseDef) throws GraphQLRequestPreparationException
      Adds a non scalar field (a sub-object), to the ObjectResponse we are building. The given objectResponse contains the field name and its optional alias.
      Parameters:
      subobjetResponseDef - The ObjectResponse for this sub-object
      Returns:
      The current builder, to allow the standard builder construction chain
      Throws:
      java.lang.NullPointerException - If the fieldName is null
      GraphQLRequestPreparationException - 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 built ObjectResponse. 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 GraphQLRequestPreparationException
      Builds a ObjectResponse from a part of a GraphQL query. This part define what's expected as a response for the field of the current ObjectResponse 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: