SlideShare a Scribd company logo
GraphQL Intro
Nir Levy, Jan 17
Agenda
● What is GraphQL
● GraphQL characteristics and syntax
● Advantages over REST
● GraphQL drawbacks
● GraphQL in Liveperson
● Demo
● Further reading
● Questions
Let’s start with an example
● Say you have an API for music albums and songs:
● And now you want to get all of an artist’s albums with their songs lists
Song:
{
“id” : 116
“artist”: “David Bowie”,
“name”: “Time”,
“album” : “Aladdin Sane”,
“duration”: “5:15”,
“trackNumber”: 6,
...
}
Album:
{
“id” : 321
“artist”: “David Bowie”,
“name”: “Aladdin Sane”,
“releaseYear”: 1973,
“songIDs”: [111,112,113,114,....],
...
}
Example continued
GET /artist/1
GET /album/321
GET /song/111
GET /song/112
…
…
GET /song/120
GET /album/322
GET /song/211
GET /song/212
…
…
GET /song/220
...
Requires many requests
Each request returns much more data than you
need
● Other option - ad-hoc API for album with
songs
○ But adding API per need might end up
with way too many APIs
○ And you’d still get more data than you
need
REST Limitations
● resource-centric: many endpoints
● The endpoints are often organized the way they’re stored in DB,
not the way they’re retrieved by clients
● large (and fixed) responses
● Getting a complete response requires multiple requests
● We would like to get on a single request
● ALL the data that we need, from several resources
● ONLY the data that we need - no large responses with redundant
fields
What is GraphQL
● A data query language
● Completely agnostic to the underlying storage or
programming language
● Invented and used by Facebook since 2012
● Open sourced on 2015
● Re-defines the client-server relations
● Moving the power to the client
● He decides what to fetch, not the server
Who uses GraphQL
What is GraphQL
Client request
album (artist: “David Bowie”
name: “Heroes”) {
releaseYear
songs {
trackNumber
name
duration
}
}
Query name
arguments
Selection set
to return
Schema
schema {
query: {
album(artist: String!
name: String!):Album
}
Album: {
id: ID
name: String
releaseYear: Integer
artist: String
songs: [Song]
}
Song: {
id: ID
name: String
duration: String
trackNumber: Integer
}
}
Response
{
"album": {
"releaseYear": 1977,
"songs": [
{
"trackNumber": 1,
"Name": "beauty and the beast",
"Duration": "3:32"
},
{
"trackNumber": 2,
"Name": "Joe the Lion",
"Duration": "3:05"
},
…
]
}
}
GraphQL Characteristics
● GraphQL describes what data to fetch rather than actual queries to a
database.
● A GraphQL server interprets these calls and then queries the storage
layer, using the schema and resolvers.
● Entirely agnostic to the storage layer, can be also used as a proxy
forward API calls.
● Contains introspection features to expose the server’s schema and
objects.
Resolvers
● The schema contains the objects the server returns.
● Each object can consist of scalar fields (int, string etc.) or other
objects.
● Each object in the schema should be provided with a resolver.
● The resolver is a piece of code that does the actual work - fetches
the results from the storage layer.
● GraphQL server will take care of combining the objects and returning
only the selection set fields.
Resolvers
● When running the query, album resolver will fetch the album
according to the provided artist and name
● Albums in DB contain song Ids - the song resolver will fetch the
songs according to the Ids
● GraphQL server will then combine the results and return only the
requested fields
● There are several solutions for batching and caching to make the
fetching more efficient
Schema
schema {
query: {
album(artist: String!
name: String!):Album
}
Album: {
id: ID
name: String
releaseYear: Integer
artist: String
songs: [Song]
}
Song: {
id: ID
name: String
duration: String
trackNumber: Integer
}
}
Songs Storage
Song:
{
“id” : 116
“artist”: “David Bowie”,
“name”: “Time”,
“album” : “Aladdin Sane”,
“duration”: “5:15”,
“trackNumber”: 6,
...
}
Albums Storage
Album:
{
“id” : 321
“artist”: “David Bowie”,
“name”: “Aladdin Sane”,
“releaseYear”: 1973,
“songIDs”: [111,112,113,114,....],
...
}
GraphQL Basic Syntax
● Two types of Operations
○ Query: read only fetch
○ Mutation: write and fetch
● Can contain arguments
● Selection Sets: a subset of the fields on an object.
○ Can be objects as well
○ Defines the returned object’s structure
{
getAlbum(artist: 123) {
name
releaseYear
songs {
name
duration
}
}
}
Mutations
● Mutations are yet another kind of queries
● By convention, we use query for read only operations, and mutation for
persist operations (create/update/delete/patch)
● Mutation also has a returned value, just like query
API Versioning in GraphQL
● When the client can’t control the returned data, any change can be a
breaking one
● Any change that is considered as a breaking one, requires a new API
version
● In contrast, GraphQL only returns the data that's explicitly requested
● New capabilities can be added via new new fields
○ Which will not be consumpt by the client until explicitly requested
● The common practice is to avoid changing existing fields, and serving a
versionless API.
● There’s a deprecation mechanism to handle obsolete fields
So Why choose GraphQL over REST?
● Single endpoint - easier to scale
● Tailored responses - client gets only what he wants
● Fewer round trips - can return several related resources together
● Backwards compatibility - the client decides the response structure,
knows exactly what to expect
● Introspective - GraphQL has a native and highly extensible schema
and type system
GraphQL drawbacks
● Coupling between entities is inherent - The schema needs to know all
types
● Still relatively new
● No clear best-practices/standards
● Frameworks and resources are less mature than REST or other
industry standards
GraphQL in Liveperson
● Audit Trail API is built using GraphQL
● We evaluate the option to build Account Config 2.0 using GraphQL
based APIs
DEMO
https://www.graphqlhub.com
Advanced Syntax - Fragments
● Fragments are aliases for a bundle of fields.
● Fields in fragments are added at the same level of invocation as
adjacent fields.
● Syntax- prefixed with ...
Query
{
album(id: 1) {
name
...customFields
}
}
fragment customFields on Album {
releaseYear
songs {
name
duration
}
}
Response
{
"album": {
"name": “heroes”,
"releaseYear": 1977,
"songs": [
{
"Name": "beauty and the beast",
"Duration": "3:32"
},
{
"Name": "Joe the Lion",
"Duration": "3:05"
},
…
]
}
}
Advanced Syntax - Directives
● Directives alter execution behavior and can be used to conditionally
include (@include) or exclude (@skip) fields.
Request
query getSong(fullDetails: Boolean id: Int) {
name
... @include(if: $fullDetails) {
duration
album
}
}
}
// response when $fullDetails resolves to false
{
"getSong": {
"name": "Time"
}
}
// response when $fullDetails resolves to true
{
"getSong": {
"name": "Time",
"album": "Aladdin Sane",
“duration”: “5:15”
}
}
Further reading
● https://github.com/chentsulin/awesome-graphql - github repo with
many links to tutorials, libraries in various languages, blogs, videos and
more
● http://graphql.org/learn
● https://www.graphqlhub.com - playground on various public GraphQL
API. good place to learn the syntax
Questions
Thank You

More Related Content

Similar to Graph QL Introduction

Querier – simple relational database access
Querier – simple relational database accessQuerier – simple relational database access
Querier – simple relational database access
ESUG
 
Neo4j (Part 1)
Neo4j (Part 1)Neo4j (Part 1)
Neo4j (Part 1)
Bibhuti Regmi
 
One Database To Rule 'em All
One Database To Rule 'em AllOne Database To Rule 'em All
One Database To Rule 'em All
Stefanie Janine Stölting
 
NoSQL Konzepte live und in Farbe
NoSQL Konzepte live und in FarbeNoSQL Konzepte live und in Farbe
NoSQL Konzepte live und in Farbe
Astrid Ritscher
 
One Database To Rule 'em All
One Database To Rule 'em AllOne Database To Rule 'em All
One Database To Rule 'em All
Stefanie Janine Stölting
 
One Database to Rule 'em all (FrOSCon 11)
One Database to Rule 'em all (FrOSCon 11)One Database to Rule 'em all (FrOSCon 11)
One Database to Rule 'em all (FrOSCon 11)
Stefanie Janine Stölting
 
Introduction to Graph Database
Introduction to Graph DatabaseIntroduction to Graph Database
Introduction to Graph Database
Eric Lee
 
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Paul Leclercq
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Nikolas Burk
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
Rob Crowley
 
S3
S3S3
Overview of GraphQL & Clients
Overview of GraphQL & ClientsOverview of GraphQL & Clients
Overview of GraphQL & Clients
Pokai Chang
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncAmazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Citus Data
 
NoSQL Concepts live with MongoDB
NoSQL Concepts live with MongoDBNoSQL Concepts live with MongoDB
NoSQL Concepts live with MongoDB
Astrid Ritscher
 

Similar to Graph QL Introduction (14)

Querier – simple relational database access
Querier – simple relational database accessQuerier – simple relational database access
Querier – simple relational database access
 
Neo4j (Part 1)
Neo4j (Part 1)Neo4j (Part 1)
Neo4j (Part 1)
 
One Database To Rule 'em All
One Database To Rule 'em AllOne Database To Rule 'em All
One Database To Rule 'em All
 
NoSQL Konzepte live und in Farbe
NoSQL Konzepte live und in FarbeNoSQL Konzepte live und in Farbe
NoSQL Konzepte live und in Farbe
 
One Database To Rule 'em All
One Database To Rule 'em AllOne Database To Rule 'em All
One Database To Rule 'em All
 
One Database to Rule 'em all (FrOSCon 11)
One Database to Rule 'em all (FrOSCon 11)One Database to Rule 'em all (FrOSCon 11)
One Database to Rule 'em all (FrOSCon 11)
 
Introduction to Graph Database
Introduction to Graph DatabaseIntroduction to Graph Database
Introduction to Graph Database
 
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
Analyze one year of radio station songs aired with Spark SQL, Spotify, and Da...
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
 
S3
S3S3
S3
 
Overview of GraphQL & Clients
Overview of GraphQL & ClientsOverview of GraphQL & Clients
Overview of GraphQL & Clients
 
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise GrandjoncAmazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
Amazing SQL your ORM can (or can't) do | PGConf EU 2019 | Louise Grandjonc
 
NoSQL Concepts live with MongoDB
NoSQL Concepts live with MongoDBNoSQL Concepts live with MongoDB
NoSQL Concepts live with MongoDB
 

More from LivePerson

Microservices on top of kafka
Microservices on top of kafkaMicroservices on top of kafka
Microservices on top of kafka
LivePerson
 
Growing into a proactive Data Platform
Growing into a proactive Data PlatformGrowing into a proactive Data Platform
Growing into a proactive Data Platform
LivePerson
 
Measure() or die()
Measure() or die() Measure() or die()
Measure() or die()
LivePerson
 
Resilience from Theory to Practice
Resilience from Theory to PracticeResilience from Theory to Practice
Resilience from Theory to Practice
LivePerson
 
System Revolution- How We Did It
System Revolution- How We Did It System Revolution- How We Did It
System Revolution- How We Did It
LivePerson
 
Liveperson DLD 2015
Liveperson DLD 2015 Liveperson DLD 2015
Liveperson DLD 2015
LivePerson
 
Http 2: Should I care?
Http 2: Should I care?Http 2: Should I care?
Http 2: Should I care?
LivePerson
 
Mobile app real-time content modifications using websockets
Mobile app real-time content modifications using websocketsMobile app real-time content modifications using websockets
Mobile app real-time content modifications using websockets
LivePerson
 
Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices
LivePerson
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]
LivePerson
 
Apache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePersonApache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePerson
LivePerson
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern Application
LivePerson
 
Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API
LivePerson
 
SIP - Introduction to SIP Protocol
SIP - Introduction to SIP ProtocolSIP - Introduction to SIP Protocol
SIP - Introduction to SIP Protocol
LivePerson
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduce
LivePerson
 
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
LivePerson
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
LivePerson
 
From a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePersonFrom a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePerson
LivePerson
 
How can A/B testing go wrong?
How can A/B testing go wrong?How can A/B testing go wrong?
How can A/B testing go wrong?
LivePerson
 

More from LivePerson (20)

Microservices on top of kafka
Microservices on top of kafkaMicroservices on top of kafka
Microservices on top of kafka
 
Growing into a proactive Data Platform
Growing into a proactive Data PlatformGrowing into a proactive Data Platform
Growing into a proactive Data Platform
 
Measure() or die()
Measure() or die() Measure() or die()
Measure() or die()
 
Resilience from Theory to Practice
Resilience from Theory to PracticeResilience from Theory to Practice
Resilience from Theory to Practice
 
System Revolution- How We Did It
System Revolution- How We Did It System Revolution- How We Did It
System Revolution- How We Did It
 
Liveperson DLD 2015
Liveperson DLD 2015 Liveperson DLD 2015
Liveperson DLD 2015
 
Http 2: Should I care?
Http 2: Should I care?Http 2: Should I care?
Http 2: Should I care?
 
Mobile app real-time content modifications using websockets
Mobile app real-time content modifications using websocketsMobile app real-time content modifications using websockets
Mobile app real-time content modifications using websockets
 
Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices Mobile SDK: Considerations & Best Practices
Mobile SDK: Considerations & Best Practices
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]Apache Avro in LivePerson [Hebrew]
Apache Avro in LivePerson [Hebrew]
 
Apache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePersonApache Avro and Messaging at Scale in LivePerson
Apache Avro and Messaging at Scale in LivePerson
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern Application
 
Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API Support Office Hour Webinar - LivePerson API
Support Office Hour Webinar - LivePerson API
 
SIP - Introduction to SIP Protocol
SIP - Introduction to SIP ProtocolSIP - Introduction to SIP Protocol
SIP - Introduction to SIP Protocol
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduce
 
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...Building Enterprise Level End-To-End Monitor System with Open Source Solution...
Building Enterprise Level End-To-End Monitor System with Open Source Solution...
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
From a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePersonFrom a Kafkaesque Story to The Promised Land at LivePerson
From a Kafkaesque Story to The Promised Land at LivePerson
 
How can A/B testing go wrong?
How can A/B testing go wrong?How can A/B testing go wrong?
How can A/B testing go wrong?
 

Recently uploaded

How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 

Recently uploaded (20)

How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 

Graph QL Introduction

  • 2. Agenda ● What is GraphQL ● GraphQL characteristics and syntax ● Advantages over REST ● GraphQL drawbacks ● GraphQL in Liveperson ● Demo ● Further reading ● Questions
  • 3. Let’s start with an example ● Say you have an API for music albums and songs: ● And now you want to get all of an artist’s albums with their songs lists Song: { “id” : 116 “artist”: “David Bowie”, “name”: “Time”, “album” : “Aladdin Sane”, “duration”: “5:15”, “trackNumber”: 6, ... } Album: { “id” : 321 “artist”: “David Bowie”, “name”: “Aladdin Sane”, “releaseYear”: 1973, “songIDs”: [111,112,113,114,....], ... }
  • 4. Example continued GET /artist/1 GET /album/321 GET /song/111 GET /song/112 … … GET /song/120 GET /album/322 GET /song/211 GET /song/212 … … GET /song/220 ... Requires many requests Each request returns much more data than you need ● Other option - ad-hoc API for album with songs ○ But adding API per need might end up with way too many APIs ○ And you’d still get more data than you need
  • 5. REST Limitations ● resource-centric: many endpoints ● The endpoints are often organized the way they’re stored in DB, not the way they’re retrieved by clients ● large (and fixed) responses ● Getting a complete response requires multiple requests ● We would like to get on a single request ● ALL the data that we need, from several resources ● ONLY the data that we need - no large responses with redundant fields
  • 6. What is GraphQL ● A data query language ● Completely agnostic to the underlying storage or programming language ● Invented and used by Facebook since 2012 ● Open sourced on 2015 ● Re-defines the client-server relations ● Moving the power to the client ● He decides what to fetch, not the server
  • 8. What is GraphQL Client request album (artist: “David Bowie” name: “Heroes”) { releaseYear songs { trackNumber name duration } } Query name arguments Selection set to return Schema schema { query: { album(artist: String! name: String!):Album } Album: { id: ID name: String releaseYear: Integer artist: String songs: [Song] } Song: { id: ID name: String duration: String trackNumber: Integer } } Response { "album": { "releaseYear": 1977, "songs": [ { "trackNumber": 1, "Name": "beauty and the beast", "Duration": "3:32" }, { "trackNumber": 2, "Name": "Joe the Lion", "Duration": "3:05" }, … ] } }
  • 9. GraphQL Characteristics ● GraphQL describes what data to fetch rather than actual queries to a database. ● A GraphQL server interprets these calls and then queries the storage layer, using the schema and resolvers. ● Entirely agnostic to the storage layer, can be also used as a proxy forward API calls. ● Contains introspection features to expose the server’s schema and objects.
  • 10. Resolvers ● The schema contains the objects the server returns. ● Each object can consist of scalar fields (int, string etc.) or other objects. ● Each object in the schema should be provided with a resolver. ● The resolver is a piece of code that does the actual work - fetches the results from the storage layer. ● GraphQL server will take care of combining the objects and returning only the selection set fields.
  • 11. Resolvers ● When running the query, album resolver will fetch the album according to the provided artist and name ● Albums in DB contain song Ids - the song resolver will fetch the songs according to the Ids ● GraphQL server will then combine the results and return only the requested fields ● There are several solutions for batching and caching to make the fetching more efficient Schema schema { query: { album(artist: String! name: String!):Album } Album: { id: ID name: String releaseYear: Integer artist: String songs: [Song] } Song: { id: ID name: String duration: String trackNumber: Integer } } Songs Storage Song: { “id” : 116 “artist”: “David Bowie”, “name”: “Time”, “album” : “Aladdin Sane”, “duration”: “5:15”, “trackNumber”: 6, ... } Albums Storage Album: { “id” : 321 “artist”: “David Bowie”, “name”: “Aladdin Sane”, “releaseYear”: 1973, “songIDs”: [111,112,113,114,....], ... }
  • 12. GraphQL Basic Syntax ● Two types of Operations ○ Query: read only fetch ○ Mutation: write and fetch ● Can contain arguments ● Selection Sets: a subset of the fields on an object. ○ Can be objects as well ○ Defines the returned object’s structure { getAlbum(artist: 123) { name releaseYear songs { name duration } } }
  • 13. Mutations ● Mutations are yet another kind of queries ● By convention, we use query for read only operations, and mutation for persist operations (create/update/delete/patch) ● Mutation also has a returned value, just like query
  • 14. API Versioning in GraphQL ● When the client can’t control the returned data, any change can be a breaking one ● Any change that is considered as a breaking one, requires a new API version ● In contrast, GraphQL only returns the data that's explicitly requested ● New capabilities can be added via new new fields ○ Which will not be consumpt by the client until explicitly requested ● The common practice is to avoid changing existing fields, and serving a versionless API. ● There’s a deprecation mechanism to handle obsolete fields
  • 15. So Why choose GraphQL over REST? ● Single endpoint - easier to scale ● Tailored responses - client gets only what he wants ● Fewer round trips - can return several related resources together ● Backwards compatibility - the client decides the response structure, knows exactly what to expect ● Introspective - GraphQL has a native and highly extensible schema and type system
  • 16. GraphQL drawbacks ● Coupling between entities is inherent - The schema needs to know all types ● Still relatively new ● No clear best-practices/standards ● Frameworks and resources are less mature than REST or other industry standards
  • 17. GraphQL in Liveperson ● Audit Trail API is built using GraphQL ● We evaluate the option to build Account Config 2.0 using GraphQL based APIs
  • 19. Advanced Syntax - Fragments ● Fragments are aliases for a bundle of fields. ● Fields in fragments are added at the same level of invocation as adjacent fields. ● Syntax- prefixed with ... Query { album(id: 1) { name ...customFields } } fragment customFields on Album { releaseYear songs { name duration } } Response { "album": { "name": “heroes”, "releaseYear": 1977, "songs": [ { "Name": "beauty and the beast", "Duration": "3:32" }, { "Name": "Joe the Lion", "Duration": "3:05" }, … ] } }
  • 20. Advanced Syntax - Directives ● Directives alter execution behavior and can be used to conditionally include (@include) or exclude (@skip) fields. Request query getSong(fullDetails: Boolean id: Int) { name ... @include(if: $fullDetails) { duration album } } } // response when $fullDetails resolves to false { "getSong": { "name": "Time" } } // response when $fullDetails resolves to true { "getSong": { "name": "Time", "album": "Aladdin Sane", “duration”: “5:15” } }
  • 21. Further reading ● https://github.com/chentsulin/awesome-graphql - github repo with many links to tutorials, libraries in various languages, blogs, videos and more ● http://graphql.org/learn ● https://www.graphqlhub.com - playground on various public GraphQL API. good place to learn the syntax

Editor's Notes

  1. Schema - add few words about validations
  2. Add some slide before about versioning