This example demonstrates how to implement a data store with Prisma for a CLI tool (In this case a simple todo list).
Note:
prismais 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 deployoryarn prisma playground. If you have the Prisma CLI installed globally (which you can do withnpm install -g prisma), you can omit theyarnprefix.
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-toolNext, navigate into the downloaded folder and install the NPM dependencies:
cd cli-tool
yarn installYou 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 deployI don't have Docker installed on my machine
To deploy your service to a public cluster (rather than locally with Docker), you need to perform the following steps:
- Remove the
clusterproperty fromprisma.yml - Run
yarn prisma deploy - When prompted by the CLI, select a public cluster (e.g.
prisma-eu1orprisma-us1) - Replace the
endpointinindex.jswith the HTTP endpoint that was printed after the previous command
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 itemnode index.js listnode index.js delete First todo item