<build>
<plugins>
...
<plugin>
<groupId>io.github.kobylynskyi</groupId>
<artifactId>graphql-codegen-maven-plugin</artifactId>
<version>5.10.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- all config options:
https://github.com/kobylynskyi/graphql-java-codegen/blob/main/docs/codegen-options.md
-->
<graphqlSchemas>
<includePattern>schema\.graphqls</includePattern>
</graphqlSchemas>
<outputDir>${project.build.directory}/generated-sources/graphql</outputDir>
<packageName>io.github.kobylynskyi.bikeshop.graphql.model</packageName>
<customTypesMapping>
<DateTime>java.util.Date</DateTime>
<Price.amount>java.math.BigDecimal</Price.amount>
</customTypesMapping>
<customAnnotationsMapping>
<EpochMillis>
<annotation>com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.example.json.EpochMillisScalarDeserializer.class)</annotation>
</EpochMillis>
</customAnnotationsMapping>
<modelNameSuffix>TO</modelNameSuffix>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
You can run the plugin manually with mvn generate-sources
. It will be run automatically as part of the Maven lifecycle
when compiling your code
Please refer to Codegen Options
- Plugin configuration in pom.xml
- Building GraphQL request and parsing response using Spring RestTemplate
- Building GraphQL request and parsing response using RestAssured
If you want to have different configuration for different .graphqls
files (e.g.: different javaPackage, outputDir,
etc.), then you will need to define separate executions for each set of schemas. E.g.:
<executions>
<execution>
<id>graphqlCodegenService1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<graphqlSchemaPaths>${project.basedir}/src/main/resources/schema1.graphqls</graphqlSchemaPaths>
<outputDir>${project.build.directory}/generated-sources/graphql1</outputDir>
</configuration>
</execution>
<execution>
<id>graphqlCodegenService2</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<graphqlSchemaPaths>${project.basedir}/src/main/resources/schema2.graphqls</graphqlSchemaPaths>
<outputDir>${project.build.directory}/generated-sources/graphql2</outputDir>
</configuration>
</execution>
</executions>