Giter Club home page Giter Club logo

fastify-graphql-nexus-prisma's Introduction

GraphQL Server with Fastify, Mercurius, Prisma, and Nexus Example

⚠️ Warning!

This repository is no longer maintained and some of the packages may be out of date.

Nonetheless, there are two patterns in here that I think are still really useful for anyone building a GraphQL API:

  • 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. You can learn about this Pothos in this talk from the Pothos creator. The main benefit I see of Pothos over Nexus is simplicity and more active development.
  • Observability & Tracing: having visibility into the health of your GraphQL API is essential, as I demo in this talk.

Intro

This repo shows how to build a GraphQL server with TypeScript and the following technologies:

  • Fastify: Fast and low overhead web framework, for Node.js
  • Mercurius: GraphQL adapter for Fastify
  • Nexus: Declarative, Code-First GraphQL Schemas for JavaScript/TypeScript
  • nexus-prisma: Plugin that allows projecting types from your Prisma schema to the GraphQL schema
  • Prisma: Next-generation ORM for type-safe interaction with the database
  • PostgreSQL: powerful, open source object-relational database system with over 30 years of active development.
  • OpenTelemetry Tracing: An observability framework for cloud-native software. Configured to trace HTTP requests, GraphQL resolution and Prisma queries.
  • Altair GraphQL: GraphQL Web Client (similar to GraphQL Playground and Gr)

The project is written in TypeScript and attempts to maintain a high degree of type-safety by leveraging Prisma and GraphQL.

Play with a deployed version of this API: https://fastify-prisma.up.railway.app/altair

Deploy it! 🚢

Deploy on Railway 🚊

DB Schema

The database schema is defined using the Prisma schema which defines 3 models:

  • User
  • Post
  • Comment

GraphQL schema

The GraphQL schema is defined with Nexus using the code-first approach.

The relevant files are:

Getting started

Prerequisites

  • A PostgreSQL DB

Steps

  1. clone repo
  2. create .env file and define DATABASE_URL and SENTRY_DSN
  3. npm install
  4. npm run migrate:dev to run shcema migrations with Prisma Migrate
  5. npm run dev to start dev server and run the API

Tracing

The GraphQL server is instrumented with OpenTelemetry tracing.

Here's how it works:

  • @autorelic/fastify-opentelemetry is a plugin that creates a root span for every fastify HTTP request and allows creating child spans using request.openTelemetry()
  • @opentelemetry/instrumentation-graphql provides auto-instrumentation for GraphQL execution
  • Additional spans for Prisma Client queries are created in the GraphQL resolvers through context.request.openTelemetry().

Example trace

trace example

Viewing traces in local development with Jaeger

You can view traces in local development using Jaeger.

  1. Start jaeger by going into the tracing folder and running docker compose up -d
  2. In your .env file set JAEGER_EXPORTER="true"
  3. Open the Jaeger UI: http://localhost:16686/

fastify-graphql-nexus-prisma's People

Contributors

2color avatar brainafesoh avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastify-graphql-nexus-prisma's Issues

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Rate Limited

These updates are currently rate limited. Click on a checkbox below to force their creation now.

  • fix(deps): update dependency fastify-plugin to v3.0.1
  • chore(deps): update dependency ts-node to v10.8.1
  • fix(deps): update dependency nexus to v1.3.0
  • fix(deps): update dependency nexus-prisma to v0.35.0
  • fix(deps): update prisma monorepo to v3.15.2 (@prisma/client, prisma)
  • chore(deps): update actions/checkout action to v3
  • chore(deps): update actions/setup-node action to v3
  • chore(deps): update dependency ts-node-dev to v2
  • fix(deps): update dependency dotenv to v16
  • fix(deps): update dependency fastify to v4
  • fix(deps): update dependency mercurius to v10
  • fix(deps): update opentelemetry-js monorepo to v1 (major) (@opentelemetry/api, @opentelemetry/context-async-hooks, @opentelemetry/core, @opentelemetry/exporter-jaeger, @opentelemetry/resources)
  • fix(deps): update sentry-javascript monorepo to v7 (major) (@sentry/node, @sentry/tracing)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
tracing/docker-compose.yaml
  • jaegertracing/all-in-one 1.23.0
github-actions
.github/workflows/test.yaml
  • actions/checkout v2
  • actions/setup-node v1
npm
package.json
  • @autotelic/fastify-opentelemetry 0.13.0
  • @opentelemetry/api 0.20.0
  • @opentelemetry/context-async-hooks 0.20.0
  • @opentelemetry/core 0.20.0
  • @opentelemetry/exporter-collector 0.20.0
  • @opentelemetry/exporter-jaeger 0.20.0
  • @opentelemetry/instrumentation-graphql 0.20.0
  • @opentelemetry/node 0.20.0
  • @opentelemetry/resources 0.20.0
  • @opentelemetry/tracing 0.20.0
  • @prisma/client 3.6.0
  • @sentry/node 6.2.5
  • @sentry/tracing 6.2.5
  • altair-fastify-plugin 4.0.0
  • dotenv 8.2.0
  • fastify 3.14.2
  • fastify-plugin 3.0.0
  • graphql 15.5.0
  • graphql-scalars 1.9.0
  • mercurius 7.4.0
  • nexus 1.1.0
  • nexus-prisma 0.34.0
  • @types/jest 26.0.22
  • @types/node 14.14.37
  • jest 26.6.3
  • prisma 3.6.0
  • ts-jest 26.5.5
  • ts-node 10.4.0
  • ts-node-dev 1.1.8
  • typescript 4.2.3
  • node ^14.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.