SlideShare a Scribd company logo
GraphQL vs REST
Maximilianos GJ Panas
Software Engineer@AgileActors
@mgjp_
Stelios Charmpalis
Software Engineer@AgileActors
@SteliosHarb
AgileActors Blog
REpresentational State Transfer
HTTP verbs(GET, POST, PUT, DELETE)
Resource Based URLs - Endpoints (/ᴀ各lms/24)
REST(ful) API
 22. GET /characters/34 
 23. { 
 24.   "id": 34, 
 25.   "name": "Luke Skywalker",
 26.   "birthYear": "1", 
 27.   "eyeColor": "blue", 
 28.   "gender": "male", 
 29.   "hairColor": "blond", 
 30.   "height": 172, 
 31.   "mass": 77, 
 32.   "skinColor": "fair" 
 33. } 
 34.  
 35.  
 18.   [ 
 19.     "/characters/34", 
 20.     "/characters/35" 
 21.   ] 
 36.  
 37.  
 38.  
 39.  
 40.  
Retrieves the info about the `characters` with ID `34`
GraphQL vs REST
It is a period of civil war....
GET /films/1
{ 
  "id": 1, 
  "title": "A New Hope", 
  "episodeID": 4, 
  "openingCrawl": "It is a period...", 
  "poster": "http://...", 
  "releaseDate": "2002‐05‐16", 
  "created": "2014‐12‐20T10:57:57.886Z", 
  "edited": "2014‐12‐20T20:18:48.516Z" 
}
PM (Project Manager)
Film Card using a RESTful API
A New Hope
Episode 4
It is a period of civil war....
Characters
{ 
  "id": 1 
  "title": "A New Hope", 
  ... 
}
# 4 different queries 
1. GET /films/1 
2. GET /films/1/characters 
3. GET /character/34 
4. GET /character/35
# 1 Request ‐ Add boolean query string 
GET /films/1?include_character_details=true
# 1 Request ‐ New custom endpoint 
GET /films_with_character_details/1
Film Card using a RESTful API
A New Hope
Episode 4
Luke Skywalker
C­3PO
/* JSON Response */ 
{ 
  "id": 1, 
  "title": "A New Hope", 
  "episodeID": 4, 
  "openingCrawl": "It is a period...", 
  "poster": "http://...", 
  "releaseDate": "2002‐05‐16", 
  "created": "2014‐12‐20T10:57:57.886Z", 
  "edited": "2014‐12‐20T20:18:48.516Z", 
  "characters": [ 
    { 
      "id": 35, 
      "name": "C‐3PO", 
      "birthYear": "112BBY", 
      "eyeColor": "yellow", 
      "gender": "n/a", 
      "hairColor": "n/a", 
      "height": 167, 
      "mass": 75, 
      "skinColor": "gold", 
      "avatar": "http://..." 
    }, { 
    ... 
  }] 
} 
/* JSON Response */ 
{ 
  "title": "A New Hope", 
  "episodeID": 4, 
  "openingCrawl": "It is a period...", 
  "poster": "http://...", 
  "characters": [ 
    { 
      "name": "C‐3PO", 
      "avatar": "http://..." 
    }, { 
    ... 
  }] 
}
SIMPLIFY JSON RESPONSE
/* GraphQL Request */ 
{ 
  title 
  episodeID 
  openingCrawl 
  poster 
  characters { 
    name 
    avatar 
  } 
}
/* JSON Response */ 
{ 
  "title": "A New Hope", 
  "episodeID": 4, 
  "openingCrawl": "It is a period...", 
  "poster": "http://...", 
  "characters": [ 
    { 
      "name": "C‐3PO", 
      "avatar": "http://..." 
    }, { 
    ... 
  }] 
}
A GRAPHQL REQUEST
Eliminate Overfetching
Eliminate Underfetching
Be Declarative
Increase Product Developer Autonomy
Natively Support Versioning
CORE GOALS
HELLO WORLD
{ 
  bestFilm { 
    title 
  } 
}
{ 
  "bestFilm": { 
    "title": "The Empire Strikes Back" 
  } 
}
ARGUMENTS
{ 
  film(id: 1) { 
    title 
  } 
}
{ 
  "film": { 
    "title": "A New Hope" 
  } 
}
COMPLEX QUERIES
{ 
  film(id: 1) { 
    title 
    poster { 
      width 
      height 
      url 
    } 
  } 
}
{ 
  "film": { 
    "title": "A New Hope", 
    "poster": { 
      "width": 300, 
      "height": 300, 
      "url": "https://..." 
    } 
  } 
}
NODES WITHIN NODES
{ 
  film(id: 1) { 
    title 
    poster(size: 1000) { 
      width 
      height 
      url 
    } 
  } 
}
{ 
  "film": { 
    "title": "A New Hope", 
    "poster": { 
      "width": 1000, 
      "height": 1000, 
      "url": "https://..." 
    } 
  } 
}
ALIASES
{ 
  film(id: 1) { 
    title 
    regularPic: poster(size: 500) { 
      width 
      height 
      url 
    } 
    retinaPic: poster(size: 1000) { 
      width 
      height 
      url 
    } 
  } 
}
{ 
  "film": { 
    "title": "A New Hope", 
    "normalPic": { 
      "width": 500, 
      "height": 500, 
      "url": "https://..." 
    }, 
    "retinaPic": { 
      "width": 1000, 
      "height": 1000, 
      "url": "https://..." 
    } 
  } 
}
NESTED QUERIES
{ 
  film(id: 1) { 
    title 
    characters { 
      name 
      films { 
        title 
        characters { 
          name 
        } 
      } 
    } 
  } 
}
{ 
  "film": { 
    "title": "A New Hope", 
    "characters": [{ 
      "name": "Yoda" 
      "films": [{ 
        "title": "The Empire Strikes Back", 
        "characters": [{ 
          "name": "Luke Skywalker" 
        }, { 
          "name": "Han Solo" 
        }] 
      }, { 
        "title": "Return of the Jedi", 
        "characters": [{ 
          "name": "C‐3PO" 
        }, { 
          ... 
        }] 
      }] 
    }, { 
HOW GRAPHQL
WORKS
User-Deᴀ各ned type system - "schema"
Data Universe is deᴀ各ned and connected on the server
Multiple Back-end services exposed through a single
controlled API
The client requests for exactly what it wants
TYPE SYSTEM (SCHEMA)
type Root { 
  bestFilm: Film 
  film(id: Int!): Film 
} 
type Film { 
  title: String 
  poster(size: Int = 300): Picture 
  characters: [Person] 
}
type Person { 
  name: String 
  films: [Film] 
} 
type Picture { 
  width: Int 
  height: Int 
  url: String 
}
GRAPHQL-JS
const Root = new GraphQLObjectType({ 
  name: 'Root', 
  description: 'The starting point of your GraphQL query', 
  fields: () => ({ 
    bestFilm: { 
      type: Film, 
      resolve: (root, args, context) => api.getTop('film') 
        .then(id => api.getFilm(id)), 
    }, 
    film: { 
      type: Film, 
      args: { id: { type: new GraphQLNonNull(GraphQLInt) } }, 
      resolve: (root, args, context) => api.getFilm(args.id), 
    }, 
  }), 
});
Demo with GraphiQL
GraphQL is not bound by any client framework
Ways of using it on the client
Relay (Speciᴀ各cally for React)
Lokka (Simplest lib, can be used with anything)
Others (Apollo, XHR, etc.)
Queries can easily be broken apart andmerged together
again
Declare exactly what your data requirements are on the
component layer
THE CLIENT STORY
GraphQL is a speciᴀ各cation of a communication protocol, not a storage
system, not a library
GraphQL is not tied to a speciᴀ各c language or framework
GraphQL does not allow clients to arbitrarily query your database(s)
GraphQL does not require a speciᴀ各c backend storage system
Security: Authentication is handled the same way as in REST
POSSIBLE MISCONCEPTIONS
Handling Resource intensive Queries on the Backend
- facebook/Dataloader
Handling errors in resolvers
- khadira/graphql-errors
Granular Control on querying
- @defer, @async, @stream
Live Queries
- Subscriptions
PRACTICAL PROBLEMS
GraphQL Introduction
GraphQL
Learn GraphQL
Zero to GraphQL in 30 Minutes – Steven Luscher
From REST to GraphQL
Validation and User Errors in GraphQL Mutations
Presentation built with Spectacle
USEFUL LINKS
THANK YOU!
Any questions?
GraphQL vs REST

More Related Content

PPT
Graphql presentation
PPTX
Introduction to GraphQL Presentation.pptx
PDF
Intro to GraphQL
PPTX
Introduction to GraphQL
PPTX
Introduction to GraphQL
PPTX
An intro to GraphQL
PDF
REST vs GraphQL
PDF
Introduction to GraphQL
Graphql presentation
Introduction to GraphQL Presentation.pptx
Intro to GraphQL
Introduction to GraphQL
Introduction to GraphQL
An intro to GraphQL
REST vs GraphQL
Introduction to GraphQL

What's hot (20)

PDF
GraphQL Fundamentals
PDF
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
PDF
REST vs. GraphQL: Critical Look
PDF
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
PDF
GraphQL: Enabling a new generation of API developer tools
PDF
Better APIs with GraphQL
PPTX
Intro GraphQL
PDF
Designing APIs with OpenAPI Spec
PPTX
Introduction to graphQL
PPTX
GraphQL Introduction
PDF
Spring Framework - AOP
PDF
Spring GraphQL
PPTX
REST API Design & Development
PDF
What is REST API? REST API Concepts and Examples | Edureka
PPTX
Api gateway in microservices
PPTX
Introduction to Spring Framework
PDF
React & GraphQL
PDF
The Apollo and GraphQL Stack
PDF
Introduction to OpenID Connect
PDF
GraphQL Fundamentals
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
REST vs. GraphQL: Critical Look
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL: Enabling a new generation of API developer tools
Better APIs with GraphQL
Intro GraphQL
Designing APIs with OpenAPI Spec
Introduction to graphQL
GraphQL Introduction
Spring Framework - AOP
Spring GraphQL
REST API Design & Development
What is REST API? REST API Concepts and Examples | Edureka
Api gateway in microservices
Introduction to Spring Framework
React & GraphQL
The Apollo and GraphQL Stack
Introduction to OpenID Connect
Ad

Viewers also liked (20)

PDF
GraphQL
PDF
Work with V8 memory leaks
PDF
Migration microservices to GraphQL
PDF
Introduction to GraphQL at API days
PDF
GraphQL Story: Intro To GraphQL
PPTX
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
PDF
The case for HTTP/2
PPTX
The history of asynchronous JavaScript
PPTX
Ellak JavaScript Day
PPTX
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
PDF
The tools & technologies behind Resin.io
PDF
GraphQL IndyJS April 2016
PDF
Zensations Drupal 8 GraphQL Presentation 2015
PPTX
Taking Control of your Data with GraphQL
PPTX
GraphQL Relay Introduction
PPTX
Relay: Seamless Syncing for React (VanJS)
PPT
Enterprise API deployment best practice
PDF
API Introduction - API Management Workshop Munich from Ronnie Mitra
PPTX
API Athens Meetup - API standards 25-6-2014
GraphQL
Work with V8 memory leaks
Migration microservices to GraphQL
Introduction to GraphQL at API days
GraphQL Story: Intro To GraphQL
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The case for HTTP/2
The history of asynchronous JavaScript
Ellak JavaScript Day
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
The tools & technologies behind Resin.io
GraphQL IndyJS April 2016
Zensations Drupal 8 GraphQL Presentation 2015
Taking Control of your Data with GraphQL
GraphQL Relay Introduction
Relay: Seamless Syncing for React (VanJS)
Enterprise API deployment best practice
API Introduction - API Management Workshop Munich from Ronnie Mitra
API Athens Meetup - API standards 25-6-2014
Ad

Similar to GraphQL vs REST (20)

PPTX
Graph ql vs rest
PDF
GraphQL as a REST API alternative
PDF
Introducing GraphQL
PDF
Introduction to REST - REST Basics - JSON
PPTX
REST API vs. GraphQL: Which Should You Pick for Your Project?
PPTX
Rest with Java EE 6 , Security , Backbone.js
PPTX
PDF
GraphQL in an Age of REST
PPTX
GraphQL vs REST
PDF
GraphQL with .NET Core Microservices.pdf
PPTX
GraphQL API Gateway and microservices
PDF
PPTX
API Design Antipatterns - APICon SF
PPTX
The API Journey: from REST to GraphQL
PDF
Building Restful Applications Using Php
PPT
emilio.ppt
PPT
emilio.ppt
PDF
Overview of GraphQL & Clients
PDF
GraphQL - A love story
PDF
Intro to GraphQL
Graph ql vs rest
GraphQL as a REST API alternative
Introducing GraphQL
Introduction to REST - REST Basics - JSON
REST API vs. GraphQL: Which Should You Pick for Your Project?
Rest with Java EE 6 , Security , Backbone.js
GraphQL in an Age of REST
GraphQL vs REST
GraphQL with .NET Core Microservices.pdf
GraphQL API Gateway and microservices
API Design Antipatterns - APICon SF
The API Journey: from REST to GraphQL
Building Restful Applications Using Php
emilio.ppt
emilio.ppt
Overview of GraphQL & Clients
GraphQL - A love story
Intro to GraphQL

More from GreeceJS (13)

PDF
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
PDF
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
PDF
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
PDF
Under the hood of RxJS (Dimitris Livas) - GreeceJS #27
PDF
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
PDF
Cross platform engineering - Lessons Learned (Michael Asimakopoulos, Valadis ...
PDF
TypeScript: JavaScript that scales (Kostas Stergiou) - GreeceJS #22
PDF
Migrating from Monolithic to Serverless (Kostas Katsikas) - GreeceJS #22
PDF
Taming forms with React
PDF
The JavaScript toolset for development on Ethereum
PDF
Modern web development and accessibility (Christina Papadimitriou, Nadia Mark...
PDF
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
PDF
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
Under the hood of RxJS (Dimitris Livas) - GreeceJS #27
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
Cross platform engineering - Lessons Learned (Michael Asimakopoulos, Valadis ...
TypeScript: JavaScript that scales (Kostas Stergiou) - GreeceJS #22
Migrating from Monolithic to Serverless (Kostas Katsikas) - GreeceJS #22
Taming forms with React
The JavaScript toolset for development on Ethereum
Modern web development and accessibility (Christina Papadimitriou, Nadia Mark...
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Dropbox Q2 2025 Financial Results & Investor Presentation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Understanding_Digital_Forensics_Presentation.pptx

GraphQL vs REST