SlideShare a Scribd company logo
For internal use only
Introduction to
GraphQL
For internal use only
Rest – REST in peace
LonglivetoGraphQL
Hello GraphQL
Reviews from Developers
++
For internal use only
Index
 History
 What is GraphQL
 Introduction
 Rapidly Growing community
 Alternative to Rest
 CRUD in GraphQL
For internal use only
History
 Invented by Facebook
 Presented publically at React JS Conference in 2015 and made open source
 Specification stable version – 2018
 Find releases - https://graphql.github.io/graphql-spec/
2012
Development
Started
2015
Open Sourced
2016 2017 2018 2019
Evolving specification
For internal use only
What is GraphQL
• GraphQL is a query language for APIs and a runtime for fulfilling
those queries with your existing data.
• GraphQL provides a complete and understandable description of the
data in your API, gives clients the power to ask for exactly what they
need and nothing more, makes it easier to evolve APIs over time, and
enables powerful developer tools.
• GraphQL is not a database, it’s a specification
For internal use only
Introduction
 Provides an efficient, powerful and flexible approach to developing web
APIs
 Enables declarative data fetching
 Exposes Single endpoint and responds to queries
 Alternative to REST Services
 Graph QL is not only for React Developers
 It can be used with any programming language and framework
For internal use only
A Rapidly growing Community
Find more Users - https://graphql.org/users/
For internal use only
What we need
• User
• Users Posts
• Follower (likes)
• Commenters
For internal use only
Data Fetching with REST
For internal use only
Data Fetching with GraphQL
For internal use only
Single Endpoint vs Multiple Endpoints
Img Reference - https://blog.apollographql.com/graphql-vs-rest-5d425123e34b
For internal use only
Data Over fetching
{
"userName" : "moredee", "firstName" :
"Deepak",
"lastName" : "More",
"isActive" : "true",
"email" : "deepak.more@db.com",
"contactNumber" : "9420390095",
"city" : "Pune”
….
}
{
"userName" : "moredee", "firstName" :
"Deepak",
"lastName" : "More",
}
URL – /get/user/10
For internal use only
Data Under fetching
{
"userName" : "moredee", "firstName" :
"Deepak",
"lastName" : "More",
"isActive" : "true",
"email" : "deepak.more@db.com",
"contactNumber" : "9420390095",
….
}
{
"userName" : "moredee", "firstName" :
"Deepak",
"lastName" : "More",
“Address” : [
…
]
}
{
“id" : “123",
“address Line" : “Nagras Road",
“address Line 1" : “Aundh",
“city" : “Pune",
“State" : “Maharashtra",
“PinCode" : “411007",
….
}
URL – /user/10
URL – /address/123
For internal use only
Problem with Advanced requests
 Rest Api - GET /users/1/friends/1/dogs/1?include=user.name,dog.age
 GraphQL :
query {
user(id: 1) {
friends {
dogs {
name
}
}
}
}
For internal use only
GraphQL vs REST Comparison
Points REST GraphQL
EndPoints Multiple Single
Fetching data Over fetching and Under fetching Fetch Exact Data
Dependency on Endpoint Highly Dependent Not Dependent
Production Iteration at Frontend Slower Faster
Advanced Request Complex Easy
For internal use only
GraphQL Type System
 Object Types
 Interfaces
 Unions
 Enumerations
 Fields
 List
 Scaler Types
 Int
 Float
 String
 Boolean
 Id (serialized in String)
For internal use only
Schema Basics
 GraphQL has its own type system that’s used to define the schema of an API.
The syntax for writing schemas is called Schema Definition Language (SDL).
 The ! following the type means that this field is required.
type User {
name: String!
contactNo: Int!
posts: [Post!]
}
type Post{
name: String!
author: User!
}
User Post
1 N
For internal use only
CRUD in GraphQL
 Graph QL Operations
 Query - use to read a data
 Mutation - use to write a data
 Subscriptions - use to listen for data
query {
search(id: “123456"){
name
posts(last: 1) {
title
}
followers {
name
}
}
}
Mutation {
createUser(name: “Deepak“, age: 28){
id
}
Subscription {
onCreate {
name
age
}
}
For internal use only
Self Explanatory
query{
book(isbn: “SEBT125") {
name
author {
firstname
lastName
}
}
Give me the book with isbn=“SEBT125"
Give me the book's name
Give me the book's author
Give me the author's first name
Give me the author’s last name
For internal use only
GraphQL Execution Engine
 Parse Query from Client
 Validate Schema
 Return JSON response
 Executes resolvers for each field
For internal use only
Server Architecture
/graphql
(Single
endpoint)
Dao Layer
Business
Layer
Schema
Validation
Layer
Resolvers
(Query,
Mutation,
Subscription)
/graphiql
(Editor)
For internal use only
2 Ways to access GraphQL App
 GraphQL Editor Application – (Windows)
 https://electronjs.org/apps/graphiql
 GraphiQL Server Utility
 Localhost:8080/graphiql
For internal use only
Validation / Error Handling GraphQL
Error status :
{
"data": null,
"errors": [
{
"message": "Cannot query field ‘names' on type ‘Book'. Did you mean ‘name'? (line 52,
column 5):n namen ^",
"locations": [
{
"line": 52,
"column": 5
}
]
}
]
}
query {
searchbook(name: “java") {
names
author {
firstname
lastName
}
}
For internal use only
Demo
 Used Technologies
 Node Js, Express, MySQL Database (Server Configuration)
 ReactJS, Websockets, Apollo Client (Using React Render Props)
 Demo Covers :
 Book Creation
 Subscription
For internal use only
How to do Server-side Caching
 Server-side caching still is a challenge with GraphQL.
For internal use only
1) Should I stop Using Rest API Now?
2) Should I migrate current application to
GraphQL?
Answer is No
For internal use only
Authentication and Authorization in GraphQL
 Authentication can be done by using Oauth
 To implement authorization, it is recommended to delegate any data
access logic to the business logic layer and not handle it directly in the
GraphQL implementation.
For internal use only
Disadvantages
 You need to learn how to set up GraphQL. The ecosystem is still rapidly
evolving so you have to keep up.
 You need to define the schema beforehand => extra work before you get
results
 You need to have a GraphQL endpoint on your server => new
libraries that you don't know yet
 The server needs to do more processing to parse the query and verify the
parameters
For internal use only
Resources
 Find libraries for technologies –
 https://graphql.org/code/
 Editor -
 https://lucasconstantino.github.io/graphiql-online/
For internal use only
References
 https://graphql.org/learn/
 https://www.howtographql.com/
 https://blog.apollographql.com/graphql-vs-rest-5d425123e34b
For internal use only
Demo
 Used Technologies
 Spring Boot, h2 Database (Server Configuration)
 ReactJS, Apollo Client (Using React Render Props)
 Demo Covers :
 Book Creation
 Book Deletion
 Books List

More Related Content

PPT
Graphql presentation
PPTX
Introduction to GraphQL
PDF
REST vs GraphQL
PPTX
Introduction to GraphQL
PDF
GraphQL
PDF
Graphql
PPTX
An intro to GraphQL
PDF
GraphQL: Enabling a new generation of API developer tools
Graphql presentation
Introduction to GraphQL
REST vs GraphQL
Introduction to GraphQL
GraphQL
Graphql
An intro to GraphQL
GraphQL: Enabling a new generation of API developer tools

What's hot (20)

PDF
Intro to GraphQL
PPTX
GraphQL Introduction
PDF
Spring GraphQL
PDF
Introduction to GraphQL
PPTX
Introduction to graphQL
PDF
GraphQL Advanced
PDF
How to GraphQL
PDF
PPTX
Selenium WebDriver training
PPTX
JVM++: The Graal VM
PDF
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
PPTX
How and Why GraalVM is quickly becoming relevant for developers (ACEs@home - ...
PDF
Jenkins-CI
PDF
GraphQL Fundamentals
PPTX
Angular 4 and TypeScript
PPTX
GraphQL API Gateway and microservices
PDF
How to GraphQL: React Apollo
PDF
React & GraphQL
PDF
REST APIs with Spring
PPTX
Graph QL Introduction
Intro to GraphQL
GraphQL Introduction
Spring GraphQL
Introduction to GraphQL
Introduction to graphQL
GraphQL Advanced
How to GraphQL
Selenium WebDriver training
JVM++: The Graal VM
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
How and Why GraalVM is quickly becoming relevant for developers (ACEs@home - ...
Jenkins-CI
GraphQL Fundamentals
Angular 4 and TypeScript
GraphQL API Gateway and microservices
How to GraphQL: React Apollo
React & GraphQL
REST APIs with Spring
Graph QL Introduction
Ad

Similar to Introduction to Graph QL (20)

PDF
Introduction to GraphQL for beginners
PDF
GraphQL over REST at Reactathon 2018
PDF
GraphQL with .NET Core Microservices.pdf
PDF
GraphQL Bangkok meetup 5.0
PDF
Graphql usage
PPTX
GraphQL.pptx
PPTX
GraphQL.pptx
PDF
GraphQL- Presentation
PDF
GraphQL for Native Apps
PPTX
GraphQL API Crafts presentation
PDF
Apollo server II
PDF
PPTX
GraphQL - an elegant weapon... for more civilized age
PDF
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
PDF
Why UI developers love GraphQL
PDF
GraphQL across the stack: How everything fits together
PDF
All you need to know about GraphQL.pdf
PPTX
GraphQL Introduction with Spring Boot
PPTX
CONDG April 23 2020 - Baskar Rao - GraphQL
PDF
Modern APIs with GraphQL
Introduction to GraphQL for beginners
GraphQL over REST at Reactathon 2018
GraphQL with .NET Core Microservices.pdf
GraphQL Bangkok meetup 5.0
Graphql usage
GraphQL.pptx
GraphQL.pptx
GraphQL- Presentation
GraphQL for Native Apps
GraphQL API Crafts presentation
Apollo server II
GraphQL - an elegant weapon... for more civilized age
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI developers love GraphQL
GraphQL across the stack: How everything fits together
All you need to know about GraphQL.pdf
GraphQL Introduction with Spring Boot
CONDG April 23 2020 - Baskar Rao - GraphQL
Modern APIs with GraphQL
Ad

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.

Introduction to Graph QL

  • 1. For internal use only Introduction to GraphQL
  • 2. For internal use only Rest – REST in peace LonglivetoGraphQL Hello GraphQL Reviews from Developers ++
  • 3. For internal use only Index  History  What is GraphQL  Introduction  Rapidly Growing community  Alternative to Rest  CRUD in GraphQL
  • 4. For internal use only History  Invented by Facebook  Presented publically at React JS Conference in 2015 and made open source  Specification stable version – 2018  Find releases - https://graphql.github.io/graphql-spec/ 2012 Development Started 2015 Open Sourced 2016 2017 2018 2019 Evolving specification
  • 5. For internal use only What is GraphQL • GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. • GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. • GraphQL is not a database, it’s a specification
  • 6. For internal use only Introduction  Provides an efficient, powerful and flexible approach to developing web APIs  Enables declarative data fetching  Exposes Single endpoint and responds to queries  Alternative to REST Services  Graph QL is not only for React Developers  It can be used with any programming language and framework
  • 7. For internal use only A Rapidly growing Community Find more Users - https://graphql.org/users/
  • 8. For internal use only What we need • User • Users Posts • Follower (likes) • Commenters
  • 9. For internal use only Data Fetching with REST
  • 10. For internal use only Data Fetching with GraphQL
  • 11. For internal use only Single Endpoint vs Multiple Endpoints Img Reference - https://blog.apollographql.com/graphql-vs-rest-5d425123e34b
  • 12. For internal use only Data Over fetching { "userName" : "moredee", "firstName" : "Deepak", "lastName" : "More", "isActive" : "true", "email" : "deepak.more@db.com", "contactNumber" : "9420390095", "city" : "Pune” …. } { "userName" : "moredee", "firstName" : "Deepak", "lastName" : "More", } URL – /get/user/10
  • 13. For internal use only Data Under fetching { "userName" : "moredee", "firstName" : "Deepak", "lastName" : "More", "isActive" : "true", "email" : "deepak.more@db.com", "contactNumber" : "9420390095", …. } { "userName" : "moredee", "firstName" : "Deepak", "lastName" : "More", “Address” : [ … ] } { “id" : “123", “address Line" : “Nagras Road", “address Line 1" : “Aundh", “city" : “Pune", “State" : “Maharashtra", “PinCode" : “411007", …. } URL – /user/10 URL – /address/123
  • 14. For internal use only Problem with Advanced requests  Rest Api - GET /users/1/friends/1/dogs/1?include=user.name,dog.age  GraphQL : query { user(id: 1) { friends { dogs { name } } } }
  • 15. For internal use only GraphQL vs REST Comparison Points REST GraphQL EndPoints Multiple Single Fetching data Over fetching and Under fetching Fetch Exact Data Dependency on Endpoint Highly Dependent Not Dependent Production Iteration at Frontend Slower Faster Advanced Request Complex Easy
  • 16. For internal use only GraphQL Type System  Object Types  Interfaces  Unions  Enumerations  Fields  List  Scaler Types  Int  Float  String  Boolean  Id (serialized in String)
  • 17. For internal use only Schema Basics  GraphQL has its own type system that’s used to define the schema of an API. The syntax for writing schemas is called Schema Definition Language (SDL).  The ! following the type means that this field is required. type User { name: String! contactNo: Int! posts: [Post!] } type Post{ name: String! author: User! } User Post 1 N
  • 18. For internal use only CRUD in GraphQL  Graph QL Operations  Query - use to read a data  Mutation - use to write a data  Subscriptions - use to listen for data query { search(id: “123456"){ name posts(last: 1) { title } followers { name } } } Mutation { createUser(name: “Deepak“, age: 28){ id } Subscription { onCreate { name age } }
  • 19. For internal use only Self Explanatory query{ book(isbn: “SEBT125") { name author { firstname lastName } } Give me the book with isbn=“SEBT125" Give me the book's name Give me the book's author Give me the author's first name Give me the author’s last name
  • 20. For internal use only GraphQL Execution Engine  Parse Query from Client  Validate Schema  Return JSON response  Executes resolvers for each field
  • 21. For internal use only Server Architecture /graphql (Single endpoint) Dao Layer Business Layer Schema Validation Layer Resolvers (Query, Mutation, Subscription) /graphiql (Editor)
  • 22. For internal use only 2 Ways to access GraphQL App  GraphQL Editor Application – (Windows)  https://electronjs.org/apps/graphiql  GraphiQL Server Utility  Localhost:8080/graphiql
  • 23. For internal use only Validation / Error Handling GraphQL Error status : { "data": null, "errors": [ { "message": "Cannot query field ‘names' on type ‘Book'. Did you mean ‘name'? (line 52, column 5):n namen ^", "locations": [ { "line": 52, "column": 5 } ] } ] } query { searchbook(name: “java") { names author { firstname lastName } }
  • 24. For internal use only Demo  Used Technologies  Node Js, Express, MySQL Database (Server Configuration)  ReactJS, Websockets, Apollo Client (Using React Render Props)  Demo Covers :  Book Creation  Subscription
  • 25. For internal use only How to do Server-side Caching  Server-side caching still is a challenge with GraphQL.
  • 26. For internal use only 1) Should I stop Using Rest API Now? 2) Should I migrate current application to GraphQL? Answer is No
  • 27. For internal use only Authentication and Authorization in GraphQL  Authentication can be done by using Oauth  To implement authorization, it is recommended to delegate any data access logic to the business logic layer and not handle it directly in the GraphQL implementation.
  • 28. For internal use only Disadvantages  You need to learn how to set up GraphQL. The ecosystem is still rapidly evolving so you have to keep up.  You need to define the schema beforehand => extra work before you get results  You need to have a GraphQL endpoint on your server => new libraries that you don't know yet  The server needs to do more processing to parse the query and verify the parameters
  • 29. For internal use only Resources  Find libraries for technologies –  https://graphql.org/code/  Editor -  https://lucasconstantino.github.io/graphiql-online/
  • 30. For internal use only References  https://graphql.org/learn/  https://www.howtographql.com/  https://blog.apollographql.com/graphql-vs-rest-5d425123e34b
  • 31. For internal use only Demo  Used Technologies  Spring Boot, h2 Database (Server Configuration)  ReactJS, Apollo Client (Using React Render Props)  Demo Covers :  Book Creation  Book Deletion  Books List

Editor's Notes

  • #6: I simple language, Graph QL is actually a specification around http for how you get and receive resources from a server.
  • #9: GraphQL helps where your client needs a flexible response format to avoid extra queries and/or massive data transformation with the overhead of keeping them in sync. Using a GraphQL server makes it very easy for a client side developer to change the response format without any change on the backend.
  • #12: Single Endpoint is serving your purpose.
  • #13: Over-fetching is fetching too much data, meaning there is data in the response you don't use.
  • #14: Under-fetching is not having enough data with a call to an endpoint, forcing you to call a second endpoint.
  • #15: GraphQL helps where your client needs a flexible response format to avoid extra queries and/or massive data transformation with the overhead of keeping them in sync. Using a GraphQL server makes it very easy for a client side developer to change the response format without any change on the backend.
  • #20: With GraphQL, you can describe the required data in a more natural way. It can speed up development, because in application structures like top-down rendering in React, the required data is more similar to your component structure.
  • #26: One common concern with GraphQL, especially when comparing it to REST, are the difficulties to maintain server-side cache. With REST, it’s easy to cache the data for each endpoint, since it’s sure that the structure of the data will not change. With GraphQL on the other hand, it’s not clear what a client will request next, so putting a caching layer right behind the API doesn’t make a lot of sense.
  • #27: Should I abandon the REST API and always should use Graph QL. And is there like no usage of REST API now. I would say No There is no mandate like migrate your application to GraphQL right now. There is no such high an immediate need that you should implement graph QL Millions of Millions Queries in Single Day. – GraphQL REST Service wiil be there