This repository contains a GraphQL server implemented in Go using gqlgen, following a schema-first approach and a clean, modular project structure.
The implementation is based on and inspired by the tutorial:
Implementation GraphQL Server With Golang
https://medium.com/@wahyubagus1910/implementation-graphql-server-with-golang-fb8f8303b4bc
- GraphQL server built with Golang
- Schema-first GraphQL using gqlgen
- Clear separation of concerns:
- Resolver layer
- Domain / DAO layer
- GraphQL Playground enabled
- Easy to extend and maintain
go-graphql/
├── cmd/app
│ ├── domain
│ │ └── dao # data access objects
│ └── resolvers # gql query/mutation resolvers
├── config # config related files
├── graph
│ ├── generated.go # generated gql code
│ └── model # GraphQL models
├── schema
│ └── schema.graphqls # GraphQL schema definitions
├── tools
│ └── tool.go # go:build tools
├── gqlgen.yml # gqlgen config
├── server.go # entrypoint
├── go.mod
└── go.sum- Go 1.18+ (recommended)
- Go modules enabled
gqlgeninstalled as a tool
git clone https://github.com/carissafarry/go-graphql.git
cd go-graphqlAdd gqlgen and other tools to your module:
go install github.com/99designs/gqlgen@v0.17.86This will download dependencies referenced both in your code and via tools.go.
go mod tidyThis reads your schema.graphqls and produces:
- GraphQL runtime code
- Models
- Resolver interfaces
gqlgen generateThe server runs at http://localhost:8080 by default. Here you can write GraphQL queries and mutations interactively.
go run .The schema lives in:
schema/schema.graphqlsExample query:
query {
users {
id
name
}
}• gqlgen Documentation: https://gqlgen.com/
• Tutorial: https://medium.com/@wahyubagus1910/implementation-graphql-server-with-golang-fb8f8303b4bc