• Stars
    star
    160
  • Rank 234,703 (Top 5 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sample auth module with Prisma 2 and Nexus

GraphQL Server with Authentication Prisma 2 and Nexus Schema

Build Status

This example shows how to implement a GraphQL server with an email-password-based auth, based on Prisma, apollo-server, graphql-shield & Nexus Schema via the Nexus Prisma plugin.

How to use

1. Clone this repo & install dependencies

Install Node dependencies:

yarn (recommended) or npm install

2. Set up the database

This uses a simple SQLite database.

Note: You can delete the migrations folder to create your own new migrations

To set up your database, run:

yarn db:save
yarn db:migrate

You can now use the SQLite Browser to view and edit your data in the ./prisma/dev.db file that was created when you ran yarn db:migrate.

3. Generate Prisma Client (type-safe database client)

Run the following command to generate Prisma Client:

yarn generate:prisma

Now you can seed your database using the seed script from package.json:

yarn seed

4. Start the GraphQL server

Launch your GraphQL server with this command:

yarn dev

Navigate to http://localhost:4002 in your browser to explore the API of your GraphQL server in a GraphQL Playground.

5. Using the GraphQL API

The schema that specifies the API operations of your GraphQL server is defined in ./src/generated/schema.graphql. Below are a number of operations that you can send to the API using the GraphQL Playground.

Feel free to adjust any operation by adding or removing fields. The GraphQL Playground helps you with its auto-completion and query validation features.

Retrieve all published posts and their authors

query {
  feed {
    id
    title
    content
    published
    author {
      id
      name
      email
    }
  }
}
See more API operations

Register a new user

You can send the following mutation in the Playground to sign up a new user and retrieve an authentication token for them:

mutation {
  signup(name: "Alice", email: "[email protected]", password: "graphql") {
    token
  }
}

Log in an existing user

This mutation will log in an existing user by requesting a new authentication token for them:

mutation {
  login(email: "[email protected]", password: "graphql") {
    token
  }
}

Check whether a user is currently logged in with the me query

For this query, you need to make sure a valid authentication token is sent along with the Bearer-prefix in the Authorization header of the request:

{
  "Authorization": "Bearer __YOUR_TOKEN__"
}

With a real token, this looks similar to this:

{
  "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJjanAydHJyczFmczE1MGEwM3kxaWl6c285IiwiaWF0IjoxNTQzNTA5NjY1fQ.Vx6ad6DuXA0FSQVyaIngOHYVzjKwbwq45flQslnqX04"
}

Inside the Playground, you can set HTTP headers in the bottom-left corner:

Once you've set the header, you can send the following query to check whether the token is valid:

{
  me {
    id
    name
    email
  }
}

6. Changing the GraphQL schema

To make changes to the GraphQL schema, you need to manipulate the files in the resolvers folder.

Next steps

Testing

Run yarn test or npm run test to run tests via Jest in the tests folder.

More Repositories

1

fastify-prisma

Basic Fastify app using Prisma as an ORM
TypeScript
28
star
2

passwordless-auth

Allows a user to login directly via email without a need for entering passwords using Cognito
TypeScript
24
star
3

serverless-prisma

Deploying a Prisma 2 app with apollo-server on AWS Lambda using the Serverless framework
TypeScript
19
star
4

prisma-lambda

Integrating Prisma with `aws-lambda-nodejs` to run Prisma on Lambda
JavaScript
18
star
5

rust-lambda

This is a CDK project that deploys a Rust function using the Rust runtime for Lambda. This creates a basic handler that logs some data sent as input
TypeScript
12
star
6

spa-deploy-cdk

Deploy a SPA with AWS Codebuild using aws-cdk
TypeScript
11
star
7

electron-sockets

An Electron app (React) connected to a Node Backend (Backpack) and SocketIO
JavaScript
11
star
8

node-beanstalk-cdk

Deploy a Node app on Elastic Beanstalk with AWS Codebuild using aws-cdk
TypeScript
11
star
9

nexus-introspection

An auth flow with Prisma and Nexus using introspection instead of Migrate
TypeScript
8
star
10

cdk-nested-stacks

A basic example of how Nested Stacks work in AWS CDK
TypeScript
8
star
11

lambda-canary-deployments

API Gateway and Lambda with weighted routing to the latest function deployed
TypeScript
7
star
12

prisma-rds-proxy

A Prisma app deployed on AWS (Lambda + API Gateway) with RDS and RDS Proxy
TypeScript
7
star
13

s3-thumbnail-generator

Generate thumbnails with S3 via SQS and Lambda created using AWS CDK
TypeScript
7
star
14

ts-algorithms

Algorithms and Data Structures created in TypeScript
TypeScript
6
star
15

graphql-codegen

Getting the best developer experience with GraphQL using TypeScript and Codegen
TypeScript
5
star
16

next-ssr

A simple React SSR app using Next.js
TypeScript
5
star
17

youtube-video-search

A minimal youtube search functionality with google auth
JavaScript
4
star
18

svelte-electron

A sample electron app made with Svelte & Webpack. Routing and Lazy Loading included
JavaScript
3
star
19

ts-rust

Using Rust a like type system in TypeScript
JavaScript
3
star
20

makefile-test

A sample repo testing how a Makefile works
TypeScript
3
star
21

push-notifications

Push Notifications in a React App using Firebase
TypeScript
3
star
22

docker-dev

Full Stack app development with Docker
TypeScript
3
star
23

testing-react

A repository with testing solutions for React patterns
TypeScript
3
star
24

ts-setup

TypeScript dev setup with Nodemon and esbuild
TypeScript
3
star
25

step-function-sync-workflow

Synchronous Express Workflows for AWS Step Functions via API Gateway
TypeScript
3
star
26

typescript-advanced

Typescript advanced snippets
TypeScript
2
star
27

asynchronous-api

Asynchronous API handling with API Gateway, SQS and Lambda
TypeScript
2
star
28

graphql-backend

A simple GraphQL backend using SQLite as the db and Knex for queries
JavaScript
2
star
29

serverless-api

A basic API using Fastify built with the Serverless framework
JavaScript
2
star
30

sls-typegraphql

GraphQL app using TypeGraphQL and the Serverless Framework
TypeScript
2
star
31

cloud-resume

Cloud resume created using Next.js and deployed to AWS
JavaScript
2
star
32

rcomp

A React component generator made using Gluegun
TypeScript
2
star
33

gdg19-react-apollo

A React app with the Apollo client for fetching data from our backend
TypeScript
2
star
34

react-experimental

Experimenting with the latest React build and Concurrent mode using Snowpack
TypeScript
2
star
35

terraform-ecs

A sample Node app deployed to ECS and infrastructure created via Terraform
HCL
1
star
36

chat-frontend

Frontend for a simple chat application using AWS Amplify and React
TypeScript
1
star
37

ryands17

A Journey...
1
star
38

lambda-container

Running an ECR image with AWS Lambda created using the CDK
TypeScript
1
star
39

ec2-cfn-signal

This is a basic CDK project that demonstrates CloudFormation helpers
TypeScript
1
star
40

my-chrome-plugin

A Chrome plugin that displays various time zones and shows a random quote every time you open it
JavaScript
1
star
41

graphql-made-easy

GraphQL made easy with TypeScript and Codegen
JavaScript
1
star
42

optimise-tests

An example repo on running only changed tests
TypeScript
1
star
43

rust-snippets

A list of snippets created while learning Rust
Rust
1
star
44

tailwind-gallery

A basic image gallery created using TailwindCSS
TypeScript
1
star
45

step-fns

Exploring Step functions using the CDK
TypeScript
1
star
46

gdg19-prisma-ts

A Prisma server build with TypeScript using Nexus
TypeScript
1
star
47

absolute-paths

An effective hack to have absolute path support in TypeScript and Node
TypeScript
1
star
48

antd-theming

Changing the theme of Ant Design in create-react-app
JavaScript
1
star
49

ec2-session-manager-tf

An EC2 instance deployed in a VPC with Session Manager so SSH access is not required
TypeScript
1
star
50

aws-federation-github-actions

Deploy on AWS using GitHub OIDC
TypeScript
1
star
51

auth-flow

Auth flow with JWT using Access and Refresh tokens
TypeScript
1
star
52

delete-exposed-credentials

Deleting exposed AWS credentials using CloudWatch Events and the AWS Health API
TypeScript
1
star
53

prerender-simple

A simple routes prendering setup using puppeteer
JavaScript
1
star
54

node-beanstalk

A sample Node app deployed to AWS Elastic Beanstalk
JavaScript
1
star
55

lambda-ssm-cache

Cache SSM Paramter Store values in Lambda via CDK
TypeScript
1
star
56

amplify-auth

A sample repo showing authentication with Cognito handled by aws-amplify
TypeScript
1
star
57

thumbnail-creator

A CDK project to create a thumbnail using Fargate from a video uploaded to S3
TypeScript
1
star
58

svelte-basics

A sample Svelte app made with Snowpack
JavaScript
1
star
59

algorithms-rust

A set of basic algorithms created in Rust
Rust
1
star
60

prefetch-routes

Prefetching routes in CRA on link hover
TypeScript
1
star
61

svelte-ts

A TypeScript flavour of Svelte + Snowpack
CSS
1
star
62

swr-todos

A Todo app created using SWR and json-server
TypeScript
1
star
63

appsync-api

AppSync API with Cognito auth and custom scopes using SST
TypeScript
1
star
64

graphql-ts

A simple GraphQL example repo created using TypeScript
TypeScript
1
star
65

fullstack-gql

A Full Stack GraphQL app with Mercurius and Next.js
TypeScript
1
star