GQLSchemaGen CLI Reference

The GQLSchemaGen CLI lets you generate GraphQL schemas directly from your Go structs. This page covers all commands, flags, and options to help you get the most out of the tool.


Quick Start

Initialize Configuration

Create a default configuration file:

$ gqlschemagen init

Options:

$ 

gqlschemagen init --output custom-config.yml gqlschemagen init -o custom-config.yml gqlschemagen init --force # Overwrite existing file gqlschemagen init -f


Generate Schema

Basic usage (requires --pkg flag):

$ 

gqlschemagen generate -p ./internal/domain

With output directory:

$ 

gqlschemagen generate -p ./internal/domain -o ./graph/schema

Using a configuration file:

$ 

Create config first

$ 

gqlschemagen init

$ 

Then generate (uses gqlschemagen.yml by default)

$ 

gqlschemagen generate

$ 

Or specify a custom config

$ 

gqlschemagen generate -c custom-config.yml

Watch mode (auto-regenerate on changes):

$ 

gqlschemagen generate -p ./internal/domain --watch gqlschemagen generate -w


Get Help

View available commands and usage:

$ 

gqlschemagen --help gqlschemagen help

$ 

Show help for a specific command

$ 

gqlschemagen generate --help gqlschemagen init --help


Commands

gqlschemagen init

Create a default configuration file.

Usage:

Options:

FlagShortDescriptionDefault
--output-oOutput file pathgqlschemagen.yml
--force-fOverwrite existing filefalse

Examples:


gqlschemagen generate

Generate GraphQL schema from Go structs.

Usage:

Required Flags:

FlagShortDescription
--pkg-pRoot package directory to scan

Optional Flags:

FlagShortTypeDescriptionDefault
--config-cstringPath to config filegqlschemagen.yml
--watch-wboolWatch for changes and regeneratefalse
--out-ostringOutput directory or file pathgraph/schema
--output-file-name--ofnstringOutput file name for single strategygqlschemagen.graphqls
--output-file-extensionstringFile extension for multiple/package strategies.graphqls
--strategy-sstringGeneration strategy: single, multiple, or packagesingle
--skip-existingboolSkip generating files that already existfalse
--field-case--casestringField name case: camel, snake, pascal, original, nonecamel
--use-json-tagboolUse json tag for field namestrue
--use-gqlgen-directives--gqlgenboolGenerate @goModel and @goField directivesfalse
--model-path-mstringBase path for @goModel directive``
--strip-prefixstringComma-separated prefixes to strip from type names``
--strip-suffixstringComma-separated suffixes to strip from type names``
--add-type-prefixstringPrefix to add to GraphQL type names``
--add-type-suffixstringSuffix to add to GraphQL type names``
--add-input-prefixstringPrefix to add to GraphQL input names``
--add-input-suffixstringSuffix to add to GraphQL input names``
--schema-file-namestringSchema file name pattern for multiple mode{model_name}.graphqls
--include-empty-typesboolInclude types with no fieldsfalse

Using Command Line Flags

All flags support long (--flag) and short (-f) formats where available.


Usage Examples

Single File Strategy

Generate all types in one schema file:

$ 

gqlschemagen generate -p ./internal/models -o ./graph/schema/schema.graphqls -s single

Multiple Files Strategy

Generate one file per type:

$ 

gqlschemagen generate -p ./internal/models -o ./graph/schema -s multiple --schema-file-name "{model_name}.graphqls"

Result:

Package Strategy

Generate one file per Go package:

$ 

gqlschemagen generate -p ./internal -o ./graph/schema -s package

Result:

With gqlgen Directives

Generate schema with gqlgen integration:

$ 

gqlschemagen generate -p ./internal/models -o ./graph/schema --gqlgen -m github.com/myapp/models

Generated:

Type Name Manipulation

Strip prefixes and add suffixes:

$ 

gqlschemagen generate -p ./internal/models --strip-prefix DB,Api --strip-suffix DTO,Entity --add-input-suffix Input

Example:

  • DBUserUser
  • ApiProductProduct
  • OrderDTOOrder
  • CreateUserDTO input → CreateUserInput

Field Case Transformation

Use snake_case for GraphQL fields:

$ 

gqlschemagen generate -p ./internal/models --case snake

Go struct:

Generated GraphQL:

Watch Mode

Auto-regenerate on file changes:

$ 

gqlschemagen generate -p ./internal/models -o ./graph/schema --watch


Configuration File vs CLI Flags

You can use either a YAML configuration file or CLI flags. CLI flags always override config file values.

Using Configuration File

$ 

Create config

$ 

gqlschemagen init

$ 

Generate using config

$ 

gqlschemagen generate

Mixing Config and Flags

$ 

Use config but override output path

$ 

gqlschemagen generate -o ./custom/output

$ 

Use custom config file

$ 

gqlschemagen generate -c my-config.yml

$ 

Override multiple settings

$ 

gqlschemagen generate -c my-config.yml -s multiple --gqlgen


Common Workflows

Development Setup

CI/CD Integration

Go Generate Integration

Add to your Go file:

Then run: