I'm excited to release GQLSchemaGen v1.0.0 - a code-first GraphQL schema generator for Go that eliminates the tedious work of manually maintaining .graphqls files.
The Problem
If you've built GraphQL APIs in Go, you know the pain:
- Write Go structs for your models
- Manually create matching GraphQL schemas
- Keep them in sync as your API evolves
- Repeat for types, inputs, and enums
One missed update and your schema is out of sync. π
The Solution
GQLSchemaGen generates GraphQL schemas directly from your Go code using simple annotations:
// @gqlType
type User struct {
ID string `gql:"id,type:ID"`
Name string `gql:"name"`
Email string `gql:"email"`
CreatedAt time.Time `gql:"createdAt,ro"` // Read-only
}
Run gqlschemagen generate and get:
type User @goModel(model: "your-module.User") {
id: ID!
name: String!
email: String!
createdAt: String!
}
Features
π― Advanced Field Control - Mark fields as read-only, write-only, or conditionally included
𧬠Generics Support - Works with Go 1.18+ generic types seamlessly
π Auto-Discovery - Automatically generates schemas for referenced types
π§ Scalar Mappings - Map uuid.UUID β ID, time.Time β DateTime globally
ποΈ Namespace Organization - Keep large schemas organized
βοΈ gqlgen Integration - Generates @goModel and @goField directives
Real-World Example
Generate multiple GraphQL types from a single Go struct:
// @gqlType(name:"User")
// @gqlType(name:"PublicUser", ignoreAll:"true")
// @gqlInput(name:"CreateUserInput")
// @gqlInput(name:"UpdateUserInput")
type User struct {
ID string `gql:"id,type:ID,ro"`
Name string `gql:"name,include:*"`
Email string `gql:"email,include:User"` // Only in User type
Password string `gql:"password,wo"` // Write-only
}
Generated schema:
type User @goModel(model: "your-module.User") {
id: ID!
name: String!
email: String!
# Password excluded (write-only)
}
type PublicUser @goModel(model: "your-module.User") {
id: ID!
name: String!
# Email excluded (not in include list)
# Password excluded (write-only)
}
input CreateUserInput {
id: ID!
name: String!
# Email excluded (not in include list)
password: String!
}
input UpdateUserInput {
id: ID!
name: String!
# Email excluded (not in include list)
password: String!
}
One Go struct, 4 different GraphQL definitions with precise field control!
Get Started
# Install
go install github.com/pablor21/gqlschemagen@latest
# Initialize config
gqlschemagen init
# Generate schemas
gqlschemagen generate --gqlgen
Learn More
π Full Documentation
π» GitHub Repository
π VS Code Extension
Built for the Go and GraphQL communities. Contributions welcome! π
Top comments (0)