GithubHelp home page GithubHelp logo

ts-graphql-book-reviews's Introduction

Book Review GraphQL API

Book review GraphQL API built using Node.js, TypeScript, Prisma, and GraphQL Yoga. This API allows you to manage users, reviews, and books.

Installation

To set up the API locally, follow these steps:

  1. Install dependencies:
pnpm install
  1. Host postgresql database. For local development you can use docker and included docker-compose.yml file:
docker-compose up -d
  1. Fill .env file, example:
DATABASE_URL="postgresql://admin:password@localhost:5432/posts"
JWT_SECRET="secret"
PORT=4000
TOKEN_EXPIRE_TIME="1d"
  1. Apply migrations to create the database schema:
npx prisma migrate dev
  1. Start the server:
npm run start:dev

Schema Overview

The GraphQL schema defines the types, queries, and mutations available in the API. Here's an overview of the main types:

  • User: Represents a user with their name, email, and reviews.
  • Book: Represents a book with its title, author, ISBN, and reviews.
  • Review: Represents a review with its text, rating, author, and book.

Queries

profile

Retrieve the profile of the currently authenticated user.

query {
  profile {
    id
    name
    email
    reviews {
      id
      text
      rating
      book {
        id
        title
      }
    }
  }
}

users

Retrieve a list of users based on the provided query.

query {
  users(query: "example") {
    id
    name
    email
    reviews {
      id
      text
      rating
      book {
        id
        title
      }
    }
  }
}

books

Retrieve a list of books based on the provided query, skip, and take parameters.

query {
  books(query: "example", skip: 0, take: 10) {
    id
    title
    author
    reviews {
      id
      text
      rating
      author {
        id
        name
      }
    }
  }
}

Mutations

createUser

Create a new user.

mutation {
  createUser(data: {
    name: "John Doe"
    email: "[email protected]"
    password: "secretpassword"
  }) {
    id
    name
    email
  }
}

login

Authenticate a user and retrieve their profile along with a token.

mutation {
  login(email: "[email protected]", password: "secretpassword") {
    user {
      id
      name
      email
    }
    token
  }
}

createBook (protected)

Create a new book.

mutation {
  createBook(title: "Sample Book", author: "Author Name", isbn: "123456789") {
    id
    title
    author
    isbn
  }
}

createReview (protected)

Create a new review for a book.

mutation {
  createReview(text: "Great book!", rating: 5, bookId: '123') {
    id
    text
    rating
    book {
      id
      title
      author
      isbn
    }
  }
}

Authentication

The API uses token-based authentication. To authenticate, use the login mutation to obtain a token. Include the token in the Authorization header of your requests with the format: Bearer <token>.

ts-graphql-book-reviews's People

Contributors

alexrazor1337 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.