Jade Bird

Jade Bird

1600481462

Building a Basic Polling GraphQL Server with Prisma

We’ll be building a basic polling GraphQL server. Some understanding of Prisma will make it easier to go along with this article.

Introduction

Prisma is an open-source database toolkit that replaces traditional ORMs. It makes database access easy with an auto-generated query builder for TypeScript and Node. js. Using only an intuitive API and plain old JavaScript objects, it enables a developer to only worry about the data and not the native database queries to get data.

Prisma consists of the following parts:

  • Prisma Client — auto-generated and type-safe query builder for Node.js and TypeScript
  • Prisma Migrate (experimental) — declarative data modeling and migration system
  • Prisma Studio (experimental) — GUI to view and edit data in your database

The databases currently supported by Prisma are PostgreSQL, MySQL, SQLite. In this article, we will be building a basic polling GraphQL server. Some understanding of Prisma will make it easier to go along with this article.

Prerequisites

As mentioned earlier basic knowledge of Prisma and Node.js will be necessary to follow along. Ensure that you have Node and Yarn, or npm installed on your machine.

Getting started

The first thing we need to do is install Prisma 2 globally. If you have an earlier version of Prisma installed, you will need to uninstall it first before you continue. To install Prisma, run any of the following commands in your terminal:

npm install -g @prisma/cli
yarn global add @prisma/cli

Setup

Let’s create the folder structure for our voting server:

$ mkdir voting-app
$ cd voting-app
$ touch README.md index.js .gitignore

You can add a description of what your server does in the README.md. You should also add the node_modules folder to the .gitignore file like so:

node_modules/

To generate the package.json file without prompts, run the following command:

$ npm init -y

The contents of the package.json file will look something like this:

{
  "name": "voting-app",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Install dependencies

$ yarn add graphql-tools graphql-yoga

#graphql #prisma #typescript #node #programming

Building a Basic Polling GraphQL Server with Prisma