Skip to content

gqlgen

A Go library that generates GraphQL server code from a schema you write.

Stars
10.8k
Forks
1.3k
Licence
MIT
Language
Go
Last update
8 days ago
Type
Library

What it is

gqlgen is a Go library for building GraphQL servers. You describe your API in the GraphQL Schema Definition Language, and gqlgen generates the Go code for the types and resolver functions, so you mainly write the logic that fetches the data. It is aimed at Go developers who want type-safe code rather than loosely typed maps.

  • Scaffold a GraphQL server in a new Go module with the go tool gqlgen init command
  • Define types and queries in a schema file and generate matching Go models and resolver stubs
  • Avoid N+1 style over-fetching by writing custom models or resolvers for nested fields such as a user's friends
  • Change the Go type backing the GraphQL ID type, for example to int or uint

Great for

  • Go developers building a new GraphQL API
  • Teams that prefer defining the schema first and generating code from it
  • Projects that need typed models instead of map[string]interface{}
  • Developers who want to control which nested fields are fetched, using custom models or explicit resolvers

Not ideal for

  • Developers not using Go, since the library is written for Go and the README shows only Go code
  • Projects that need a GraphQL server in another language
  • Anyone who wants a fully finished application out of the box, since gqlgen generates a server skeleton you still have to fill in
Step-by-step guide: how to use gqlgenInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Go (version not specified in the README excerpt)

    Create a new Go module

    mkdir example && cd example && go mod init example

    Add gqlgen as a tool dependency

    go get -tool github.com/99designs/gqlgen

    Initialise gqlgen config and generate models

    go tool gqlgen init
  2. 2

    Run it

    • Run the commands above to create a module and add gqlgen
    • Run go tool gqlgen init to create the config and generate starter code
    • Start the server with go run server.go
  3. 3

    Get the most out of it

    • Read the getting-started tutorial at gqlgen.com/getting-started for a full walkthrough
    • Use the worker_limit config attribute to control how many field resolvers run concurrently
    • Use @goField directives or the models section of gqlgen.yml to control which fields get resolvers
    • Browse the _examples folder in the repository for real-world applications

Downloads

Strengths

  • Schema-first workflow: the GraphQL schema is the source of truth and Go code is generated from it
  • Generated code is typed, which the README emphasizes as avoiding loosely typed maps
  • Documented getting-started tutorial, reference docs, and example projects

Trade-offs

  • You must learn both GraphQL schema concepts and gqlgen's configuration (gqlgen.yml or directives) to customize behavior
  • The README notes some interface getters can't cover every case, such as Relay-style connections, so you may need the omit_getters option
  • The README is truncated here, so details of subscriptions and dataloader support are not confirmed from the text provided

How it compares

ProjectStarsTypeLevelUpdatedBest for
gqlgen (this)10.8kLibraryintermediate8 days agoGo developers building a new GraphQL API
graphql10.1kLibraryintermediate5 months agoGo developers who want to expose a GraphQL API from a Go service
dataloader13.4kLibraryintermediate19 days agoNode.js developers building a GraphQL server with graphql-js
pentagi33kAI model / agentadvanced14 days agoSecurity engineers and penetration testers who want an autonomous assistant on their own servers
graphql-code-generator11.3kDev toolintermediate4 days agoFrontend developers who want typed code for GraphQL queries
go-zero33.4kLibraryintermediate5 days agoGo developers building REST APIs or microservices

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.