GraphQL API for an e-commerce store built with Go, gqlgen, PostgreSQL, and Redis.
- Product CRUD with cursor-based pagination
- Order management with transactional item creation
- JWT authentication (register / login)
- DataLoader for batched product lookups
- Redis caching on product queries
- Input validation
- Go 1.24
- gqlgen for GraphQL code generation
- pgx/v5 for PostgreSQL
- go-redis/v9 for caching
- dataloadgen for N+1 prevention
- golang-jwt for auth
- testcontainers-go for integration tests
# start postgres and redis
docker compose up -d
# run the server
go run ./cmd/serverServer starts on http://localhost:8080 with the GraphQL playground.
| Variable | Default | Description |
|---|---|---|
PORT |
8080 |
Server port |
DATABASE_URL |
postgres://store:store@localhost:5432/graphql_store?sslmode=disable |
Postgres DSN |
REDIS_URL |
localhost:6379 |
Redis address |
JWT_SECRET |
dev-secret-change-me |
JWT signing secret |
# needs Docker for testcontainers
go test ./...cmd/server/ main entrypoint
graph/
schema/ GraphQL schema files
model/ Go models (custom + generated)
resolver/ resolver implementations
internal/
auth/ JWT generation, validation, middleware
cache/ Redis product cache
db/ database connection and migrations
loader/ DataLoader for batched queries
store/ data access layer
testutil/ test helpers (testcontainers)
docker build -t graphql-store .
docker run -p 8080:8080 \
-e DATABASE_URL=postgres://... \
-e REDIS_URL=redis:6379 \
-e JWT_SECRET=your-secret \
graphql-store