cgapp logo
Book and Author information GraphQL API

A GraphQL server using backend (Golang) database (Postgres) containerised with (Docker)!

go version GraphQL 

📖 Problem

Build a simple graphql server with any database you prefer ( in-memory map[string]interface{} will do just fine ) that can perform this simple task. Finding books of all the authors and vice versa.

⚡️ Quick start

Using docker
     $ go test ./...  # run from root of the project directory 
     $ docker-compose down --volume # to make sure to remove shared volume
     $ docker-compose up --build --force-recreate # here --force-recreate is optional

🔔 NoteIf you interested to run it from locally without Docker please ensure database and .env properly configured

  • go run /cmd/app/main.go

Example .env file

GIN_PORT=8080
GIN_MODE=debug
DB_HOST=localhost
DB_PORT=5432
DB_USER=test
DB_PASSWORD=test
DB_NAME=test

✍️ Populate demo data

for populating demo data please visit localhost:port/load-data

🤾‍♂️ Let's visit localhost:port and expolre my graphql api

📋 Folder Structure

book-info-graphql
├── build
│    ├── Dockerfile
│    ├── init.sql
├── cmd
│    ├── app
│    │    ├── config
│    │    │  └── loader.go
│    │    └── main.go
├── graph
│    ├── ***                  - All graph related code along with auto generated code
├── internal
│    └── app
│         ├── adapter         - Outer layer. All framework and external database and middlewares related code 
│         ├── application     - Middle layer. Usecase or buniness logic relaed code
│         │    └── usecase
│         └── domain          - Inner layer. Domain, interface and factory related code
│              ├── interface
│              └── factory
└── .env

❓ GraphQl query

A test image

# For Getting author data
query{
    authors(name: "Hasan"){
        name, books{
            id, title
        }
    }
}
# For getting books data

query{
    books{
        id, title, authors{
            id, name
        }
    }
}