Goals

Get to know the fundamentals of GraphQL: understand the query language and its runtime. Design and implement a GraphQL API, and learn the differences between it and REST.

Examples

Exercises

Introduction

Context

Client and Server

In a distributed system, multiple systems must communicate with one another. On the web, a client (e.g. a browser or a server) wants to communicate with a server (e.g. a web service). To facilitate this, the server provides an application programming interface (API). These APIs can be implemented using various architectural styles and technologies.

client_server.svg

Client–server model

Request-Response Pattern

The Request-Response Pattern is a communication pattern between two systems, where one system (the client) sends a request to the other system (the server) and the server responds with a response. This pattern is the basis for communication between a client and a server in a distributed system. The request contains information about the operation that should be performed and the parameters for the operation. The response contains the result of the operation. The request-response pattern is synchronous, which means that the client blocks until the server sends a response.

tanenbaum_client_server.svg

Request–response

Preparation

In this topic**,** we will create a GraphQL service that manages tasks for projects. For this, we use the Hasura Platform to quickly map a Postgres database schema to a GraphQL API.

Screenshot 2023-02-03 at 11.37.03.png

Instant GraphQL APIs on your data | Built-in Authz & Caching

Checkout source code

To start, we checkout the example source code from:

topics/graphql/tasks · main · hs-heilbronn / fankhauser · GitLab

Start the stack

Next, we start the Hasura stack. This will run a server at [http://localhost:8080](<http://localhost:8080>):

docker compose up

Create tables

Now, we create a projects table with an id and a name column: