Class QueryField


  • public class QueryField
    extends java.lang.Object
    This class gives parsing capabilities for the QueryString for one object.
    For instance, for the GraphQL query queryType.boards("{id name publiclyAvailable topics(since: \"2018-12-20\"){id}}"), it is created for the field named boards, then the #readTokenizerForResponseDefinition(StringTokenizer) is called for the whole String.
    Then another QueryField is created, for the field named topics, and the (since: \"2018-12-20\") is parsed by the #readTokenizerForInputParameters(StringTokenizer), then the {id} String is parsed by #readTokenizerForResponseDefinition(StringTokenizer) .
    Author:
    etienne-sf
    • Constructor Summary

      Constructors 
      Constructor Description
      QueryField​(java.lang.Class<?> owningClass, java.lang.String fieldName)
      The constructor, when created by the Builder: it must provide the owningClass
      QueryField​(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias)
      The constructor, when created by the Builder: it must provide the owningClass
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendToGraphQLRequests​(java.lang.StringBuilder sb, java.util.Map<java.lang.String,​java.lang.Object> parameters, boolean appendName)
      Append this query field in the StringBuilder in which the query is being written.
      java.lang.String getAlias()  
      java.lang.Class<?> getClazz()  
      java.util.List<QueryField> getFields()  
      java.lang.String getName()  
      java.lang.Class<?> getOwningClazz()  
      boolean isQueryLevel()
      Indicates whether this field is a query/mutation/subscription or not
      boolean isScalar()
      Indicates whether this field is a scalar or not.
      void readTokenizerForResponseDefinition​(QueryTokenizer qt, java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.lang.reflect.Field>> aliasFields, java.lang.String schema)
      Reads the definition of the expected response definition from the server.
      • Methods inherited from class java.lang.Object

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

      • QueryField

        public QueryField​(java.lang.Class<?> owningClass,
                          java.lang.String fieldName,
                          java.lang.String fieldAlias)
                   throws GraphQLRequestPreparationException
        The constructor, when created by the Builder: it must provide the owningClass
        Parameters:
        owningClass - The Class that owns the field
        fieldName - The name of the field
        fieldAlias - The alias for this field
        Throws:
        GraphQLRequestPreparationException
    • Method Detail

      • readTokenizerForResponseDefinition

        public void readTokenizerForResponseDefinition​(QueryTokenizer qt,
                                                       java.util.Map<java.lang.Class<?>,​java.util.Map<java.lang.String,​java.lang.reflect.Field>> aliasFields,
                                                       java.lang.String schema)
                                                throws GraphQLRequestPreparationException
        Reads the definition of the expected response definition from the server. It is recursive.
        For instance, for the GraphQL query queryType.boards("{id name publiclyAvailable topics(since: \"2018-12-20\"){id}}"), it will be called twice:
        Once for the String id name publiclyAvailable topics(since: \"2018-12-20\"){id}} (without the leading '{'), where QueryField is boards,
        Then for the String id}, where the QueryField is topics
        Parameters:
        qt - The StringTokenizer, where the next token is the first token after the '{' have already been read.
        The StringTokenizer is read until the '}' associated with this already read '{'.
        For instance, when this method is called with the StringTokenizer where these characters are still to read: id date author{name email alias} title content}}, the StringTokenizer is read until and including the first '}' that follows content. Thus, there is still a '}' to read.
        aliasFields - This maps contains the Field, that matches each alias, of each GraphQL type. This allows a proper deserialization of each alias value returned in the json response
        schema - value of the springBeanSuffix plugin parameter for the searched schema. When there is only one schema, this plugin parameter is usually not set. In this case, its default value ("") is used.
        Throws:
        GraphQLRequestPreparationException
      • appendToGraphQLRequests

        public void appendToGraphQLRequests​(java.lang.StringBuilder sb,
                                            java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                            boolean appendName)
                                     throws GraphQLRequestExecutionException
        Append this query field in the StringBuilder in which the query is being written. Any parameter will be replaced by its value. It's a recursive method, that calls itself when this field is not a scalar: it calls itself for each subfield.
        Parameters:
        sb -
        parameters -
        appendName - true if the name of the field must be written in the query (for regular fields for instance). False otherwise (for fragments, for instance)
        Throws:
        GraphQLRequestExecutionException
      • isQueryLevel

        public boolean isQueryLevel()
        Indicates whether this field is a query/mutation/subscription or not
        Returns:
        true if the QueryField is a query, a mutation or a subscription. False otherwise.
      • getFields

        public java.util.List<QueryField> getFields()
      • getOwningClazz

        public java.lang.Class<?> getOwningClazz()
      • getClazz

        public java.lang.Class<?> getClazz()
      • getName

        public java.lang.String getName()
      • getAlias

        public java.lang.String getAlias()