Skip to content

farabixcode/nest-graphql-product-api

Repository files navigation

README

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Products API

An Graphql based api where user can read, create, delete product & listen for realtime notification about newly created & deleted product

GraphQL Schema

Types

type Delete {
  id: String!
  deleted: Boolean!
}

type Transaction {
  id: String!
  quantity: Int!
  time: String!
  status: String!
}

type Product {
  id: String!
  transactions: [Transaction!]!
}

Queries

type Query {
  products: [Product!]!
  product(id: String!): Product!
}

Mutations

type Mutation {
  createProduct(quantity: Int!): Product!
  deleteProduct(id: String!): Delete!
}

Subscriptions

type Subscription {
  createdProduct: Product!
  deletedProduct: Delete!
}

API Reference

Get All Products

query products {
  products {
    id
    transactions {
      id
      quantity
      time
    }
  }
}

Get a specific product

query product {
  product(id: "8e532ef8-88a2-44eb-8683-632badc2d106") {
    id,
    transactions{
      id,
      quantity,
      time
    }
  }
}

Create a product

mutation createProduct{
  createProduct(quantity: 14) {
    id,
    transactions{
      id,
      quantity,
      time
    }
  }
}

Delete a specific product

mutation deleteProduct{
  deleteProduct(id: "8e532ef8-88a2-44eb-8683-632badc2d106") {
    id,
    deleted
  }
}

Real time notification - If any product is created

subscription createdProduct{
  createdProduct{
    id,
    transactions{
      id,
      quantity,
      time
    }
  }
}

Real time notification - If any product is deleted

subscription deletedProduct {
  deletedProduct{
    id,
    deleted
  }
}

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published