Class DocumentParser
java.lang.Object
com.graphql_java_generator.plugin.DocumentParser
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
GenerateCodeDocumentParser
,GenerateGraphQLSchemaDocumentParser
public abstract class DocumentParser
extends Object
implements org.springframework.beans.factory.InitializingBean
This class generates the Java classes, from the documents. These documents are read from the
graphql-spring-boot-starter code, in injected here thanks to spring's magic.
There is no validity check: we trust the information in the Document, as it is read by the GraphQL
The graphQL-java library maps both FieldDefinition and InputValueDefinition in very similar structures, which are actually trees. These structures are too hard too read in a Velocity template, and we need to parse down to a properly structures way for that.
There is no validity check: we trust the information in the Document, as it is read by the GraphQL
Parser
.
The graphQL-java library maps both FieldDefinition and InputValueDefinition in very similar structures, which are actually trees. These structures are too hard too read in a Velocity template, and we need to parse down to a properly structures way for that.
- Author:
- etienne-sf
-
Field Summary
Modifier and TypeFieldDescriptionprotected AddRelayConnections
A utility that adds Relay Connection capabilities to the read schema.protected CommonConfiguration
This instance is responsible for providing all the configuration parameters from the project configuration (Maven, Gradle...)protected List<CustomScalarType>
All theCustomScalarType
which have been read during the reading of the documentsprotected final String
protected final String
protected final String
List of all the directives that have been read in the GraphQL schemaAll theObjectType
which have been read during the reading of the documentsprotected GraphqlUtils
Various utilities, grouped in a dedicated classprotected List<InterfaceType>
All theInterfaceTypeDefinition
which have been read during the reading of the documentsprotected ObjectType
The Mutation root operation for this Document, if defined (that is: if this schema implements one or more mutations)protected String
The name of the type that implements the mutation operation.protected ObjectType
The Query root operation for this Documentprotected String
The name of the type that implements the query operation.protected List<ScalarType>
maps for all scalers, when they are mandatory.protected List<AppliedDirective>
List of the directives that have declared for theschema
in the GraphQL schemaprotected ResourceSchemaStringProvider
This Spring Bean is responsible for finding and loading all the GraphQL schema files, based on the project configuration.protected ObjectType
The Subscription root operation for this Document, if defined (that is: if this schema implements one or more subscriptions)protected String
The name of the type that implements the subscription operation.All theType
s that have been parsed, added by the default scalars.All theUnionTypeDefinition
which have been read during the reading of the documents -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Fill thetypes
map, from all the types (object, interface, enum, scalars) that are valid for this schema.getDirectiveDefinition
(String name) Returns the type for the given nameReturns the type for the given name<T> T
Returns the type for the given name, where the found type is of an expected kind.protected String
Returns the name of the package for utility classes.
In this class, it always return the result ofCommonConfiguration#getPackageName()
protected void
initScalarTypes
(Class<?> IDclass) This method initializes thescalarTypes
list.int
The main method of the class: it graphqlUtils.executes the generation of the GraphQL schemas, as defined in the project configurationreadDirectiveDefinition
(graphql.language.DirectiveDefinition node) Reads a directive definition, and stores its informations into theDirectiveImpl
for further processingreadEnumType
(EnumType enumType, graphql.language.EnumTypeDefinition node) Reads an enum definition.readObjectTypeDefinition
(graphql.language.ObjectTypeDefinition node) Read an object type from its GraphQL definition
-
Field Details
-
DEFAULT_QUERY_NAME
- See Also:
-
DEFAULT_MUTATION_NAME
- See Also:
-
DEFAULT_SUBSCRIPTION_NAME
- See Also:
-
configuration
This instance is responsible for providing all the configuration parameters from the project configuration (Maven, Gradle...) -
addRelayConnections
A utility that adds Relay Connection capabilities to the read schema. It is called if theCommonConfiguration.isAddRelayConnections()
is true -
graphqlUtils
Various utilities, grouped in a dedicated class -
schemaStringProvider
This Spring Bean is responsible for finding and loading all the GraphQL schema files, based on the project configuration. -
directives
List of all the directives that have been read in the GraphQL schema -
schemaDirectives
List of the directives that have declared for theschema
in the GraphQL schema -
queryTypeName
The name of the type that implements the query operation. The default name is "Query". It is overridden in thereadSchemaDefinition()
method, if defined in the provided GraphQL schema. -
queryType
The Query root operation for this Document -
mutationTypeName
The name of the type that implements the mutation operation. The default name is "Mutation". It is overridden in thereadSchemaDefinition()
method, if defined in the provided GraphQL schema. -
mutationType
The Mutation root operation for this Document, if defined (that is: if this schema implements one or more mutations) -
subscriptionTypeName
The name of the type that implements the subscription operation. The default name is "Subscription". It is overridden in thereadSchemaDefinition()
method, if defined in the provided GraphQL schema. -
subscriptionType
The Subscription root operation for this Document, if defined (that is: if this schema implements one or more subscriptions) -
interfaceTypes
All theInterfaceTypeDefinition
which have been read during the reading of the documents -
unionTypes
All theUnionTypeDefinition
which have been read during the reading of the documents -
enumTypes
All theObjectType
which have been read during the reading of the documents -
scalarTypes
maps for all scalers, when they are mandatory. The key is the type name. The value is the class to use in the java code -
customScalars
All theCustomScalarType
which have been read during the reading of the documents -
types
All theType
s that have been parsed, added by the default scalars. So it contains the query, the mutation (if defined), the subscription (if defined), the types, the input types, all the scalars (including the default ones), the interfaces, the unions and the enums.
The key is the type's name. The value is theType
.
-
-
Constructor Details
-
DocumentParser
public DocumentParser()
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
initScalarTypes
This method initializes thescalarTypes
list. This list depends on the use case- Parameters:
IDclass
-
-
parseGraphQLSchemas
The main method of the class: it graphqlUtils.executes the generation of the GraphQL schemas, as defined in the project configuration- Returns:
- Throws:
IOException
- When an error occurs, during the parsing of the GraphQL schemas
-
fillTypesMap
public void fillTypesMap()Fill thetypes
map, from all the types (object, interface, enum, scalars) that are valid for this schema. This allow to get the properties from their type, as only their type's name is known when parsing the schema. -
readDirectiveDefinition
Reads a directive definition, and stores its informations into theDirectiveImpl
for further processing- Parameters:
node
-- Returns:
-
getDirectiveDefinition
-
readObjectTypeDefinition
Read an object type from its GraphQL definition- Parameters:
node
-- Returns:
-
readEnumType
Reads an enum definition. It can be called from either anEnumTypeDefinition
or anEnumTypeExtensionDefinition
- Parameters:
enumType
- The enum for which the definition is read.node
-- Returns:
-
getType
Returns the type for the given name- Parameters:
typeName
-- Returns:
- Throws:
RuntimeException
- if the type could not be found
-
getType
Returns the type for the given name- Parameters:
typeName
-throwExceptionIfNotFound
- If true, aRuntimeException
is thrown when the type is not found. If false and the type is not found, null is returned.- Returns:
- The found type, or null if the type is not found and throwExceptionIfNotFound is false
- Throws:
RuntimeException
- if throwExceptionIfNotFound is true and the type could not be found
-
getType
Returns the type for the given name, where the found type is of an expected kind.- Parameters:
typeName
-classOfType
- The expected class for this type (typically one ofScalarType
,ObjectType
...)throwExceptionIfNotFound
- If true, aRuntimeException
is thrown when the type is not found. If false and the type is not found, null is returned.- Returns:
- The found type, or null if the type is not found and throwExceptionIfNotFound is false
- Throws:
RuntimeException
- if throwExceptionIfNotFound is true and the type could not be found
-
getUtilPackageName
Returns the name of the package for utility classes.
In this class, it always return the result ofCommonConfiguration#getPackageName()
- Returns:
-