PetrNikolas / nestjs-graphql-example

NestJS and GraphQL example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NestJS and GraphQL example

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

GraphQL

open http://localhost:3000/graphql in browser

Examples

Query

# Get user by ID
query{
    user(userId: "USER_ID") {
        userId
        age
        email
    }
}

# Get multiple users by IDs
query{
    users(userIds: ["USER_ID"]) {
        userId
        age
        email
    }
}

# Get all users
query{
    users {
        userId
        age
        email
    }
}

Mutations

# Create user
mutation{createUser(createUserData: {
  email: "hello@mail.com",
  age: 28}) {
    userId
    email
    age
    isSubscribed
  }
}

# Update user by ID
mutation{updateUser(updateUserData: {
    userId: "USER_ID"
    age: 29}) {
        userId
        email
        age
        isSubscribed
    }
}

# Delete user by ID
mutation{
    deleteUser(deleteUserData: {
        userId: "USER_ID"}) {
        userId
    }
}

About

NestJS and GraphQL example

License:MIT License


Languages

Language:TypeScript 90.3%Language:JavaScript 9.7%