gqlgen is a Go library for building GraphQL servers with strong typing and generated models. You define the API in GraphQL SDL and use go generate to produce server scaffolding.
Overview
gqlgen targets developers who want to run GraphQL APIs in Go without hand-writing repetitive resolver boilerplate. The workflow is schema-first: you describe types and operations in the GraphQL Schema Definition Language, then codegen fills in models and wiring so resolvers stay type-safe and avoid generic map-based payloads.
The library emphasizes compile-time safety and generated code for routine pieces of a server. Configuration in gqlgen.yml lets you map GraphQL types to your own Go structs, force resolvers for specific fields, control concurrency for field resolution, and remap scalars such as ID to integers or strings. Directives support inline model and field hints when you want schema and Go types to stay aligned.
Getting started involves adding gqlgen as a tool dependency, initializing config, generating models, and running a small GraphQL server process. Documentation points to tutorials, real-world examples, and reference material for the APIs. The project also documents patterns for nested data, such as loading related records only when the client requests those fields.
Compared with other Go GraphQL implementations, the project invites side-by-side evaluation on its site. It focuses on codegen and schema-first development rather than being a hosted product you deploy on its own.
Key features
- Schema-first GraphQL SDL workflow
- go generate based code generation
- Strong typing without map[string]interface{}
- Custom models and explicit field resolvers
- Configurable ID scalar mapping
- Concurrent field resolvers with worker limits
- Directives for inline Go model binding
- Optional interface getter generation
Use cases
- New Go GraphQL APIs from an SDL schema
- Type-safe resolvers for production services
- Controlled loading of nested graph fields
- Remapping GraphQL ID types to Go types
- Comparing Go GraphQL server approaches