-
Notifications
You must be signed in to change notification settings - Fork 47
client_runtimeclasses
- Runtime Classes
- [Recommended way] How to use the configure source code generation to not include runtime classes?
- How to use the configure source code generation to include runtime classes?
Note:
- This is the recommended usage is to NOT COPY the runtime classes, and leave them in the dependencies.
- When running against more than one GraphQL servers, you must not copy the runtime classes, or copy them only once.
As the result of the execution of graphql-maven-plugin:generateClientCode maven goal or gradle task, two type of source code is generated:
- The Query, Mutation and POJOs classes, that are the Java part for the GraphQL schema
- All the necessary runtime classes that do not depend on the schema and support the client execution
The runtime classes may be copied as source code so that, your project, when it runs, doesn't depend on any external dependency from graphql-java-generator.
To copy the generation of runtime classes you can use the parameter copyRuntimeSources (-Dcom.graphql_java_generator.mavenplugin.copyRuntimeSources). If copyRuntimeSources is false, then the runtime classes won't be copied. By default, the parameter value is true.
Do this, set the plugin parameter copyRuntimeSources (-Dcom.graphql_java_generator.mavenplugin.copyRuntimeSources) to false:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-maven-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<goals>
<goal>graphql</goal>
</goals>
</execution>
</executions>
<configuration>
<mode>client</mode>
<packageName>my.target.package</packageName>
<copyRuntimeSources>false</copyRuntimeSources> <!-- This will be the default value for 2.x plugin versions -->
</configuration>
</plugin>
</plugins>
</build>
...
</project>
In this case, you must have the graphql-java-client-runtime
dependency in your project, like this:
For Maven projects:
<project ...>
...
<dependencies>
...
<dependency>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-java-client-runtime</artifactId>
<version>2.8</version>
</dependency>
...
</dependencies>
...
</project>
For gradle projects:
dependencies {
...
// The graphql-java-client-dependencies module agregates all dependencies for the generated code
implementation "com.graphql-java-generator:graphql-java-client-runtime:${graphQLJavaGeneratorVersion}"
...
}
Do this, set the plugin parameter copyRuntimeSources (-Dcom.graphql_java_generator.mavenplugin.copyRuntimeSources) to true.
The main purpose for adding this feature to the plugin is double:
- Do not generate/keep non-model dependent code if it's already in a dependency. If for some reason an upgrade or patch of the runtime classes is released, the code does not need to be regenerated and just the graphql-java-client-runtime dependency version must be updated.
- On the other hand, in some cases, you may want to customize the runtime classes with customized behavior. I know that this may sound a bit strange but I found myself in this situation.
Here there's an example of plugin configuration to not generate runtime classes
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-maven-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<goals>
<goal>graphql</goal>
</goals>
</execution>
</executions>
<configuration>
<mode>client</mode>
<packageName>my.target.package</packageName>
<copyRuntimeSources>true</copyRuntimeSources> <!-- This is the default value for 1.x plugin versions -->
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Remember that if you decide not to copy the runtime classes, com.graphql-java-generator:graphql-java-client-runtime:2.0, or an equivalent dependency of you own must be somehow included in your classpath. To do this, the plugin provide the graphql-java-client-dependencies
pom dependency. You can use it this way:
For Maven projects:
<project ...>
...
<dependencies>
...
<dependency>
<groupId>com.graphql-java-generator</groupId>
<artifactId>graphql-java-client-dependencies</artifactId>
<type>pom</type>
<version>2.8</version>
</dependency>
...
</dependencies>
...
</project>
For gradle projects:
dependencies {
...
// The graphql-java-client-dependencies module agregates all dependencies for the generated code
implementation "com.graphql-java-generator:graphql-java-client-dependencies:2.8"
...
}
Creating a first app (non spring)
Connect to more than one GraphQL servers
Easily execute GraphQL requests with GraphQL Repositories
Access to an OAuth2 GraphQL server
How to personalize the client app
Howto personalize the generated code
Client migration from 1.x to 2.x
Implement an OAuth2 GraphQL server
Howto personalize the generated code
Server migration from 1.x to 2.x