/books-api

GraphQL Books API

Primary LanguageJavaMIT LicenseMIT

books-api-logo

Build Status Code coverage Slack

GraphQL books API made using Spring Boot and DGS. This is a sibling project of the Book Project.

Setup

Prerequisites:

  • JDK 11 or higher
  • Configure Lombok
  • PostgreSQL 12 or (better) Docker
    • For Linux users, install docker-compose
    • For macOS and Windows users, install Docker Desktop

Recommended IntelliJ plugin: JS GraphQL

Before running the app

Buildkit

As this Dockerfile caches the projects maven dependencies, please ensure docker buildkit is supported (Docker v18.09+) and is enabled.

Use the following command to see if the environment variable is set.

echo $DOCKER_BUILDKIT

If the result returns a blank string or an 0 please use the following command to set it:

export DOCKER_BUILDKIT=1

Running the app

  1. Import as a Maven project into your favourite IDE
  2. Ensure Docker Desktop is running if you are using macOS or Windows. If using Linux, ensure the Docker daemon is running
  3. Build the docker image:
    • With default values: docker-compose build booksapi , or
    • with a custom mvn goal(s), e.g. docker-compose build --build-arg mvn_arg="clean package -DskipTests" booksapi
  4. Run the docker-compose file: docker-compose up -d
    • if you wish to view the output use docker logs -f booksapi
    • alternatively use docker-compose up db booksapi to launch the containers interactively
  5. Wait for the server to start (macOS and Windows: you can check this on Docker desktop for the booksapi container if you used the detached flag earlier)
  6. Go to http://localhost:8082/graphiql

Sample query:

{
    findAllBooks {
        title
        isbn13
        yearOfPublication
        blurb
        publishers {
            name
        }
        isbn10
        authors {
            fullName
        }
        lang {
            name
        }
        genre {
            name
        }
        covers {
            pathToSmall
            pathToMedium
            pathToLarge
        }
        publishingFormat {
            formatName
        }
    }
}

Access database

To access the PostgreSQL database when docker-compose/Docker desktop is running, use the follow credentials in your favourite client:

  • Host: localhost
  • Port: 5432
  • User: dbuser
  • Password: dbpassword
  • Database: books_api
  • URL: jdbc:postgresql://localhost:5432/books_api

For example, in IntelliJ ultimate or DataGrip:

image

Contributing

If you wish to contribute (thanks!), please first see the contributing document.