Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gqlgen

> 后端框架
Open source

go generate based graphql server library

10.7K stars0 likes1 views
WebsiteGitHub

About

go generate based graphql server library

gqlgen

What is gqlgen?

gqlgen is a Go library for building GraphQL servers without any fuss.

  • gqlgen is based on a Schema first approach — You get to Define your API using the GraphQL Schema Definition Language.
  • gqlgen prioritizes Type safety — You should never see map[string]interface{} here.
  • gqlgen enables Codegen — We generate the boring bits, so you can focus on building your app quickly.

Still not convinced enough to use gqlgen? Compare gqlgen with other Go graphql implementations

Quick start

  1. Initialise a new go module
bash
mkdir example
cd example
go mod init example
  1. Add github.com/99designs/gqlgen to your project, as a tool dependency
bash
go get -tool github.com/99designs/gqlgen
  1. Initialise gqlgen config and generate models
bash
go tool gqlgen init
  1. Start the graphql server
bash
go run server.go

More help to get started:

  • Getting started tutorial - a comprehensive guide to help you get started
  • Real-world examples show how to create GraphQL applications
  • Reference docs for the APIs

Reporting Issues

If you think you've found a bug, or something isn't behaving the way you think it should, please raise an issue on GitHub.

Contributing

We welcome contributions, Read our Contribution Guidelines to learn more about contributing to gqlgen

Frequently asked questions

How do I prevent fetching child objects that might not be used?

When you have nested or recursive schema like this:

graphql
type User {
	id: ID!
	name: String!
	friends: [User!]!
}

You need to tell gqlgen that it should only fetch friends if the user requested it. There are two ways to do this:

Using Custom Models

Write a custom model that omits the friends field:

go
type User struct {
  ID int
  Name string
}

And reference the model in gqlgen.yml:

yaml
# gqlgen.yml
models:
  User:
    model: github.com/you/pkg/model.User # go import path to the User struct above

Using Explicit Resolvers

If you want to keep using the generated model, mark the field as requiring a resolver explicitly in gqlgen.yml like this:

yaml
# gqlgen.yml
models:
  User:
    fields:
      friends:
        resolver: true # force a resolver to be generated

After doing either of the above and running generate we will need to provide a resolver for friends:

go
func (r *userResolver) Friends(ctx context.Context, obj *User) ([]*User, error) {
  // select * from user where friendid = obj.ID
  return friends,  nil
}

You can also use inline config with directives to achieve the same result

…

The field resolvers will be executed concurrently in separate goroutines. The degree of concurrency can be customized with the worker_limit configuration attribute.

Can I change the type of the ID from type String to Type Int?

Yes! You can by remapping it in config as seen below:

yaml
models:
  ID: # The GraphQL type ID is backed by
    model:
      - github.com/99designs/gqlgen/graphql.IntID # a go integer
      - github.com/99designs/gqlgen/graphql.ID # or a go string
      - github.com/99designs/gqlgen/graphql.UintID # or a go uint

This means gqlgen will be able to automatically bind to strings or ints for models you have written yourself, but the first model in this list is used as the default type and it will always be used when:

  • Generating models based on schema
  • As arguments in resolvers

There isn't any way around this, gqlgen has no way to know what you want in a given context.

Why do my interfaces have getters? Can I disable these?

These were added in v0.17.14 to allow accessing common interface fields without casting to a concrete type. However, certain fields, like Relay-style Connections, cannot be implemented with simple getters.

If you'd prefer to not have getters generated in your interfaces, you can add the following in your gqlgen.yml:

yaml
# gqlgen.yml
omit_getters: true

Other Resources

  • Christopher Biscardi @ Gophercon UK 2018
  • Introducing gqlgen: a GraphQL Server Generator for Go
  • Dive into GraphQL by Iván Corrales Solera
  • Sample Project built on gqlgen with Postgres by Oleg Shalygin
  • Hackernews GraphQL Server with gqlgen by Shayegan Hooshyari

Issues· 393 open

View all issuesOpen on GitHub
  • #3912

    Auto-fill missing mandatory field OR Give error when missing mandatory field

    Updated Sep 23, 2026
  • #4321

    Feature request: @disableConcurrency directive to opt a field/object out of per-field goroutines

    Updated Sep 10, 2026
  • #3906

    Crazy plugin idea

    help wantedproposalUpdated Sep 4, 2026
  • #4304

    Generating an `Any` field in go1.27 becomes `interface{}` instead of `any` in the resolver code.

    Updated Sep 2, 2026
  • #4294

    NewScalarFieldContext's fast path allocates an error on every field resolution, unconditionally

    Updated Aug 24, 2026
  • #4295

    Support the HTTP QUERY method (RFC 10008)

    Updated Aug 21, 2026
  • #3560

    Break generated exec code into subpackages?

    Updated Jul 30, 2026
  • #4041

    Incremental Code Generation for Large Schemas

    enhancementproposalUpdated Jul 29, 2026
  • #4140

    Federation: Multi entity resolver interactions with @requires

    help wantedfederationbatchUpdated Jul 17, 2026
  • #4269

    Allow configuring worker_limit at runtime (server startup and per-request)

    Updated Jul 15, 2026

> Tags

Gocodegendataloadergogenerategolang

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架