The Battle: REST vs GraphQL

by Razvan Timis

About the presentation

  • What is GraphQL?
  • A blogging app: REST Vs GraphQL
  • REST Vs GraphQL
  • Who’s using GraphQL? Use cases
  • Coding on blogging app

What is GraphQL

  • A query language and server-side runtime for your API
  • Alternative to REST
Graphql diagram

A blogging app: REST vs GraphQL

  • A blogging application that need to display for a specific user: full name, posts, followers.
Blog App

A blogging app: REST vs GraphQL

REST Blogging request 1 REST Blogging request 2

A blogging app: REST vs GraphQL

Graphql Request

A blogging app: REST vs GraphQL

Let see how the GraphQL schema look

            
              type Query {
                User(id: String): User
              }
              type User {
                name: String
                age: Int
                posts: [Post]
                followers(last: Int):[Follower]
              }
              type Post {
                title: String
                content: String
              }
              type Follower {
                name: String
                age: Int
              }
              type Mutation {
                addUser(name: String, age: Int): User
              }
            
          

REST Vs GraphQL

  • No more over fetching extra data.
  • Graphql Request
  • No more under fetching data.
  • Graphql Request
  • API changes and evolution
              
                type User {
                  name: String @deprecated(reason: "Use `fullName`")
                  fullName: String
                  age: Int
                  posts: [Post]
                  followers(last: Int):[Follower]
                }
              
            

A directive can be attached to a field or fragment inclusion, and can affect execution of the query in any way the server desires. more...

  • Single endpoint
  • Graphql single endpoint
  • Insightful Analytics: low-level performance monitoring and usage of each field
  • Graphql Analytics
  • Documentation comes with no extra cost
  • Graphql documentation

Who’s using GraphQL

For more... click here

Use case #1

Netflix studio

Studio Engineering is building hundreds of applications and tools that power these workflows.

Use case #1 problem

Netflix studio

One of the pains in the studio space was the growing complexity of the data and its relationships

Use case #1 solution

Netflix offers a unified API aggregation layer at the edge

Netflix federation

Use case #2

Dynamic page is constructed based on a query that will return an array of some set of possible “sections”

Use case #2

GraphQL Unions for Backend-Driven UI

Airbnb Schema

Coding on blogging app

Thank you!

References