This repo contains multiple tutorials as listed below. We will go over them one by one.
- CRUD operations ( in-memory storage )
- Using SQLite DB ( persistent storage)
- Nodejs
- NPM
- Clone the repo GraphQL-Nodejs
- cd GraphQL-With-Nodejs
- npm install
- node src/crud.js
- Open browser and enter the url http://localhost:4000/
Get data
feed{
id,
url,
description
}
}
Create data
mutation {
post(url: "www.prisma.io", description: "Prisma replaces traditional ORMs") {
id
}
}
Update data
mutation {
updateLink(id: "link-1", url: "www.xyz.io", description: "xyz") {
id,
url,
description
}
}
Delete data
mutation {
deleteLink(id: "link-1") {
id,
url,
description
}
}
In this section, we are going to set up a SQLite to persist the data of incoming GraphQL mutations. Instead of writing SQL directly, we will use Prisma to access your database. Prisma is an open source database toolkit that makes it easy for developers to reason about their data and how they access it, by providing a clean and type-safe API for submitting database queries.
In addition to the steps given in tutorial 1, please add below steps
- npm install prisma --save-dev
- npm install @prisma/client
- npx prisma init
- npx prisma migrate dev ( You will get a prompt asking you to provide a name for the migration. Let’s name it “init”. Type in the name and hit Enter )
- npx prisma generate
- node src/index.js
Get data
feed{
id,
url,
description
}
}
Create data
mutation {
post(url: "www.prisma.io", description: "Prisma replaces traditional ORMs") {
id
}
}
Run npx prisma studio
. The command should open a tab in your browser automatically (running on http://localhost:5555) showing a visual representation of your tables and data.
Tutorial reference - https://www.howtographql.com/graphql-js/1-getting-started/