Skip to content
Branch: master
Find file History
Latest commit 8ccfa80 May 29, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
client minor improvements Jan 29, 2019
prisma adjust datamodel to v1.1 Apr 15, 2019
server add TS grpc example Feb 4, 2019
README.md update to v1.34 May 28, 2019
package.json Update dependency prisma-client-lib to v1.34.0 May 29, 2019
service.proto add gRPC example and do seeding based on js files Jan 29, 2019

README.md

gRPC Server Example

This example shows how to implement a gRPC API with Node.js and Prisma.

How to use

1. Download example & install dependencies

Clone the repository:

git clone git@github.com:prisma/prisma-examples.git

Install Node dependencies:

cd prisma-examples/node/grpc
npm install

2. Install the Prisma CLI

To run the example, you need the Prisma CLI. Please install it via NPM or using another method:

npm install -g prisma

3. Set up database & deploy Prisma datamodel

For this example, you'll use a free demo database (AWS Aurora) hosted in Prisma Cloud. To set up your database, run:

prisma deploy

Then, follow these steps in the interactive CLI wizard:

  1. Select Demo server
  2. Authenticate with Prisma Cloud in your browser (if necessary)
  3. Back in your terminal, confirm all suggested values
Alternative: Run Prisma locally via Docker
  1. Ensure you have Docker installed on your machine. If not, you can get it from here.
  2. Create docker-compose.yml for MySQL (see here for Postgres):
    version: '3'
    services:
      prisma:
        image: prismagraphql/prisma:1.34
        restart: always
        ports:
        - "4466:4466"
        environment:
          PRISMA_CONFIG: |
            port: 4466
            databases:
              default:
                connector: mysql
                host: mysql
                port: 3306
                user: root
                password: prisma
                migrations: true
      mysql:
        image: mysql:5.7
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: prisma
        volumes:
          - mysql:/var/lib/mysql
    volumes:
      mysql:
  3. Run docker-compose up -d
  4. Set the endpoint in prisma.yml to http://localhost:4466
  5. Run prisma deploy

You can now use Prisma Admin to view and edit your data by appending /_admin to your Prisma endpoint.

4. Start the gRPC server

npm run start

The server is now running on 0.0.0.0:50051.

5. Using the gRPC API

To use the gRPC API, you need a gRPC client. We provide several client scripts inside the ./client directory. Each script is named according to the operation it performs against the gRPC API (e.g. the feed.js script sends the Feed operation). Each script can be invoked by running the corresponding NPM script defined in package.json, e.g. npm run feed.

In case you prefer a GUI client, we recommend BloomRPC:

Next steps

You can’t perform that action at this time.