go-graphql

Design and implement schema-first GraphQL servers in Go with gqlgen or graph-gophers.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-graphql-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-graphql
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/go/go-graphql
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-graphql-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building GraphQL servers in Go involves recurring pitfalls: N+1 query storms from child resolvers, leaked subscription goroutines, exposed internal errors, and uncapped query complexity. This Skill provides a schema-first discipline covering library selection, SDL design, thin resolvers, per-request DataLoaders, auth, error mapping, subscriptions, and production limits. ## Core Features & Use Cases - Library Selection & Schema Design: Choose between gqlgen (codegen, federation, large schemas) and graph-gophers/graphql-go (reflection, small schemas), then design SDL with deliberate nullability, ID scalars, cursor pagination, and mutation payload envelopes. - Performance & Safety Patterns: Implement per-request DataLoaders to eliminate N+1 queries, two-layer auth with schema directives, error presenters that hide internals, and complexity limits with gated introspection. - Review & Audit Workflow: Audit existing servers for N+1 resolvers, global DataLoader scope, subscription goroutine leaks, and missing complexity caps. - Use Case: You are building a Go GraphQL API where a User.posts field fires one SQL query per user. Apply this Skill to wire a per-request DataLoader in HTTP middleware, mark the field resolver: true in gqlgen.yml, and coalesce all loads into a single batch query. ## Quick Start Ask the assistant to design a GraphQL schema and implement thin resolvers with per-request DataLoaders for a Go service using gqlgen.

Frequently Asked Questions about go-graphql

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 queries in Go GraphQL resolvers?

Use a DataLoader created per request in HTTP middleware to batch child-resolver loads into a single query. In gqlgen, mark the field resolver: true in gqlgen.yml and load through dataloadgen or graph-gophers/dataloader instead of querying the database directly.

gqlgen vs graph-gophers graphql-go: which should I use?

Choose gqlgen for large schemas (100+ types), Apollo Federation, compile-time type safety, and generated resolver stubs. Choose graph-gophers/graphql-go for small or medium schemas, no build step, and faster iteration with reflection-based binding.

Why does graph-gophers reject my Int field resolver?

graph-gophers/graphql-go requires int32 for the GraphQL Int scalar, not int. Using int causes a parse-time type mismatch error. Use int32 for Int and float64 for Float in resolver signatures.

How do I prevent GraphQL subscription goroutine leaks in Go?

Subscribe once before spawning the goroutine, defer close(ch) so iteration stops, and select on ctx.Done() to exit when the client disconnects. Without this, each disconnected client leaves a goroutine running forever.

Should DataLoaders be global or per-request in GraphQL servers?

DataLoaders must be created per request in HTTP middleware, never globally. A global loader caches across requests, serving stale data and potentially leaking one user's data to another.

How do I limit GraphQL query complexity in gqlgen?

Wire extension.FixedComplexityLimit(200) on the server to cap query cost, gate extension.Introspection behind a non-production ENV check, and consider AutomaticPersistedQuery to reject arbitrary query strings in production.