master v0.17.31 v0.17.30 v0.17.29 v0.17.28 v0.17.27 v0.17.26 v0.17.25 v0.17.24 v0.17.23 v0.17.22 v0.17.21 v0.17.20 v0.17.19 v0.17.18 v0.17.17 v0.17.16 v0.17.15 v0.17.14 v0.17.13 v0.17.12


How to write plugins for gqlgen
You are looking at the docs for the unreleased master branch. The latest version is v0.17.31.

Plugins provide a way to hook into the gqlgen code generation lifecycle. In order to use anything other than the default plugins you will need to create your own entrypoint:

Using a plugin

To use a plugin during code generation, you need to create a new entry point. Create generate.go in the same folder as resolver.go with the following code:

// go:build ignore

package main

import (


func main() {
	cfg, err := config.LoadConfigFromDefaultLocations()
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to load config", err.Error())

	err = api.Generate(cfg,
		api.AddPlugin(yourplugin.New()), // This is the magic line
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())

In resolver.go, add //go:generate go run generate.go. Now you can run go generate ./... instead of go run generate to generate the code.

Writing a plugin

There are currently only two hooks:

Take a look at plugin.go for the full list of available hooks. These are likely to change with each release.