Choosing a Golang Library for GraphQL: A Comparison of Gqlgen, Gophers, and GraphQL-Go

Kacper Bąk
2 min readMar 1, 2023
Photo by Maxim Hopman on Unsplash

GraphQL is a query language for APIs that allows clients to request only the data they need, making it a powerful alternative to REST APIs. When building a GraphQL API using Golang, I found several libraries to choose from. In this article, I will compare three popular libraries: Gqlgen, Gophers, and GraphQL-Go.

First, it is worth noting that Thunder, which used to be a popular choice for building GraphQL APIs in Golang, is no longer supported. Therefore, I will focus on the three remaining libraries.

GraphQL-Go is a library that allows a “code-first” approach to defining GraphQL schemas, where the schema is defined in the code itself. While this approach has its advantages, such as type safety and easy validation, it also has some disadvantages. For example, there is no automatic client-side code generation, which can be a drawback in larger projects.

Gophers, on the other hand, is based on a “schema-first” approach, where the schema is defined in a separate file. While this approach may be more familiar to developers with GraphQL roots, it can lead to type security and validation issues.

Finally, we have Gqlgen, which in my opinion offers the best solution at this point. It allows a schema-first approach to defining GraphQL schemas, but also provides automatic code generation on both the server and client sides. This feature can save developers time and ensure that code is always up-to-date with the schema.

In addition to automatic code generation, Gqlgen offers many other features that make it a popular choice for building GraphQL APIs in Golang. For example, it has a feature-rich plugin system that allows developers to easily add functionality to the server. It also provides a built-in subscription system and supports batch querying, making it an effective choice for large-scale applications.

In terms of performance, a benchmark conducted by Appleboy showed that Gqlgen is the fastest of the three libraries. In terms of popularity, Gqlgen has about 8700 stars on GitHub at the time of writing this article, while Gophers has about 4400 stars.

Overall, Gqlgen seems to be the best choice for building GraphQL APIs in Golang. Its combination of schema-first approach with automatic code generation, rich plugin system, and excellent performance make it a top contender. In addition, Gqlgen makes it easy to define multiple schemas, which can be beneficial for large applications where multiple teams are working on different parts of the system.

In conclusion, while all three libraries have their pros and cons, Gqlgen offers the most comprehensive set of features for building GraphQL APIs in Golang.