{"id":14969221,"url":"https://github.com/2color/fastify-graphql-nexus-prisma","last_synced_at":"2025-08-28T21:31:45.921Z","repository":{"id":37234895,"uuid":"358630635","full_name":"2color/fastify-graphql-nexus-prisma","owner":"2color","description":"GraphQL Server with Fastify, Mercurius, Prisma, and Nexus ","archived":false,"fork":false,"pushed_at":"2022-07-18T14:51:17.000Z","size":124,"stargazers_count":134,"open_issues_count":18,"forks_count":20,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-23T04:05:26.289Z","etag":null,"topics":["fastify","graphql","nodejs","postgresql","prisma","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2color.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-16T14:45:05.000Z","updated_at":"2024-08-27T15:25:36.000Z","dependencies_parsed_at":"2022-07-20T11:47:16.287Z","dependency_job_id":null,"html_url":"https://github.com/2color/fastify-graphql-nexus-prisma","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2color%2Ffastify-graphql-nexus-prisma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2color%2Ffastify-graphql-nexus-prisma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2color%2Ffastify-graphql-nexus-prisma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2color%2Ffastify-graphql-nexus-prisma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2color","download_url":"https://codeload.github.com/2color/fastify-graphql-nexus-prisma/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231299726,"owners_count":18354982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["fastify","graphql","nodejs","postgresql","prisma","typescript"],"created_at":"2024-09-24T13:41:23.246Z","updated_at":"2024-12-26T01:47:27.902Z","avatar_url":"https://github.com/2color.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# GraphQL Server with Fastify, Mercurius, Prisma, and Nexus Example\n\n## ⚠️ Warning! \n\nThis repository is **no longer maintained** and some of the packages may be out of date.\n\nNonetheless, there are two patterns in here that I think are still really useful for anyone building a GraphQL API:\n- Code-first GraphQL schema construction. I still think this is the way to go if you like type safety and TypeScript. I would probably switch Nexus and nexus-prisma for [**Pothos**](https://pothos-graphql.dev/). You can learn about this Pothos in [this talk from the Pothos creator](https://www.youtube.com/watch?v=LqKPfMmxFxw). The main benefit I see of Pothos over Nexus is simplicity and more active development.\n- Observability \u0026 Tracing: having visibility into the health of your GraphQL API is essential, as I demo in [this talk](https://www.youtube.com/watch?v=H9P2rrQJEts). \n\n\n## Intro\n\n\nThis repo shows how to build a GraphQL server with TypeScript and the following technologies:\n\n- [**Fastify**](https://www.fastify.io/): Fast and low overhead web framework, for Node.js\n- [**Mercurius**](https://mercurius.dev/): GraphQL adapter for Fastify\n- [**Nexus**](https://nexusjs.org/): Declarative, Code-First GraphQL Schemas for JavaScript/TypeScript\n- [**nexus-prisma**](https://github.com/prisma/nexus-prisma/): Plugin that allows projecting types from your Prisma schema to the GraphQL schema\n- [**Prisma**](https://www.prisma.io/): Next-generation ORM for type-safe interaction with the database\n- [**PostgreSQL**](https://www.postgresql.org/): powerful, open source object-relational database system with over 30 years of active development.\n\u003c!-- - [**Sentry**](https://sentry.io/): an error tracking and monitoring tool. --\u003e\n- [**OpenTelemetry Tracing**](https://opentelemetry.io/): An observability framework for cloud-native software. Configured to trace HTTP requests, GraphQL resolution and Prisma queries.\n- [**Altair GraphQL**](https://altair.sirmuel.design/): GraphQL Web Client (similar to GraphQL Playground and Gr)\n\nThe project is written in TypeScript and attempts to maintain a high degree of type-safety by leveraging Prisma and GraphQL.\n\nPlay with a deployed version of this API: https://fastify-prisma.up.railway.app/altair\n\n## Deploy it! 🚢\n\n[![Deploy on Railway 🚊](https://railway.app/button.svg)](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2F2color%2Ffastify-graphql-nexus-prisma\u0026plugins=postgresql\u0026envs=SENTRY_DSN\u0026optionalEnvs=SENTRY_DSN)\n\n\n## DB Schema\n\nThe database schema is defined using the [Prisma schema](./prisma/schema.prisma) which defines 3 models:\n- User\n- Post\n- Comment\n\n\n## GraphQL schema\n\nThe GraphQL schema is defined with Nexus using the [code-first approach](https://www.prisma.io/blog/the-problems-of-schema-first-graphql-development-x1mn4cb0tyl3).\n\nThe relevant files are:\n- [./src/schema.ts](./src/schema.ts): Source of truth for the schema in TypeScript\n- [./schema.graphql](./schema.graphql): Generated GraphQL scehma\n\n## Getting started\n\n### Prerequisites \n- A PostgreSQL DB\n\n### Steps\n\n1. clone repo\n2. create `.env` file and define `DATABASE_URL` and `SENTRY_DSN`\n3. `npm install`\n4. `npm run migrate:dev` to run shcema migrations with [Prisma Migrate](https://www.prisma.io/migrate)\n5. `npm run dev` to start dev server and run the API\n\n## Tracing\n\nThe GraphQL server is instrumented with OpenTelemetry tracing.\n\nHere's how it works:\n- `@autorelic/fastify-opentelemetry` is a plugin that creates a root span for every fastify HTTP request and allows creating child spans using `request.openTelemetry()`\n-  `@opentelemetry/instrumentation-graphql` provides auto-instrumentation for GraphQL execution\n- Additional spans for Prisma Client queries are created in the GraphQL resolvers through `context.request.openTelemetry()`.\n\n\n### Example trace\n\n![trace example](https://user-images.githubusercontent.com/1992255/123289101-6c69d400-d510-11eb-9154-8aa0bdb8d10c.png)\n\n\n### Viewing traces in local development with Jaeger\n\nYou can view traces in local development using [Jaeger](https://www.jaegertracing.io/).\n\n1. Start jaeger by going into the [tracing](./tracing) folder and running `docker compose up -d`\n2. In your `.env` file set `JAEGER_EXPORTER=\"true\"`\n3. Open the Jaeger UI: `http://localhost:16686/`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2color%2Ffastify-graphql-nexus-prisma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2color%2Ffastify-graphql-nexus-prisma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2color%2Ffastify-graphql-nexus-prisma/lists"}