Instructor: Make sure you have at least Prisma 1.8 installed by running prisma-v. Then you can initialize in your Prisma project using the prisma-init command and naming the project database. Prisma is completely open source, so you can create a database locally, or you can use a demo server.
You can peek where you want the server to be hosted, and then give it a name. We can go with to-do database. Then make the stage div. Let's have a look at the files that prisma-init generates. The database folder has a datamodel.graphql and a prisma.yml file.
Data model contains the model for your database. This is where you define the database schema. The prisma.yml is the configuration that connects to your server on the data module. Let's update the todomodule.graphql to have the to-do type.
The to-do type can have some fields. The first field we want to have is the title of the to-do, which is of type string, and a completed field, which is of type Boolean. We should also add an ID field to serve as the unique identifier for each record.
Let's head back to the command and cd into the database folder, then run prisma deploy to deploy our project.
After deploying, you can copy the HTTP link and open in a browser. Pasting it in the browser, it should load the Prisma playground. Then you can inspect the schema by clicking the schema tab. You can see we have the queries where you can fetch the to-dos, each to-do item. It creates to-do mutation, it updates to-do mutation, and so on.
In fact, we can test the create to-do mutation by creating a mutation query and calling the create to-do mutation. We can pass in the title, which can be Cook, and completed, of course. It's false by default. We can return the title and the completed field when the mutation is successful.
Let's run this mutation by clicking the play button. Here you have it. It returns the created to-do, which is Cook. Of course, it's not completed. We can also query the database to see if that mutation was actually successful.
We should have the to-dos, and we should just return the title and the completed field. We can also return the ID as well. There you have it. We have the Cook and the completed is set to false. The ID is actually generated by the database.
Without writing any server code, you can actually go ahead and connect your client application to this API endpoint. Then you can start querying your database and creating to-dos.