This project is for building GraphQL APIs in Go (Golang) using gqlgen.
It demonstrates how to structure a GraphQL server, define schemas, resolvers, and manage data using an in-memory store.
This repository is ideal for learning:
- GraphQL fundamentals in Go
- gqlgen project structure
- Resolver patterns
- Basic API routing with
net/http
- GraphQL API built with gqlgen
- Strongly typed schema-first development
- In-memory data store (no database required)
- Clean separation of schema, resolvers, and storage
- Ready-to-extend project structure
golang-graphql-starter/
├── server.go # Application entry point
├── tools/
│ └── tools.go # gqlgen tool dependency
│
├── graph/
│ ├── resolver.go # Root resolver definitions
│ ├── schema.resolvers.go # Query & Mutation resolvers
│ ├── generated/
│ │ └── generated.go # Auto-generated GraphQL code
│ ├── model/
│ │ └── models_gen.go # Auto-generated models
│ └── store/
│ └── store.go # In-memory data store
-
server.go
- Initializes the GraphQL server
- Registers HTTP routes
- Starts the application
-
GraphQL Schema
- Defined using gqlgen (schema-first)
- Auto-generates Go models and resolvers
-
Resolvers
- Handle incoming GraphQL queries and mutations
- Interact with the in-memory store
-
Store
- Simple in-memory data storage
- Simulates database operations
Description:
Serves the GraphQL Playground UI.
Use this endpoint to:
- Explore the schema
- Execute queries and mutations
- Test the API
Description:
Main GraphQL endpoint.
All GraphQL queries and mutations are sent here.
Content-Type:
application/json
query {
users {
id
name
}
}mutation {
createUser(name: "John") {
id
name
}
}- Sets up HTTP server
- Configures gqlgen handler
- Enables GraphQL Playground
- Root resolver struct
- Injects dependencies like the store
- Implements:
- Query resolvers
- Mutation resolvers
- Contains business logic
- In-memory slice-based storage
- Functions to:
- Add records
- Fetch records
Do not edit manually
- Go 1.18+
- gqlgen installed
go mod tidy
go run server.gohttp://localhost:8080
github.com/99designs/gqlgennet/http