Class QueryField
java.lang.Object
com.graphql_java_generator.client.request.QueryField
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
ConstructorDescriptionQueryField
(Class<?> owningClass, String fieldName) The constructor, when created by theBuilder
: it must provide the owningClassQueryField
(Class<?> owningClass, String fieldName, String fieldAlias) The constructor, when created by theBuilder
: it must provide the owningClass -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendToGraphQLRequests
(StringBuilder sb, Map<String, Object> parameters, boolean appendName) Append this query field in theStringBuilder
in which the query is being written.getAlias()
Class<?>
getClazz()
getName()
Class<?>
boolean
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, Map<Class<?>, Map<String, Field>> aliasFields, String schema) Reads the definition of the expected response definition from the server.
-
Constructor Details
-
QueryField
public QueryField(Class<?> owningClass, String fieldName, String fieldAlias) throws GraphQLRequestPreparationException The 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
The 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, Map<Class<?>, Map<String, throws GraphQLRequestPreparationExceptionField>> aliasFields, String schema) 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
- 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.aliasFields
- This maps contains theField
, that matches each alias, of each GraphQL type. This allows a proper deserialization of each alias value returned in the json responseschema
- 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(StringBuilder sb, Map<String, 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
-
getClazz
-
getName
-
getAlias
-