Class GraphqlUtils

java.lang.Object
com.graphql_java_generator.GraphqlUtils

@Component
public class GraphqlUtils
extends java.lang.Object
Author:
EtienneSF
  • Constructor Summary

    Constructors 
    Constructor Description
    GraphqlUtils()  
  • Method Summary

    Modifier and Type Method Description
    <T> java.lang.reflect.Method getGetter​(java.lang.Class<T> clazz, java.lang.reflect.Field field)
    Retrieves the getter for the given field on the given field
    <T> T getInputObject​(java.util.Map<java.lang.String,​java.lang.Object> map, java.lang.Class<T> clazz)
    This method returns a GraphQL input object, as defined in the GraphQL schema, from the Map that has been read from the JSON object sent to the server.
    <T> java.util.List<T> getListInputObjects​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> list, java.lang.Class<T> clazz)
    This method returns a list of instances of the given class, from a list of Map.
    java.lang.String getPascalCase​(java.lang.String name)
    Returns the given name in PascalCase.
    <T> java.lang.reflect.Method getSetter​(java.lang.Class<T> clazz, java.lang.reflect.Field field)
    Retrieves the setter for the given field on the given field
    java.lang.Object invokeGetter​(java.lang.Object object, java.lang.String fieldName)
    Invoke the getter for the given field name, on the given object.
    void invokeSetter​(java.lang.Object object, java.lang.reflect.Field field, java.lang.Object value)
    Invoke the setter for the given field, on the given object.
    void invokeSetter​(java.lang.Object object, java.lang.String fieldName, java.lang.Object value)
    Invoke the setter for the Field of the given name, on the given object.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • getPascalCase

      public java.lang.String getPascalCase​(java.lang.String name)
      Returns the given name in PascalCase. For instance: theName -> TheName
      Parameters:
      name -
      Returns:
    • getInputObject

      public <T> T getInputObject​(java.util.Map<java.lang.String,​java.lang.Object> map, java.lang.Class<T> clazz)
      This method returns a GraphQL input object, as defined in the GraphQL schema, from the Map that has been read from the JSON object sent to the server.
      Type Parameters:
      T - The class expected to be returned
      Parameters:
      map - The map, read from the JSON in the GraphQL request. Only the part of the map, related to the expected class is sent.
      t - An empty instance of the expected type. This instance's fields will be set by this method, from the value in the map
      Returns:
      An instance of the expected class. If the map is null, null is returned. Of the map is empty, anew instance is returned, with all its fields are left empty
    • getListInputObjects

      public <T> java.util.List<T> getListInputObjects​(java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> list, java.lang.Class<T> clazz)
      This method returns a list of instances of the given class, from a list of Map. This is used on server-side, to map the input read from the JSON into the InputType that have been declared in the GraphQL schema.
      Type Parameters:
      T -
      Parameters:
      list -
      clazz -
      Returns:
    • getSetter

      public <T> java.lang.reflect.Method getSetter​(java.lang.Class<T> clazz, java.lang.reflect.Field field)
      Retrieves the setter for the given field on the given field
      Type Parameters:
      T -
      Parameters:
      t -
      field -
      Returns:
    • getGetter

      public <T> java.lang.reflect.Method getGetter​(java.lang.Class<T> clazz, java.lang.reflect.Field field)
      Retrieves the getter for the given field on the given field
      Type Parameters:
      T -
      Parameters:
      t -
      field -
      Returns:
    • invokeGetter

      public java.lang.Object invokeGetter​(java.lang.Object object, java.lang.String fieldName)
      Invoke the getter for the given field name, on the given object. All check exceptions are hidden in a RuntimeException
      Parameters:
      object -
      fieldName -
      Returns:
      the field's value for the given object
      Throws:
      java.lang.RuntimeException - If any exception occurs
    • invokeSetter

      public void invokeSetter​(java.lang.Object object, java.lang.reflect.Field field, java.lang.Object value)
      Invoke the setter for the given field, on the given object. All check exceptions are hidden in a RuntimeException
      Parameters:
      object -
      field -
      value -
      Throws:
      java.lang.RuntimeException - If any exception occurs
    • invokeSetter

      public void invokeSetter​(java.lang.Object object, java.lang.String fieldName, java.lang.Object value)
      Invoke the setter for the Field of the given name, on the given object. All check exceptions are hidden in a RuntimeException
      Parameters:
      object -
      fieldName -
      value -
      Throws:
      java.lang.RuntimeException - If any exception occurs