Skip to content

entrptaher/playground-prisma-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instructions

Step 1: Create database endpoint

Follow the instruction to install prisma and create a new demo prisma database. You will also find how to setup your own database using docker if you are interested.

You need the demo database url from that tutorial. You can skip this part if you already have another prisma endpoint.

Step 2: Update .env file

Create a .env file with the prisma api endpoint you got from step 1,

PRISMA_API=https://eu1.prisma.sh/abcdefg/hello-world/dev

Step 3: Install additional cli tools

graphql cli will help us generate schema from prisma automagically.

npm i -g graphql-cli prisma

Step 4: Deployment

Install all dependencies,

yarn install

Deploy the schema to endpoint,

prisma deploy

Start the app,

yarn start

Step 5: Enjoy

Open browser and go to the playground at http://localhost:4000

Queries

Get all users

query users {
  users {
    id
    name
  }
}

Mutations

# Create a user
mutation createUser{
  createUser(name: "POI"){
    id
    name
  }
}

# Update a user by id
mutation updateUser{
  updateUser(id: "cjwuaubca8d2j0b05hd22o9ih", name: "Bob Max") {
    id
    name
  }
}

Subscriptions

The following subscriptions are implemented with pub-sub,

subscription userAdded {
  userAdded {
    id
    name
  }
}

subscription userUpdated {
  userUpdated {
    id
    name
  }
}

The following is implemented with prisma-binding, it's a bit different then prisma-client on the resolver file,

subscription user{
  user{
    mutation
    node{
      id
      name
    }
    updatedFields
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published