Skip to content
Branch: master
Find file History
Latest commit 4e481ef Aug 15, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
client run ts-lint on examples/typescript Jun 26, 2019
prisma rename project.prisma -> schema.prisma Jul 9, 2019
server run ts-lint on examples/typescript Jun 26, 2019
README.md rename Photon JS to Photon.js (#186) Aug 12, 2019
package.json add ts-node as dev dep Jun 26, 2019
service.proto Add password field to SignupUserRequest Jul 4, 2019
tsconfig.json Update tsconfig.json Aug 15, 2019
yarn.lock

README.md

gRPC Server Example

This example shows how to implement a gRPC API with TypeScript and Photon.js.

How to use

1. Download example & install dependencies

Clone the repository:

git clone git@github.com:prisma/photonjs.git

Install Node dependencies:

cd photonjs/examples/typescript/grpc
npm install

2. Install the Prisma 2 CLI

To run the example, you need the Prisma 2 CLI:

npm install -g prisma2

3. Set up database

For this example, you'll use a simple SQLite database. To set up your database, run:

prisma2 lift save --name 'init'
prisma2 lift up

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 prisma2 lift up.

4. Generate Photon (type-safe database client)

Run the following command to generate Photon.js:

prisma2 generate

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

npm run seed

5. Start the gRPC server

npm run start

The server is now running on 0.0.0.0:50051.

6. 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:

Screenshot of BloomRPC

Next steps

You can’t perform that action at this time.