/prisma-nexus-boilerplate

A boilerplate for a prisma-nexus GraphQL implementation

Primary LanguageTypeScript

Prisma Nexus boilerplate

This repository is a boiler plate for using the prisma plugin with GraphQL Nexus. Currently, only prisma version 1 is supported. We plan on supporting prisma 2 once it hits GA.

1. Table of Contents

  1. Table of Contents
  2. Technologies used
  3. GraphQL middleware
  4. How to use
  5. Deployment
  6. To-do

2. Technologies Used

3. GraphQL Middleware

This boilerplate has the following graphql middleware packages installed to help ease implementation.

4. How to use

  1. Install the prisma cli
npm install -g prisma
  1. Build your data model in prisma/datamodel.prisma using the graphql schema definition language
type User {
  id: ID! @id
  email: String! @unique
  token: String
  name: String
  username: String
  description: String
  photo_url: String
  flagged_as_objectionable: Boolean @default(value: false)
  view_objectionable_content: Boolean @default(value: true)
  receive_push_notifications: Boolean @default(value: true)
  oneSignalPlayerId: String
  fcm_token: String
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

type Notification {
  ...
}
...
  1. Deploy your model
prisma deploy
  1. Customize your GraphQL server with Queries, Mutations, Subscriptions, GraphQL types, and/or computed fields

Navigate to the models directory and update the respected file(s).

const Notification = prismaObjectType({
  name: 'Notification',
  description: 'A separare entity to control notifications for users',
  definition(t) {
    t.prismaFields(['*']);
  }
});

Note: This section is done using graphql-nexus. Check out the docs for more info.

5. Deployment

There are 3 separate services that need to be deployed: A graphql server, a prisma server, and a postgres database. If using AWS, EC2 is typically used to create a graphql server, a Fargate instance for the prisma server, and an RDS instance to host the database.

5. To-do

  1. Upgrade to prisma 2
  2. Add examples for yup validation
  3. Add JWT Refresh token support/examples
  4. Add OneSignal Datasource
  5. Add middleware for push notifications
  6. Add examples for file upload
  7. Add Subscription examples