gqlgen-plugin/

directory
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2025 License: MIT

README

gqlgen Plugin Example

This example demonstrates how to use gqlscanner as a gqlgen plugin.

Setup

  1. Install dependencies:
go get github.com/99designs/gqlgen
go get github.com/pablor21/gqlscanner/plugin
  1. Create a tools.go file to ensure the plugin is included:
//go:build tools
// +build tools

package tools

import (
    _ "github.com/99designs/gqlgen"
    _ "github.com/pablor21/gqlscanner/plugin"
)
  1. Run go mod tidy:
go mod tidy

Configuration

The gqlgen.yml file is configured to use the gqlscanner plugin:

plugins:
  gqlscanner:
    packages:
      - ./graph/models

This tells gqlscanner to scan the ./graph/models directory for Go structs with gql annotations.

Usage

Generate GraphQL code with gqlgen:

go run github.com/99designs/gqlgen generate

This will:

  1. gqlscanner plugin runs first: Generates GraphQL schemas from Go structs in graph/models/
  2. gqlgen continues: Generates resolvers and types based on the schemas

Models

The graph/models/ directory contains example Go structs:

  • product.go - Product and Category types

These use the same annotation format as the CLI example.

Plugin vs CLI

Feature CLI Plugin
Usage Standalone tool Integrated with gqlgen
When to run Manually or in build scripts Automatically during gqlgen generate
Configuration gqlscanner.yml or flags gqlgen.yml plugins section
Best for Independent schema generation Full gqlgen workflow

Workflow

  1. Define Go structs with gql annotations in graph/models/
  2. Run gqlgen generate
  3. gqlscanner generates schemas to graph/schema/
  4. gqlgen generates resolvers and types
  5. Implement resolver logic

Example Output

After running gqlgen generate, you'll have:

graph/
├── generated.go          # gqlgen generated code
├── model/
│   └── models_gen.go     # Generated GraphQL models
├── models/
│   └── product.go        # Your Go structs (source)
├── schema/
│   └── schema.graphql    # Generated by gqlscanner
└── *.resolvers.go        # Generated resolver stubs

Advanced Configuration

You can customize gqlscanner behavior in gqlgen.yml:

plugins:
  gqlscanner:
    packages:
      - ./graph/models
    # Additional config can be added here
    # (currently packages is the main config option)

For more control over schema generation, use the CLI tool separately and reference the generated schemas in gqlgen.yml.

Directories

Path Synopsis
graph

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL