{"id":26871726,"url":"https://github.com/eocode/nestjs-graphql","last_synced_at":"2026-04-30T00:07:44.607Z","repository":{"id":126329583,"uuid":"290580698","full_name":"eocode/NestJS-GraphQL","owner":"eocode","description":"NestJS project with GraphQL","archived":false,"fork":false,"pushed_at":"2020-09-13T18:08:58.000Z","size":224,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T07:34:08.667Z","etag":null,"topics":["js","project","software-engineering"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eocode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-26T18:58:55.000Z","updated_at":"2021-05-02T19:33:58.000Z","dependencies_parsed_at":"2023-06-16T08:00:48.797Z","dependency_job_id":null,"html_url":"https://github.com/eocode/NestJS-GraphQL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"notiz-dev/nestjs-prisma-starter","purl":"pkg:github/eocode/NestJS-GraphQL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FNestJS-GraphQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FNestJS-GraphQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FNestJS-GraphQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FNestJS-GraphQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eocode","download_url":"https://codeload.github.com/eocode/NestJS-GraphQL/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eocode%2FNestJS-GraphQL/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32448893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["js","project","software-engineering"],"created_at":"2025-03-31T07:30:33.787Z","updated_at":"2026-04-30T00:07:44.603Z","avatar_url":"https://github.com/eocode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Instructions\n\nStarter template for 😻 [NestJS](https://nestjs.com/) and [Prisma](https://www.prisma.io/).\n\n\u003e Checkout [NestJS Prisma Schematics](https://github.com/marcjulian/nestjs-prisma) to automatically add Prisma support to your Nest application.\n\n## Version\n\n| Branch                                                                                                       |  Nest | Prisma                                               |  Graphql                                                              |\n| ------------------------------------------------------------------------------------------------------------ | ----- | ---------------------------------------------------- | --------------------------------------------------------------------- |\n| master                                                                                                       | v7    | [prisma2](https://github.com/prisma/prisma2)         | [Code-first](https://docs.nestjs.com/graphql/quick-start#code-first)  |\n| [Prisma2 Code First](https://github.com/fivethree-team/nestjs-prisma-starter/tree/nest-6-prisma2-code-first) | v6    | [prisma2-preview](https://github.com/prisma/prisma2) | [Code-first](https://github.com/19majkel94/type-graphql)              |\n| [Prisma1 Code First](https://github.com/fivethree-team/nestjs-prisma-starter/tree/nest-6-code-first)         | v6    | [v1](https://github.com/prisma/prisma)               | [Code-first](https://github.com/19majkel94/type-graphql)              |\n| [Prisma1 SDL First]()                                                                                        | v6    | [v1](https://github.com/prisma/prisma)               | [SDL First](https://docs.nestjs.com/graphql/quick-start#schema-first) |\n| [Prisma1 SDL First](https://github.com/fivethree-team/nestjs-prisma-starter/tree/nest-5)                     | v5    | [v1](https://github.com/prisma/prisma)               | [SDL First](https://docs.nestjs.com/graphql/quick-start#schema-first) |\n\n## Features\n\n- GraphQL w/ [playground](https://github.com/prisma/graphql-playground)\n- Code-First w/ [decorators](https://docs.nestjs.com/graphql/quick-start#code-first)\n- [Prisma](https://www.prisma.io/) for database modelling, migration and type-safe access (Postgres, MySQL \u0026 MongoDB)\n- 🔐 JWT authentication w/ [passport-jwt](https://github.com/mikenicholson/passport-jwt)\n- REST API docs w/ [Swagger](https://swagger.io/)\n\n## Overview\n\n- [Instructions](#instructions)\n  - [Features](#features)\n  - [Overview](#overview)\n  - [Prisma Setup](#prisma-setup)\n    - [1. Install Dependencies](#1-install-dependencies)\n    - [2. Prisma2: Prisma Migrate](#2-prisma2-prisma-migrate)\n    - [3. Prisma2: Prisma Client JS](#3-prisma2-client-js)\n    - [4. Seed the database data with this script](#4-seed-the-database-data-with-this-script)\n    - [5. Install Nestjs](#5-install-nestjs)\n  - [Start NestJS Server](#start-nestjs-server)\n  - [Playground](#playground)\n  - [Rest Api](#rest-api)\n  - [Docker](#docker)\n  - [Schema Development](#schema-development)\n  - [NestJS - Api Schema](#nestjs---api-schema)\n    - [Resolver](#resolver)\n  - [Graphql Client](#graphql-client)\n    - [Angular](#angular)\n      - [Setup](#setup)\n      - [Queries](#queries)\n      - [Mutations](#mutations)\n      - [Subscriptions](#subscriptions)\n      - [Authentication](#authentication)\n\n## Prisma Setup\n\n### 1. Install Dependencies\n\nInstall the dependencies for the nest server:\n\n```bash\nnpm install\n```\n\n### 2. Prisma2: Prisma Migrate\n\n[Prisma Migrate](https://github.com/prisma/prisma2/tree/master/docs/prisma-migrate) is used to manage the schema and migration of the database.\n\nSaving the migration of the database:\n\n```bash\nnpx prisma migrate save --experimental\n# or\nnpm run prisma:save\n```\n\nPerform the database migration:\n\n```bash\nnpx prisma migrate up --experimental\n# or\nnpm run prisma:up\n```\n\n### 3. Prisma2: Prisma Client JS\n\n[Prisma Client JS](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/api) is a type-safe database client auto-generated based on the data model.\n\nTo generate Prisma Client JS execute, this will always be executed after `npm install`:\n\n```bash\nnpx prisma generate\n# or\nnpm run prisma:generate\n```\n\n### 4. Seed the database data with this script\n\nExecute the script with this command:\n\n```bash\nnpm run seed\n```\n\n### 5. Install Nestjs\n\nThe [Nestjs CLI](https://docs.nestjs.com/cli/usages) can be used to generate controller, services, resolvers and more.\n\n```bash\nnpm i -g @nestjs/cli\n```\n\n**[⬆ back to top](#overview)**\n\n## Start NestJS Server\n\nRun Nest Server in Development mode:\n\n```bash\nnpm run start\n\n# watch mode\nnpm run start:dev\n```\n\nRun Nest Server in Production mode:\n\n```bash\nnpm run start:prod\n```\n\nPlayground for the NestJS Server is available here: http://localhost:3000/graphql\n\n**[⬆ back to top](#overview)**\n\n## Playground\n\nSome queries and mutations are secured by an auth guard. You have to acquire a JWT token from `signup` or `login`. Add the the auth token as followed to **HTTP HEADERS** in the playground and replace `YOURTOKEN` here:\n\n```json\n{\n  \"Authorization\": \"Bearer YOURTOKEN\"\n}\n```\n\n## Rest Api\n\n[RESTful API](http://localhost:3000/api) documentation available with Swagger.\n\n## Docker\n\nNest serve is a Node.js application and it is easily [dockerized](https://nodejs.org/de/docs/guides/nodejs-docker-webapp/).\n\nSee the [Dockerfile](./Dockerfile) on how to build a Docker image of your Nest server.\n\nNow to build a Docker image of your own Nest server simply run:\n\n```bash\n# give your docker image a name\ndocker build -t \u003cyour username\u003e/nest-prisma-server .\n# for example\ndocker build -t nest-prisma-server .\n```\n\nAfter Docker build your docker image you are ready to start up a docker container running the nest server:\n\n```bash\ndocker run -d -t -p 3000:3000 --env-file .env nest-prisma-server\n```\n\nNow open up [localhost:3000](http://localhost:3000) to verify that your nest server is running.\n\n## Schema Development\n\nUpdate the Prisma schema `prisma/schema.prisma` and after that run the following two commands:\n\n```bash\nnpx prisma generate\n# or in watch mode\nnpx prisma generate --watch\n# or\nnpm run prisma:generate\nnpm run prisma:generate:watch\n```\n\n**[⬆ back to top](#overview)**\n\n## NestJS - Api Schema\n\nThe [schema.graphql](./src/schema.graphql) is generated with [code first approach](https://docs.nestjs.com/graphql/quick-start#code-first). The schema is generated from the [models](./src/models/user.ts), the [resolvers](./src/resolvers/auth/auth.resolver.ts) and the [input](./src/resolvers/auth/dto/login.input.ts) classes.\n\nYou can use [class-validator](https://docs.nestjs.com/techniques/validation) to validate your inputs and arguments.\n\n### Resolver\n\nTo implement the new query, a new resolver function needs to be added to `users.resolver.ts`.\n\n```ts\n@Query(returns =\u003e User)\nasync getUser(@Args() args): Promise\u003cUser\u003e {\n  return await this.prisma.client.user(args);\n}\n```\n\nRestart the NestJS server and this time the Query to fetch a `user` should work.\n\n**[⬆ back to top](#overview)**\n\n## Graphql Client\n\nA graphql client is necessary to consume the graphql api provided by the NestJS Server.\n\nCheckout [Apollo](https://www.apollographql.com/) a popular graphql client which offers several clients for React, Angular, Vue.js, Native iOS, Native Android and more.\n\n### Angular\n\n#### Setup\n\nTo start using [Apollo Angular](https://www.apollographql.com/docs/angular/basics/setup.html) simply run in an Angular and Ionic project:\n\n```bash\nng add apollo-angular\n```\n\n`HttpLink` from apollo-angular requires the `HttpClient`. Therefore, you need to add the `HttpClientModule` to the `AppModule`:\n\n```ts\nimports: [BrowserModule,\n    HttpClientModule,\n    ...,\n    GraphQLModule],\n```\n\nYou can also add the `GraphQLModule` in the `AppModule` to make `Apollo` available in your Angular App.\n\nYou need to set the URL to the NestJS Graphql Api. Open the file `src/app/graphql.module.ts` and update `uri`:\n\n```ts\nconst uri = 'http://localhost:3000/graphql';\n```\n\nTo use Apollo-Angular you can inject `private apollo: Apollo` into the constructor of a page, component or service.\n\n**[⬆ back to top](#overview)**\n\n#### Queries\n\nTo execute a query you can use:\n\n```ts\nthis.apollo.query({query: YOUR_QUERY});\n\n# or\n\nthis.apollo.watchQuery({\n  query: YOUR_QUERY\n}).valueChanges;\n```\n\nHere is an example how to fetch your profile from the NestJS Graphql Api:\n\n```ts\nconst CurrentUserProfile = gql`\n  query CurrentUserProfile {\n    me {\n      id\n      email\n      name\n    }\n  }\n`;\n\n@Component({\n  selector: 'app-home',\n  templateUrl: 'home.page.html',\n  styleUrls: ['home.page.scss'],\n})\nexport class HomePage implements OnInit {\n  data: Observable\u003cany\u003e;\n\n  constructor(private apollo: Apollo) {}\n\n  ngOnInit() {\n    this.data = this.apollo.watchQuery({\n      query: CurrentUserProfile,\n    }).valueChanges;\n  }\n}\n```\n\nUse the `AsyncPipe` and [SelectPipe](https://www.apollographql.com/docs/angular/basics/queries.html#select-pipe) to unwrap the data Observable in the template:\n\n```html\n\u003cdiv *ngIf=\"data | async | select: 'me' as me\"\u003e\n  \u003cp\u003eMe id: {{me.id}}\u003c/p\u003e\n  \u003cp\u003eMe email: {{me.email}}\u003c/p\u003e\n  \u003cp\u003eMe name: {{me.name}}\u003c/p\u003e\n\u003c/div\u003e\n```\n\nOr unwrap the data using [RxJs](https://www.apollographql.com/docs/angular/basics/queries.html#rxjs).\n\nThis will end up in an `GraphQL error` because `Me` is protected by an `@UseGuards(GqlAuthGuard)` and requires an `Bearer TOKEN`.\nPlease refer to the [Authentication](#authentication) section.\n\n**[⬆ back to top](#overview)**\n\n#### Mutations\n\nTo execute a mutation you can use:\n\n```ts\nthis.apollo.mutate({\n  mutation: YOUR_MUTATION,\n});\n```\n\nHere is an example how to login into your profile using the `login` Mutation:\n\n```ts\nconst Login = gql`\n  mutation Login {\n    login(email: \"test@example.com\", password: \"pizzaHawaii\") {\n      token\n      user {\n        id\n        email\n        name\n      }\n    }\n  }\n`;\n\n@Component({\n  selector: 'app-home',\n  templateUrl: 'home.page.html',\n  styleUrls: ['home.page.scss'],\n})\nexport class HomePage implements OnInit {\n  data: Observable\u003cany\u003e;\n\n  constructor(private apollo: Apollo) {}\n\n  ngOnInit() {\n    this.data = this.apollo.mutate({\n      mutation: Login,\n    });\n  }\n}\n```\n\n**[⬆ back to top](#overview)**\n\n#### Subscriptions\n\nTo execute a subscription you can use:\n\n```ts\nthis.apollo.subscribe({\n  query: YOUR_SUBSCRIPTION_QUERY,\n});\n```\n\n**[⬆ back to top](#overview)**\n\n#### Authentication\n\nTo authenticate your requests you have to add your `TOKEN` you receive on `signup` and `login` [mutation](#mutations) to each request which is protected by the `@UseGuards(GqlAuthGuard)`.\n\nBecause the apollo client is using `HttpClient` under the hood you are able to simply use an `Interceptor` to add your token to the requests.\n\nCreate the following class:\n\n```ts\nimport { Injectable } from '@angular/core';\nimport {\n  HttpEvent,\n  HttpInterceptor,\n  HttpHandler,\n  HttpRequest,\n} from '@angular/common/http';\nimport { Observable } from 'rxjs';\n\n@Injectable()\nexport class TokenInterceptor implements HttpInterceptor {\n  constructor() {}\n\n  intercept(\n    req: HttpRequest\u003cany\u003e,\n    next: HttpHandler\n  ): Observable\u003cHttpEvent\u003cany\u003e\u003e {\n    const token = 'YOUR_TOKEN'; // get from local storage\n    if (token !== undefined) {\n      req = req.clone({\n        setHeaders: {\n          Authorization: `Bearer ${token}`,\n        },\n      });\n    }\n\n    return next.handle(req);\n  }\n}\n```\n\nAdd the Interceptor to the `AppModule` providers like this:\n\n```ts\nproviders: [\n    ...\n    { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true },\n    ...\n  ]\n```\n\nAfter you configured the Interceptor and retrieved the `TOKEN` from storage your request will succeed on resolvers with `@UseGuards(GqlAuthGuard)`.\n\n**[⬆ back to top](#overview)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feocode%2Fnestjs-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feocode%2Fnestjs-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feocode%2Fnestjs-graphql/lists"}