Looking for most powerful GraphQL Framework: GQL Java, DGS, Apollo, or GQLGen

In-depth comparison of four popular GraphQL frameworks

Bayu Aji Kurniawan
Kitalulus Engineering
4 min readSep 19, 2022

--

https://res.cloudinary.com/practicaldev/image/fetch/s--_kE6s9R1--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5fwy682370ht9ezffls4.png
https://dev.to/danicodes01/graphicql-324f

Java, NodeJs, and Go are some of the most popular programming languages in Back-end development. Here in KitaLulus, we use all three to serve various APIs (REST) on the BE side. But for the NodeJs, we use Apollo to serve GraphQL instead of REST.

Now let’s get through a comparison between GraphQL Java, DGS Java, Apollo GraphQL and Gqlgen Go.

Comparison

GQL Java

GQL java is simple and easy to implement. However, the common method to create schema in Gql Java is to write schema first then write the runtime code that matches this schema to build GraphQLSchema object

This means that our schemas will have two sources of truth. In consequence, if there is a change in the schema, we will also need to change the schema from both locations.

Furthermore, if our schemas scale to hundreds of types and have many different resolvers, it can be even more difficult to:

  • add new field, we need to make sure schema from both location is changed
  • if we have a deprecated schema we need to mark in both location
  • delete existing schema, make sure schema deleted in both location
  • fix bug in resolver code

We might be relying on our build or automation tests to catch these errors. However, this is yet another challenge we have to overcome when creating the API.

You can read more in this article:

DGS Java

DGS is built on top of GQL Java. So it has all features of GQL Java, plus a plugin for code generation.

The DGS Code Generation plugin generates code during our project’s build process based on our Domain Graph Service’s GraphQL schema file. The plugin generates the following:

  • Data types for types, input types, enums and interfaces.
  • A DgsConstants class containing the names of types and fields
  • Example data fetchers
  • A type-safe query API that represents our queries

I don’t write the implementation of Code Generation but it is documented well, https://netflix.github.io/dgs/generating-code-from-schema/

The code generation plugin in DGS tackles the two sources of truth problems.

Apollo GraphQL

Apollo GQL is also very simple. What we have to do is first, we define a schema. Then, we can resolve the data that we need to send in the resolver. In Apollo, we don’t need the codegen feature since in Javascript we can directly map the data to an object and we don’t need to generate the object first.

Gqlgen Go

Gqlgen is a Go library for building GraphQL servers.

  • gqlgen is based on a Schema first approach
  • gqlgen prioritizes Type safety
  • gqlgen enables codegen

Gqlgen can also use codegen, but instead of optional like DGS, codegen in gqlgen is more like the main features.

Gqlgen will become very difficult when implementing a nested schema. It requires us to write a custom struct or we need to specify which field of a schema needs to be resolved, which I found annoying. We will not find this kind of difficulty in other GraphQL framework mentioned in this article.

Side by side comparison of GQL Java, DSG Java, Apollo, and GQLgen Go

Conclusion

GraphQL java is simple but it has two sources of truth problems, and this precise problem has been solved by DGS using DGS’s supported codegen plugin.

DGS is similar with gqlgen in Go, but from the implementation of the framework, DGS Java is more simple. That’s because gqlgen in Go required an extra work when defining a nested schema which is what I found this annoying since we in KitaLulus will use a lot of nested schemas.

Apollo GraphQL is also simple and easy to implement and is comparable with DGS, Apollo GraphQL and DGS. Both are definitely good, simple and easy to implement.

When it comes to GraphQL federation, both framework support all features of federation 1 (one) and federation 2 (two), and it’s difficult to decide which one is better.

https://www.apollographql.com/docs/federation/supported-subgraphs/

DGS supported Federation
Apollo supported Federation

Now it’s back to our preferences when deciding whether we want to implement GraphQL using Apollo or DGS. Since Apollo is used in JavaSript and DGS is used in Java/Kotlin.

I prefer to write GraphQL code using DGS Java over Apollo because eventually, we will resolve GQL schema with data from a few databases, and mostly we use a relational database and Java has some great frameworks that make working with databases pretty easy and intuitive (ORM Tools — Object to Relational Mapping).

--

--