graphql-java is one of the most popular JVM based GraphQL implemenations. GraphQL Kotlin is
built on top of
grahpql-java as it can be easily extended with additional functionality and this implementation
has been used and tested by many users.
The most common way to create the schema in
graphql-java is to first manually write the SDL file:
Then write the runtime code that matches this schema to build the
This means that there are two sources of truth for your schema and changes in either have to be reflected in both locations. As your schema scales to hundreds of types and many different resolvers, it can get more difficult to track what code needs to be changed if you want to add a new field, deprecate or delete an existing one, or fix a bug in the resolver code.
These errors will hopefully be caught by your build or automated tests, but it is another layer your have to be worried about when creating your API.
graphql-kotlin-schema-generator aims to simplify this process by using Kotlin reflection to generate the schema for you.
All you need to do is write your schema code in a Kotlin class with public functions or properties.
This makes changes in code directly reflect to your schema and you can still produce the
GraphQLSchema to print and export an SDL file.
DGS is a GraphQL server framework for Spring Boot. It works with both Java and Kotlin.
DGS is also built on top of
graphql-java and implements many similar features to
graphql-kotlin and graphql-java-kickstart/graphql-spring-boot.
- Auto-configuration of server routes and request handling
- Auto-wiring of data fetchers (resolvers) to the
- Apollo Federation support
- Subscriptions support
- Client schema-code generation
While both libraries do very similar things, there are some minor differences which may serve different usecases better. As with open source library, you can compare and use the right tool for the job.
- Support for a SDL-First (Schema-First) approach
- Ability to autogenerate code stubs from the schema
- Includes JsonPath testing library
- Build on top of Spring MVC
- Supports code-first approach (generates schema from source code - does not require duplicate implementation of data fetchers, schema classes, and SDL files)
- Abstract server logic can be used in any framework, e.g. Ktor
- Reference server implementation build on top of Spring Webflux for a reactive server stack
- Simple nesting of data fetchers
- Client code generation for Ktor and Spring
- Client plugin support for both Maven and Gradle