This example demonstrates how to implement a data store with Prisma for a CLI tool (In this case a simple todo list). Note that typically you would deploy Prisma behind an application server.
Note:
prisma
is listed as a development dependency and script in this project'spackage.json
. This means you can invoke the Prisma CLI without having it globally installed on your machine (by prefixing it withyarn
), e.g.yarn prisma deploy
oryarn prisma playground
. If you have the Prisma CLI installed globally (which you can do withnpm install -g prisma
), you can omit theyarn
prefix.
Clone the Prisma monorepo and navigate to this directory or download only this example with the following command:
curl https://codeload.github.com/graphcool/prisma/tar.gz/master | tar -xz --strip=2 prisma-master/examples/cli-tool
Next, navigate into the downloaded folder and install the NPM dependencies:
cd cli-tool
yarn install
You can now deploy the Prisma service (note that this requires you to have Docker installed on your machine - if that's not the case, follow the collapsed instructions below the code block):
yarn prisma deploy
I don't have Docker installed on my machine
To deploy your service to a demo server (rather than locally with Docker), please follow this link.
The Prisma database service that's backing your GraphQL server is now available. This means you can now start to test the CLI Tool:
node index.js add First todo item
node index.js list
node index.js delete First todo item
The easiest way to explore this deployed service and play with the API generated from the data model is by using the GraphQL Playground.
You can either start the desktop app via
yarn playground
Or you can open a Playground by navigating to http://localhost:4466/cli-tool in your browser.
query Todoes {
todoes(orderBy: id_DESC) {
id
title
}
}