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
FieldsModifier and TypeFieldDescriptionprotected AddRelayConnectionsA utility that adds Relay Connection capabilities to the read schema.protected CommonConfigurationThis instance is responsible for providing all the configuration parameters from the project configuration (Maven, Gradle...)protected List<CustomScalarType>All theCustomScalarTypewhich have been read during the reading of the documentsprotected final Stringprotected final Stringprotected final StringList of all the directives that have been read in the GraphQL schemaAll theObjectTypewhich have been read during the reading of the documentsprotected GraphqlUtilsVarious utilities, grouped in a dedicated classprotected List<InterfaceType>All theInterfaceTypeDefinitionwhich have been read during the reading of the documentsprotected ObjectTypeThe Mutation root operation for this Document, if defined (that is: if this schema implements one or more mutations)protected StringThe name of the type that implements the mutation operation.protected ObjectTypeThe Query root operation for this Documentprotected StringThe 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 theschemain the GraphQL schemaprotected ResourceSchemaStringProviderThis Spring Bean is responsible for finding and loading all the GraphQL schema files, based on the project configuration.protected ObjectTypeThe Subscription root operation for this Document, if defined (that is: if this schema implements one or more subscriptions)protected StringThe name of the type that implements the subscription operation.All theTypes that have been parsed, added by the default scalars.All theUnionTypeDefinitionwhich have been read during the reading of the documents -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidFill thetypesmap, 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> TReturns the type for the given name, where the found type is of an expected kind.protected StringReturns the name of the package for utility classes.
In this class, it always return the result ofCommonConfiguration#getPackageName()protected voidinitScalarTypes(Class<?> IDclass) This method initializes thescalarTypeslist.intThe 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 theDirectiveImplfor 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 theschemain 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 theInterfaceTypeDefinitionwhich have been read during the reading of the documents -
unionTypes
All theUnionTypeDefinitionwhich have been read during the reading of the documents -
enumTypes
All theObjectTypewhich 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 theCustomScalarTypewhich have been read during the reading of the documents -
types
All theTypes 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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
initScalarTypes
This method initializes thescalarTypeslist. 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 thetypesmap, 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 theDirectiveImplfor 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 anEnumTypeDefinitionor 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, aRuntimeExceptionis 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, aRuntimeExceptionis 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:
-