A GraphQL server implementation built with Go, PostgreSQL, and github.com/graphql-go/graphql.
GoferQL API is a GraphQL server that provides a flexible API for managing posts, comments, users, categories, and tags. It uses SQLC for type-safe database operations and the graphql-go package for GraphQL implementation.
- Go
- PostgreSQL
- github.com/graphql-go/graphql
- SQLC
.
├── cmd/
│ ├── seed/
│ │ └── main.go // generate dummy data
│ └── server/
│ └── main.go // server handler
├── config/
│ └── config.go // server config
├── graphql/
│ ├── mutations/ // mutations
│ │ ├── category.go
│ │ ├── comment.go
│ │ ├── post.go
│ │ ├── postTag.go
│ │ ├── tag.go
│ │ └── user.go
│ ├── queries/ //queries
│ │ ├── category.go
│ │ ├── comment.go
│ │ ├── post.go
│ │ ├── tag.go
│ │ └── user.go
│ ├── resolvers/ // resolvers
│ │ ├── category.go
│ │ ├── comment.go
│ │ ├── post.go
│ │ ├── postTag.go
│ │ ├── tag.go
│ │ └── user.go
│ ├── types/ // types
│ │ └── types.go
│ └── utils/ // schema
│ └── schema.go
├── internal/
│ └── db/ // database + sqlc
│ ├── migrations/
│ ├── queries/
│ └── sqlc/
├── .env
├── go.mod
├── go.sum
├── Makefile // all project commands
├── README.md
├── schema.graphql // graphql schema
└── sqlc.yaml // sqlc config
- Clone the repository:
git clone https://github.com/AbdelilahOu/GoferQl-api
cd GoferQl-api
- Install dependencies:
go mod download
- Set up the database:
# Create database container
make containerup
# Create PostgreSQL database
make createdb
# Run migrations
make migrations-up
- seed database:
make seed
- Configure environment variables:
cp .env.example .env
# Edit .env with your configuration
- Run the server:
make server
The API supports the following main types:
- User (username, email, bio)
- Post (title, content, status)
- Comment (content, nested replies)
- Category (name, description)
- Tag (name)
Fetch posts with author and comments:
query {
posts(limit: 10, offset: 0) {
id
title
content
user {
username
}
comments {
content
user {
username
}
}
}
}
Create a new post:
mutation {
createPost(
title: "Hello World"
content: "This is my first post"
status: "published"
userId: "user-id"
categoryId: "category-id"
) {
id
title
createdAt
}
}