Class GraphqlClientUtils

java.lang.Object
com.graphql_java_generator.client.GraphqlClientUtils

@Component
public class GraphqlClientUtils
extends java.lang.Object
Author:
etienne-sf
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static GraphqlClientUtils graphqlClientUtils
    A singleton without Spring
  • Constructor Summary

    Constructors 
    Constructor Description
    GraphqlClientUtils()  
  • Method Summary

    Modifier and Type Method Description
    java.lang.Class<?> checkFieldOfGraphQLType​(java.lang.String name, java.lang.Boolean shouldBeScalar, java.lang.Class<?> owningClass)
    Check if the given field is owned by the class of this ObjectResponse.
    java.lang.Class<?> checkIsScalar​(java.lang.reflect.Field field, java.lang.Boolean shouldBeScalar)
    This method checks whether the given field (as an attribute) of the given class is a GraphQL scalar, or not, depending on shouldBeScalar.
    java.lang.Class<?> checkIsScalar​(java.lang.String fieldName, java.lang.reflect.Method method, java.lang.Boolean shouldBeScalar)
    This method checks whether the given field (as a method: getter, query...) of the given class is a GraphQL scalar, or not, depending on shouldBeScalar.
    void checkName​(java.lang.String graphqlIdentifier)
    Checks that the given GraphQL name is valid.
    java.util.Map<java.lang.String,​java.lang.Object> generatesBindVariableValuesMap​(java.lang.Object[] paramsAndValues)
    This method retrieves the couple of name and values given in these parameters, stores them in a map where the key is the param name, and the value is the value of the Map.
    graphql.schema.GraphQLScalarType getGraphQLCustomScalarType​(java.lang.reflect.AccessibleObject fieldOrMethod)
    This method retrieves the GraphQLScalarType for a custom scalar field or method.
    graphql.schema.GraphQLScalarType getGraphQLScalarTypeFromName​(java.lang.String typeName)
    Returns the GraphQL scalar type for the given Standard or Custom Scalar name, as defined in the GraphQL schema.
    java.lang.Class<?> getGraphQLType​(java.lang.reflect.AccessibleObject fieldOrMethod)
    Returns the Class indicated as the value for the graphqlType attribute of the GraphQLScalar or GraphQLNonScalar annotation
    java.lang.String getGraphQLTypeNameFromClass​(java.lang.Class<?> clazz)
    Retrieves the GraphQL type name (as defined in the GraphQL schema), from the GraphQL annotation added in the generated code by the plugin.
    boolean isScalar​(java.lang.reflect.AccessibleObject fieldOrMethod)
    Indicates whether the given class is a scalar or not

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • checkName

      public void checkName​(java.lang.String graphqlIdentifier) throws GraphQLRequestPreparationException
      Checks that the given GraphQL name is valid.
      Parameters:
      graphqlIdentifier -
      Throws:
      java.lang.NullPointerException - If name is null
      GraphQLRequestPreparationException - If the given graphqlIdentifier is not a valid identifier
    • checkIsScalar

      public java.lang.Class<?> checkIsScalar​(java.lang.reflect.Field field, java.lang.Boolean shouldBeScalar) throws GraphQLRequestPreparationException
      This method checks whether the given field (as an attribute) of the given class is a GraphQL scalar, or not, depending on shouldBeScalar.
      Parameters:
      field - The field whose type should be (or not) a scalar
      shouldBeScalar - if true, this method checks that field's type is a scalar (if false, checks that it is not a scalar)
      Returns:
      Returns the Class indicated as the value for the graphqlType attribute of the GraphQLScalar or GraphQLNonScalar annotation
      Throws:
      GraphQLRequestPreparationException
    • checkIsScalar

      public java.lang.Class<?> checkIsScalar​(java.lang.String fieldName, java.lang.reflect.Method method, java.lang.Boolean shouldBeScalar) throws GraphQLRequestPreparationException
      This method checks whether the given field (as a method: getter, query...) of the given class is a GraphQL scalar, or not, depending on shouldBeScalar.
      Parameters:
      fieldName - the name of the field represented by the given method.
      method - The method whose return should be (or not) a scalar. This method can be a setter, a getter (in which case its name is different from the fieldName), or a query/mutation/subscription (in which case its name is the fieldName)
      shouldBeScalar - if true, this method checks that method return type is a scalar (if false, checks that it is not a scalar)
      Throws:
      GraphQLRequestPreparationException
    • isScalar

      public boolean isScalar​(java.lang.reflect.AccessibleObject fieldOrMethod) throws GraphQLRequestPreparationException
      Indicates whether the given class is a scalar or not
      Parameters:
      fieldOrMethod -
      Returns:
      true if clazz is a scalar type
      Throws:
      GraphQLRequestPreparationException
    • getGraphQLType

      public java.lang.Class<?> getGraphQLType​(java.lang.reflect.AccessibleObject fieldOrMethod) throws GraphQLRequestPreparationException
      Returns the Class indicated as the value for the graphqlType attribute of the GraphQLScalar or GraphQLNonScalar annotation
      Parameters:
      fieldOrMethod -
      Returns:
      Throws:
      GraphQLRequestPreparationException
    • checkFieldOfGraphQLType

      public java.lang.Class<?> checkFieldOfGraphQLType​(java.lang.String name, java.lang.Boolean shouldBeScalar, java.lang.Class<?> owningClass) throws GraphQLRequestPreparationException
      Check if the given field is owned by the class of this ObjectResponse. This method returns the class for this field.
      Parameters:
      name - The name of the field we want to check
      shouldBeScalar - if true: also checks that the field is a scalar (throws a GraphQLRequestPreparationException if not). If false: also checks that the field is not a scalar (throws a GraphQLRequestPreparationException if not). If null: no check whether the field is a scalar or not
      owningClass - The class in which will search for name as a GraphQL field
      Returns:
      the class of this field
      Throws:
      java.lang.NullPointerException - if name is null
      GraphQLRequestPreparationException - if the check is KO
    • generatesBindVariableValuesMap

      public java.util.Map<java.lang.String,​java.lang.Object> generatesBindVariableValuesMap​(java.lang.Object[] paramsAndValues) throws GraphQLRequestExecutionException, java.lang.ClassCastException
      This method retrieves the couple of name and values given in these parameters, stores them in a map where the key is the param name, and the value is the value of the Map.
      Parameters:
      paramsAndValues - A series of name and values : (paramName1, paramValue1, paramName2, paramValue2...). So there must be an even number of items in this array. Empty arrays are allowed (that is no parameter name and value).
      This series is sent by the developer's code, when it calls the request methods.
      Returns:
      The map with paramName1, paramName2 (...) are the keys, and paramValue1, paramValue2 (...) are the associated content.
      Throws:
      GraphQLRequestExecutionException - When a non-even number of parameters is sent to this method
      java.lang.ClassCastException - When a parameter name is not a String
    • getGraphQLTypeNameFromClass

      public java.lang.String getGraphQLTypeNameFromClass​(java.lang.Class<?> clazz)
      Retrieves the GraphQL type name (as defined in the GraphQL schema), from the GraphQL annotation added in the generated code by the plugin.
      Parameters:
      clazz -
      Returns:
    • getGraphQLCustomScalarType

      public graphql.schema.GraphQLScalarType getGraphQLCustomScalarType​(java.lang.reflect.AccessibleObject fieldOrMethod)
      This method retrieves the GraphQLScalarType for a custom scalar field or method. GraphQLScalar is used in generated InputType and response type POJOs and GraphQLCustomScalar is used in some legacy generated response type POJOs.
      Parameters:
      fieldOrMethod - The field or method of the generated POJO class
      Returns:
      the GraphQLScalarType
    • getGraphQLScalarTypeFromName

      public graphql.schema.GraphQLScalarType getGraphQLScalarTypeFromName​(java.lang.String typeName)
      Returns the GraphQL scalar type for the given Standard or Custom Scalar name, as defined in the GraphQL schema. The GraphQLScalarType contains the method that allows to parse a String value, parse an AST value, or serialize the value (for instance to write it into a JSON string)
      Parameters:
      typeName -
      Returns:
      The GraphQL type. Or null if not found (enum, object, input type, interface, union)