ricardoalmeida / federation-nexus-prisma

Sample GraphQL using Prisma 2 and Nexus-schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GraphQL Apollo Federation, Prisma and Nexus-Schema

This example is an GraphQL server implementation in TypeScript using Apollo Federation, Prisma and Nexus-Schema. It uses Postgres database.

How to use

1. Download and install dependencies

Clone this repository:

git clone git@github.com:ricardoalmeida/federation-nexus-prisma.git

Install yarn dependencies:

cd federation-nexus-prisma
yarn install

2. Start Postgres via Docker

docker-compose up -d

3. Run db migrations

yarn prisma:migrate

4. Start Service and Gateway

Vitrola (Service)

yarn dev

Gateway Server

yarn gateway

The GraphQL Playground is available in http://localhost:4000/graphql.

Using the GraphQL API

Try it out!

mutation createTrack {
  createOneTrack(data: { name: "Favorite Track" }) {
    id
    name
  }
}

mutation createPlaylist {
  createOnePlaylist(data: { description: "My playlist" }) {
    id
  }
}

query playlists {
  playlists {
    id
    description
    tracks {
      id
    }
  }
}

query playlist {
  playlist(where: { id: 1 }) {
    id
    tracks {
      id
    }
  }
}

Development

If you use VSCode, install plugin for Prisma: https://marketplace.visualstudio.com/items?itemName=Prisma.prisma

Integration tests

GraphQL queries and mutations are using Postgres for an integration test validation. So make sure you have the db up and running.

yarn postgres:start
yarn test

Authentication & Authorization

The Gateway authenticates the user (TODO) and send proper headers to the service. The service uses graphql-shield to verify permissions.

About

Sample GraphQL using Prisma 2 and Nexus-schema


Languages

Language:TypeScript 91.2%Language:Dockerfile 6.3%Language:JavaScript 1.9%Language:Shell 0.7%