Class QueryField
java.lang.Object
com.graphql_java_generator.client.request.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
Then another
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 theBuilder
: it must provide the owningClassQueryField(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias)
The constructor, when created by theBuilder
: it must provide the owningClass -
Method Summary
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 theStringBuilder
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 notboolean
isScalar()
Indicates whether this field is a scalar or not.void
readTokenizerForResponseDefinition(QueryTokenizer qt)
Reads the definition of the expected response definition from the server.
-
Constructor Details
-
QueryField
public QueryField(java.lang.Class<?> owningClass, java.lang.String fieldName, java.lang.String fieldAlias) throws GraphQLRequestPreparationExceptionThe constructor, when created by theBuilder
: it must provide the owningClass- Parameters:
owningClass
- TheClass
that owns the fieldfieldName
- The name of the fieldfieldAlias
- The alias for this field- Throws:
GraphQLRequestPreparationException
-
QueryField
public QueryField(java.lang.Class<?> owningClass, java.lang.String fieldName) throws GraphQLRequestPreparationExceptionThe constructor, when created by theBuilder
: it must provide the owningClass- Parameters:
owningClass
- TheClass
that owns the fieldfieldName
- The name of the field- Throws:
GraphQLRequestPreparationException
-
-
Method Details
-
readTokenizerForResponseDefinition
public void readTokenizerForResponseDefinition(QueryTokenizer qt) throws GraphQLRequestPreparationExceptionReads 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
- TheStringTokenizer
, where the next token is the first token after the '{' have already been read.
TheStringTokenizer
is read until the '}' associated with this already read '{'.
For instance, when this method is called with theStringTokenizer
where these characters are still to read: id date author{name email alias} title content}}, theStringTokenizer
is read until and including the first '}' that follows content. Thus, there is still a '}' to read.- Throws:
GraphQLRequestPreparationException
-
appendToGraphQLRequests
public void appendToGraphQLRequests(java.lang.StringBuilder sb, java.util.Map<java.lang.String,java.lang.Object> parameters, boolean appendName) throws GraphQLRequestExecutionExceptionAppend this query field in theStringBuilder
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
-
isScalar
Indicates whether this field is a scalar or not.- Returns:
- true if this field is a scalar (custom or not), and false otherwise.
- Throws:
GraphQLRequestPreparationException
-
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
-
getOwningClazz
public java.lang.Class<?> getOwningClazz() -
getClazz
public java.lang.Class<?> getClazz() -
getName
public java.lang.String getName() -
getAlias
public java.lang.String getAlias()
-