Skip to content

mattcollier/nestjs-graphql

Repository files navigation

Attribution

Thanks to gitdagray for initial skeleton for this project: https://github.com/gitdagray/nestjs-course. The graphql implementation was inspired by: https://github.com/vahid-nejad/nestjs-graphql-course.

Description

The initial skeleton provides REST endpoints for doing CRUD operations on users which is an in memory list of users and their attributes.

TODO:

  • [ x ] Incorporate a GraphQL interface.
  • [ x ] Implement a parent child relationship with an in-memory posts collection.
  • [ x ] Implement a dataloader to optimize retrieval of user posts.
  • [ x ] Implement a mutation with DTO validations for creating a new user.
  • [ x ] Implement a user query to retrieve a single user.
  • [ x ] Add additional e2e tests for GraphQL API.

Objectives Met

Access the GraphQL Playground at http://localhost:3000/graphql

The GraphQL API can now satisfy the following queries:

# users corresponds to the name given to the "findAll" resolver
{users {id, name, email, role}}

# with posts
{users {id, name, email, role, posts {content}}}

# get a single user
{user(id: 1) { id name email role }}

# create a user, returns the new user with the `id` created on the server
mutation {
  createUser(createUserInput: {  email: "[email protected]", role: ADMIN, name: "Alice" }) {
    name
    role
    email
    id
  }
}

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