Class QueryTokenizer

java.lang.Object
com.graphql_java_generator.client.request.QueryTokenizer

public class QueryTokenizer extends Object
This class is responsible to split the GraphQL query into meaningful tokens: the spaces, EOL (...) are removed and the (, @, { (...) are sent as token. It also allows to check the comming tokens. For instance, when reading a field name, it's possible to check if the next token is :, which means that the current token s not the field name, but the field alias.
Author:
etienne-sf
  • Field Details

    • EMPTY_DELIMITERS

      public static final String EMPTY_DELIMITERS
      The list of character that can separate tokens, and that has no meaning. By default, these tokens are removed from the result, and won't be visible in the returned tokens.
      See Also:
    • MEANINGFUL_DELIMITERS

      public static final String MEANINGFUL_DELIMITERS
      See Also:
  • Constructor Details

    • QueryTokenizer

      public QueryTokenizer(String graphQLRequest)
      Create a tokenizer for the given GraphQL query
      Parameters:
      graphQLRequest -
      Throws:
      NullPointerException - If graphQLRequest is null
  • Method Details

    • hasMoreTokens

      public boolean hasMoreTokens()
      Indicates if there are next non empty tokens in the list.
      Returns:
      true if there are real token or meaningful delimiters left to read
    • hasMoreTokens

      public boolean hasMoreTokens(boolean returnEmptyDelimiters)
      Indicates if there are next non empty tokens in the list.
      Parameters:
      returnEmptyDelimiters - If true, all token are sent, which means that every character found in the source String are sent as token. Each separator is sent one character per one character.
      If false the characters that are in the EMPTY_DELIMITERS are not sent.
      Returns:
      true if there are real token or meaningful delimiters left to read
    • nextToken

      public String nextToken()
      Returns the next token. The characters that exist in the MEANINGFUL_DELIMITERS are sent one character by one character. The characters that exist in the EMPTY_DELIMITERS are not sent.
      Returns:
    • nextToken

      public String nextToken(boolean returnEmptyDelimiters)
      Returns the next token, which may or may not be an empty one, depending on returnEmptyDelimiters
      Parameters:
      returnEmptyDelimiters - If true, all token are sent, which means that every character found in the source String are sent as token. Each separator is sent one character per one character.
      If false the characters that are in the EMPTY_DELIMITERS are not sent.
      Returns:
    • checkNextToken

      public boolean checkNextToken(String expected)
      Checks if the next meaningful token is the expected string that is given. The index is not updated, which means that if this method returns true, the next returned token will be the expected value.
      Parameters:
      expected -
      Returns:
    • checkNextTokenStartsWith

      public boolean checkNextTokenStartsWith(String expectedStart)
      Checks if the next meaningful token starts by the expected string that is given. The index is not updated, which means that if this method returns true, the next returned token will be the token that begins by the expected string.
      Parameters:
      expectedStart -
      Returns:
    • readNextRealToken

      public String readNextRealToken(String expected, String action) throws GraphQLRequestPreparationException
      Reads the next real token, that is the next token that is not a separator
      Parameters:
      expected - If expected is not null, this method will check that the real token read is equal to this expected value
      action - The action for which the real token is needed (use to get some context in a the exception message, if any). The exception message will be: "error occurs while " + action
      Returns:
      Throws:
      GraphQLRequestPreparationException