Introduction

GraphQL is a strongly typed query language for APIs and a server-side runtime for executing those queries with your existing data. GraphQL allows clients to fetch multiple resources from the server in a single request by giving clients the ability to specify the exact data needed in the query. This removes the need for multiple API calls. GraphQL is language and database independent, and thus can be implemented in almost every programming language alongside any database of choice.

In this tutorial, you will build a GraphQL-powered Ruby on Rails API for taking notes. When you are finished, you will be able to create and view notes from the API using GraphQL.

If you would like to take a look at the code for this tutorial, check out the companion repository for this tutorial on the DigitalOcean Community GitHub.

Prerequisites

To follow this tutorial, you’ll need:

  • The Ruby programming language and the Ruby on Rails framework installed on your development machine. This tutorial was tested on version 2.6.3 of Ruby and version 6.0.2.1 of Rails, so make sure to specify these versions during the installation process. Follow one of these tutorials to install Ruby and Rails:
  • How To Install Ruby on Rails with rbenv on Ubuntu 18.04
  • How To Install Ruby on Rails with rbenv on CentOS 7.
  • How To Install Ruby on Rails with rbenv on macOS.
  • PostgreSQL installed. To follow this tutorial, use PostgreSQL version 11.2. Install PostgreSQL by following Steps 1 and 2 of one of the following tutorials:
  • How To Use PostgreSQL with Your Ruby on Rails Application on Ubuntu 18.04
  • How To Use PostgreSQL with Your Ruby on Rails Application on macOS.
  • To develop this application on a different distribution of Linux or on another operating system, visit the official PostgreSQL downloads page. For more information on how to use PostgreSQL, visit How To Install and Use PostgreSQL.

#ruby on rail #api #postgresql #graphql #ruby

How to Set Up a Ruby on Rails GraphQL API
2.65 GEEK