Generator for Immutable Java classes from GraphQL Schema.
This project assists you in creating either a GraphQL server or client in Java. You can configure it to create either Lombok or Immutables or Groovy based DTOs.
Clone the project and run ./gradlew build
This should build the project using Gradle.
Then run:
java -jar build/libs/graphql-java-immutables-0.0.1.jar
You get a warning like Missing 'generator.file' property!
Set it like this:
export GENERATOR_FILE=your_file.graphql
Where your_file.graphql
points to a valid GraphQL schema.
All the available configuration properties and the defaults are the following:
File file
OutputType outputType = IMMUTABLES or LOMBOK_JAVA or GROOVY
String fileComment = ''
String javadocComment = ''
boolean includeJacksonJson = true
String classnameSuffix = 'DTO'
String classnamePrefix = ''
String packageName = 'org.example'
Each of these should be set using environment variable. For example, to set the package name:
export GENERATOR_PACKAGENAME=com.your_package
Files are put under the src/main/java
directory.
For example, given the following GraphQL file:
scalar Date
scalar DateTime
type Query {
user(name: String): User
}
type User {
created: Date!
id: ID!
name: String!
type: UserType!
events: [Event!]
}
type Event {
when: DateTime!
type: String!
comments: String
}
enum UserType {
USER
ADMIN
}
It will create a User class, Event class, and UserType enum.