Schema Personalization (for server mode)

The generated code embeds Java annotations that should suit most of your needs. But you can have special needs.

The current version is stable. But we need your feedback to improve it, according to your needs.

With the schema personalization, you can:

The JSON schema for the schema personalization JSON is available in git. This define the format that your configuration file must respect.

You’ll find samples files in the test resources of the plugin project. Of course, the xxx_KO_xxx files are bad samples… ;-)

Currently, the annotations used in the client mode can not be changed. These annotations are mainly Jackson’s annotation to allow JSON serialization and deserialization of the POJO, to map with the GraphQL requests and responses.

So this applies only when in server mode. In this case, the plugin generates classes and attribute annotations in this way:

To configure the way the code is generated, you’ll have to define a json file that respects the personalization JSON schema.

Then you declare where to find this json file in the pom file, by using the schemaPersonalizationFile tag:

<project ...>
...

	<build>
		<plugins>
...
			<plugin>
				<groupId>com.graphql-java-generator</groupId>
				<artifactId>graphql-maven-plugin</artifactId>
				<version>1.12.3</version>
				<executions>
					<execution>
						<goals>
							<goal>graphql</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<mode>client</mode>
					<packageName>my.target.package</packageName>
					<schemaPersonalizationFile>src/main/graphql/forum_personalization.json</schemaPersonalizationFile>
				</configuration>
			</plugin>
...
		</plugins>
	</build>
...
</project>

In this sample, the personalization file is stored in a dedicated folder, instead of the resource. It avoids to add this compile time file into the packed artefact.

But you can keep this file in the resource file, if you want to avoid creating an additional folder, that perhaps you’ll forget. That’s up to you…

You’ll find below some samples of what’s possible, and how to do it. Of course, you can mix all these possibilities in one json file.

If you want to add an annotation to a generated Java POJO:

{
	"entityPersonalizations": [
		{
			"name": "myEntity",
			"addAnnotation": "@my.annotation.package.Annotation"
		}
	]
}

If you want to set the annotation to a generated Java POJO, and replace all annotations coming from the plugin:

{
	"entityPersonalizations": [
		{
			"name": "myEntity",
			"replaceAnnotation": "@my.annotation.package.MyAnnotation @my.annotation.package.MyOtherAnnotation",
		}
	]
}

If you want to add fields to an entity:

{
	"entityPersonalizations": [
		{
			"name": "MyEntity",
			"newFields": [
				{
					"name": "field1.1",
					"type": "type1.1",
					"id": true,
					"list": true,
					"mandatory": true,
					"addAnnotation": "addAnnotation1.1",
					"replaceAnnotation": "replaceAnnotation1.1"
				},
				{
					"name": "field1.2",
					"type": "type1.2",
					"id": false,
					"list": false,
					"mandatory": false,
					"addAnnotation": "addAnnotation1.2",
					"replaceAnnotation": "replaceAnnotation1.2"
				}
			]
		}
	]
}

If you want to personalize some fields:

{
	"entityPersonalizations": [
		{
			"name": "entity1",
			"fieldPersonalizations": [
				{
					"name": "field1.3",
					"type": "type1.3",
					"id": true,
					"list": true,
					"mandatory": true,
					"addAnnotation": "@my.annotation.package.Annotation1 @my.annotation.package.Annotation2",
					"replaceAnnotation": "replaceAnnotation1.3"
				},
				{
					"name": "field2",
					"replaceAnnotation": "@my.annotation.package.Annotation3 @my.annotation.package.Annotation4"
				}
			]
		}
	]
}