SlideShare uma empresa Scribd logo
1 de 23
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

Mais conteúdo relacionado

Semelhante a Graph QL Introduction

Querier – simple relational database access
Querier – simple relational database accessQuerier – simple relational database access
Querier – simple relational database accessESUG
 
NoSQL Konzepte live und in Farbe
NoSQL Konzepte live und in FarbeNoSQL Konzepte live und in Farbe
NoSQL Konzepte live und in FarbeAstrid Ritscher
 
Introduction to Graph Database
Introduction to Graph DatabaseIntroduction to Graph Database
Introduction to Graph DatabaseEric 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 CloudNikolas 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
 
Overview of GraphQL & Clients
Overview of GraphQL & ClientsOverview of GraphQL & Clients
Overview of GraphQL & ClientsPokai 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 GrandjoncCitus Data
 
NoSQL Concepts live with MongoDB
NoSQL Concepts live with MongoDBNoSQL Concepts live with MongoDB
NoSQL Concepts live with MongoDBAstrid Ritscher
 

Semelhante a 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
 

Mais de LivePerson

Microservices on top of kafka
Microservices on top of kafkaMicroservices on top of kafka
Microservices on top of kafkaLivePerson
 
Growing into a proactive Data Platform
Growing into a proactive Data PlatformGrowing into a proactive Data Platform
Growing into a proactive Data PlatformLivePerson
 
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 PracticeLivePerson
 
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 websocketsLivePerson
 
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 8LivePerson
 
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 LivePersonLivePerson
 
Data compression in Modern Application
Data compression in Modern ApplicationData compression in Modern Application
Data compression in Modern ApplicationLivePerson
 
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 ProtocolLivePerson
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceLivePerson
 
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 ScienceLivePerson
 
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 LivePersonLivePerson
 
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
 

Mais de 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?
 

Último

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 

Último (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

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

Notas do Editor

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