https://github.com/petrnikolas/nestjs-graphql-example
NestJS and GraphQL example
https://github.com/petrnikolas/nestjs-graphql-example
Last synced: 12 months ago
JSON representation
NestJS and GraphQL example
- Host: GitHub
- URL: https://github.com/petrnikolas/nestjs-graphql-example
- Owner: PetrNikolas
- License: mit
- Created: 2021-12-14T14:52:21.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-14T15:08:04.000Z (over 4 years ago)
- Last Synced: 2025-01-11T10:19:50.768Z (over 1 year ago)
- Language: TypeScript
- Size: 127 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NestJS and GraphQL example
## Installation
```bash
$ npm install
```
## Running the app
```bash
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
```
## Test
```bash
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
```
## GraphQL
```bash
open http://localhost:3000/graphql in browser
```
### Examples
#### Query
```graphql
# 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
```graphql
# 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
}
}
```