https://github.com/basemax/bookstoregraphqlts
This is a TypeScript-based GraphQL API for a bookstore that allows users to browse books and manage their accounts. The API is built using Apollo Server, and it uses Redis for caching and PostgreSQL as the database. Docker is used to automatically install PostgreSQL and the GraphQL tools.
https://github.com/basemax/bookstoregraphqlts
api graphql javascript js postgresql psql ts typescript
Last synced: 3 months ago
JSON representation
This is a TypeScript-based GraphQL API for a bookstore that allows users to browse books and manage their accounts. The API is built using Apollo Server, and it uses Redis for caching and PostgreSQL as the database. Docker is used to automatically install PostgreSQL and the GraphQL tools.
- Host: GitHub
- URL: https://github.com/basemax/bookstoregraphqlts
- Owner: BaseMax
- License: gpl-3.0
- Created: 2023-04-14T15:49:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-18T10:09:48.000Z (about 2 years ago)
- Last Synced: 2025-03-28T17:08:04.266Z (over 1 year ago)
- Topics: api, graphql, javascript, js, postgresql, psql, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 732 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TypeScript GraphQL API for Bookstore
This is a TypeScript-based GraphQL API for a bookstore that allows users to browse books and manage their accounts. The API is built using Apollo Server, and it uses Redis for caching and PostgreSQL as the database. Docker is used to automatically install PostgreSQL and the GraphQL tools.
## Features
- Browse books: users can query for a list of all books or search for a book by its ID.
- Manage accounts: users can create, update, and delete their accounts, as well as purchase books.
- Browse genres: users can query for a list of all genres.
- Caching: the API uses Redis to cache the books query for at least a day, the users query for 3 hours, and the genres query for 1 week.
## Technologies
- TypeScript
- Apollo Server
- Redis
- PostgreSQL
- Docker
## Getting Started
To get started with the project, follow these steps:
Clone the repository:
```bash
git clone https://github.com/BaseMax/BookstoreGraphQLTS
```
Install dependencies:
```bash
cd BookstoreGraphQLTS
npm install
```
Start the PostgreSQL and Redis servers using Docker:
```bash
docker-compose up -d
```
Start the server:
```bash
npm run start
```
Visit http://localhost:4000/graphql to interact with the API using the GraphQL Playground.
## Testing
To run the tests, use the following command:
```shell
npm run test:e2e
```
This will execute the test suite and provide the test results.
## Background
You are tasked with building a GraphQL API for a bookstore that will allow users to browse books and manage their accounts. The API should be built using TypeScript and Apollo Server, and it should use Redis for caching and PostgreSQL as the database. Docker should be used to automatically install PostgreSQL and the GraphQL tools.
## Requirements
The GraphQL API should have the following types:
- Book: a book has an ID, title, author, ISBN, and an array of genres.
- User: a user has an ID, name, email, password, and an array of books they have purchased.
- Genre: a genre has an ID and a name.
The API should have the following queries and mutations.
### Queries:
- books: returns a list of all books. This query should be cached in Redis for at least a day.
```graphql
query {
books {
id
title
author
ISBN
genre {
name
}
}
}
```
- book: returns a book by its ID.
```graphql
query {
book(id: id) {
id
title
author
ISBN
genre {
name
}
}
}
```
- users: returns a list of all users.
```graphql
query {
users {
id
name
email
books
}
}
```
- user: returns a user by their ID.
```graphql
query($id: ID!) {
user(id: $id) {
id
name
email
books
}
}
```
- genres: returns a list of all genres. This query should be cached in Redis for 1 week.
```graphql
query {
genres {
id
name
}
}
```
### Mutations
- createBook: creates a new book.
```graphql
mutation {
createBook(createBookInput) {
id
title
author
ISBN
genres
}
}
```
- updateBook: updates a book by its ID.
```graphql
mutation {
updateBook(updateBookInput) {
id
title
author
ISBN
genres
}
}
```
- deleteBook: deletes a book by its ID.
```graphql
mutation {
removeBook(id: id) {
id
title
author
ISBN
genres
}
}
```
- purchaseBook: adds a book to a user's list of purchased books.
```graphql
mutation {
purchaseBook(userId: $userId, bookId: $bookId) {
id
name
email
books
}
}
```
- createUser: creates a new user.
```graphql
mutation() {
createUser(createUserInout) {
id
name
email
}
}
```
- updateUser: updates a user by their ID.
```graphql
mutation {
updateUser(updateUserInput) {
id
name
email
books
}
}
```
- deleteUser: deletes a user by their ID.
```graphql
mutation() {
deleteUser(id: $id) {
id
name
email
books
}
}
```
The API should use Redis to cache the books query for at least a day, the users query for 3 hours, and the genres query for 1 week.
The API should use PostgreSQL as the database for storing and retrieving data.
Docker should be used to automatically install PostgreSQL and the GraphQL tools.
## Deliverables
- Instructions for running the API using Docker.
- A brief write-up explaining any design decisions and assumptions made during the development process.
Note: This is just an example assignment and you can customize it based on your specific requirements and needs.
## Contributions
Contributions are welcome! If you find a bug or would like to suggest a new feature, please open an issue or a pull request.
Copyright 2023, Max Base