When exact paths to GraphQL schemas are too cumbersome to provide in the graphqlSchemaPaths, use the graphqlSchemas
block. The parameters inside that block are the following:
Key inside graphqlSchemas |
Data Type | Default value | Description |
|---|---|---|---|
rootDir |
String | Main resources dir | The root directory from which to start searching for schema files. |
recursive |
Boolean | true |
Whether to recursively look into sub directories. |
includePattern |
String | .*\.graphqls? |
A Java regex that file names must match to be included. It should be a regex as defined by the Pattern JDK class. It will be used to match only the file name without path. |
excludedFiles |
Set | (empty set) | A set of files to exclude, even if they match the include pattern. These paths should be either absolute or relative to the provided rootDir. |
Defines how to generate interfaces (resolvers) for each operation: Query/Mutation/Subscription. Provides ability
to skip generation of separate interface class for each operation in favor of having a single "root" interface (
see ApiRootInterfaceStrategy
and ApiNamePrefixStrategy)
| Value | Description |
|---|---|
INTERFACE_PER_OPERATION (default) |
Generate separate interface classes for each GraphQL operation. |
DO_NOT_GENERATE |
Do not generate separate interfaces classes for GraphQL operation. |
Defines how root interface (QueryResolver / MutationResolver / SubscriptionResolver will be generated (in addition
to separate interfaces for each query/mutation/subscription)
| Value | Description |
|---|---|
INTERFACE_PER_SCHEMA |
Generate multiple super-interfaces for each graphql file. Takes into account apiNamePrefixStrategy. E.g.: OrderServiceQueryResolver.java, ProductServiceQueryResolver.java, etc. |
SINGLE_INTERFACE (default) |
Generate a single QueryResolver.java, MutationResolver.java, SubscriptionResolver.java for all graphql schema files. |
DO_NOT_GENERATE |
Do not generate super interface for GraphQL operations. |
Defines which prefix to use for API interfaces.
| Value | Description |
|---|---|
FILE_NAME_AS_PREFIX |
Will take GraphQL file name as a prefix for all generated API interfaces + value of apiNamePrefix config option. E.g.: * following schemas: resources/schemas/order-service.graphql, resources/schemas/product-service.graphql * will result in: OrderServiceQueryResolver.java, ProductServiceQueryResolver.java, etc |
FOLDER_NAME_AS_PREFIX |
Will take parent folder name as a prefix for all generated API interfaces + value of apiNamePrefix config option. E.g.:* following schemas: resources/order-service/schema1.graphql, resources/order-service/schema2.graphql * will result in: OrderServiceQueryResolver.java, OrderServiceGetOrderByIdQueryResolver.java, etc |
CONSTANT (default) |
Will take only the value of apiNamePrefix config option. |
resources/schemas/order-service.graphql*, *
resources/schemas/product-service.graphql*
* will result in: OrderServiceQueryResolver.java
, ProductServiceQueryResolver.java, etc | | FOLDER_NAME_AS_PREFIX | Will take parent folder name as a prefix for
all generated API interfaces + value of apiNamePrefix config option. E.g.:
* following schemas: *
resources/order-service/schema1.graphql*, *
resources/order-service/schema2.graphql*
* will result in: OrderServiceQueryResolver.java
, OrderServiceGetOrderByIdQueryResolver.java, etc | | CONSTANT (default) | Will take only the value
of apiNamePrefix config option. |
Following options can be defined if you want generated resolvers to extend certain interfaces. Can be handy if you are using graphql-java-tools and want your resolver classes to extend only interfaces generated by this plugin.
Note: if you want to include a GraphQL type name into the interface name, then use {{TYPE}} placeholder.
E.g.: graphql.kickstart.tools.GraphQLResolver<{{TYPE}}>
Key inside parentInterfaces |
Data Type | Default value | Description |
|---|---|---|---|
queryResolver |
String | Empty | Interface that will be added as "extend" to all generated api Query interfaces. |
mutationResolver |
String | Empty | Interface that will be added as "extend" to all generated api Mutation interfaces. |
subscriptionResolver |
String | Empty | Interface that will be added as "extend" to all generated api Subscription interfaces. |
resolver |
String | Empty | Interface that will be added as "extend" to all generated TypeResolver interfaces. |
Can be used to supply custom mappings for scalars.
Supports following formats:
- Map of (GraphQLObjectName.fieldName) to (JavaType). E.g.:
Event.dateTime = java.util.Date - Map of (GraphQLType) to (JavaType). E.g.:
EpochMillis = java.time.LocalDateTime
Can be used to supply custom annotations (serializers) for scalars.
@ in front of the annotation class is optional.
Supports following formats:
- Map of (GraphQLObjectName.fieldName) to (JavaAnnotation).
E.g.:
Event.dateTime = @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.DateDeserializer.class) - Map of (GraphQLType) to (JavaAnnotation).
E.g.:
EpochMillis = @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.EpochMillisDeserializer.class)
Can be used to supply custom annotations for directives in a following format:
Map of (GraphQL.directiveName) to (JavaAnnotation).
E.g.: auth = @org.springframework.security.access.annotation.Secured({{roles}}).
@ in front of the annotation class is optional.
Note: In order to supply the value of directive argument to annotation, use placeholder {{directiveArgument}}. You
can also use one of the formatters for directive argument value: {{val?toString}}, {{val?toArray}}
, {{val?toArrayOfStrings}}.
Can be used to supply a custom configuration for Relay support. For reference see: https://www.graphql-java-kickstart.com/tools/relay/
For example, the following schema:
type Query { users(first: Int, after: String): UserConnection @connection(for: "User") }
will result in generating the interface with the following method:
graphql.relay.Connection<User> users(Integer first, String after) throws Exception;
Provide a path to external file via property configurationFiles
Sample content of the file:
JSON:
{
"generateApis": true,
"packageName": "com.kobylynskyi.graphql.testconfigjson",
"customTypesMapping": {
"Price.amount": "java.math.BigDecimal"
}
}generateClient=true
generateApis=true
generateBuilder=true
generateImmutableModels=true
generateToString=true
generateEqualsAndHashCode=true
apiPackageName="io.github.graphql.j.resolver"
modelPackageName="io.github.graphql.j.model"
modelNameSuffix="TO"
apiInterfaceStrategy="DO_NOT_GENERATE"
apiRootInterfaceStrategy="SINGLE_INTERFACE"
generateModelsForRootTypes=true
apiNamePrefix="GitHub"
addGeneratedAnnotation=false
generatedLanguage="KOTLIN"
customTypesMapping={
Long="Long",
Object="org.json.JSONObject"
}
customAnnotationsMapping={
"QuestionNode.metaData"=["com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.github.dreamylost.JsonObjectDeserializer::class)"]
"QuestionNode.envInfo"=["com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.github.dreamylost.JsonObjectDeserializer::class)"]
}
