SlideShare a Scribd company logo
A Query Language for your API
GraphQL
Bhargav Anadkat
Twitter @bhargavlalo
WHAT TO EXPECT AHEAD...
❏ Introduction
❏ Start with Example
❏ REST Limitations
❏ Why choose GraphQL over
REST?
❏ What is GraphQL?
❏ Who uses GraphQL?
❏ Language Supported
❏ Install & Configure in NodeJs
❏ Install & Configure in .Net/C#
❏ Install & Configure in PHP
❏ Understanding Tools
❏ Types & Schema
❏ Scalar Type
❏ Object Type
❏ Query Type
❏ Mutation Type
❏ Input Type
❏ Enum Type
❏ Syntax & Language
❏ Fields
❏ Arguments
❏ Aliases
❏ Fragments
❏ Resolver
❏ Introspection
❏ Live Example
❏ PHP Sample
❏ Shopify
❏ Movies
❏ Further reading
❏ Questions
Let’s start with an Example
You have an API for music albums and songs:
Album:
{
“id” : 321
“artist”: “David Bowie”,
“name”: “Aladdin Sane”,
“releaseYear”: 1973,
“songIDs”:
[111,112,113,114,....],
…
}
Song:
{
“id” : 116
“artist”: “David Bowie”,
“name”: “Time”,
“album” : “Aladdin Sane”,
“duration”: “5:15”,
“trackNumber”: 6,
...
}
And now you want to get all of an artist’s albums with their songs lists
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
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 is a modern query language for the API.
It allows the front-end developer, to write queries that have the exact data shape they want.
GraphQL is developed by Facebook.
GraphQL was developed internally by Facebook in 2012
It's open source version publicly released in 2015 and current stable version released in
June 2018
GraphQL official website is https://graphql.org/
GraphQL official git repository is https://github.com/graphql/graphql-spec
What is GraphQL?
Who’s using GraphQL
Language Supported by GraphQL
❏ C# / .NET
❏ Clojure
❏ Elixir
❏ Erlang
❏ Go
❏ Groovy
❏ Java
❏ JavaScript
❏ PHP
❏ Python
❏ Scala
❏ Ruby
Node.JS NPM package Install
npm init
npm install graphql --save
Install & Configure Node.JS
.Net/C# GraphQL nuGet library
❏ graphql-dotnet: GraphQL for .NET
❏ graphql-net: Convert GraphQL to IQueryable
❏ Hot Chocolate: GraphQL Server for .net core and .net classic
Install & Configure in .Net/C#
PHP Composer Library
❏ graphql-php: A PHP port of GraphQL reference implementation
❏ graphql-relay-php: A library to help construct a graphql-php server
supporting react-relay.
Install & Configure in PHP
GraphiQL
Install NodeJs express Tool
https://github.com/graphql/graphiql
ChromeiQL
Install Chrome Browser Extension
https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl=
en
GraphQL Playground
Install EXE
https://github.com/prisma/graphql-playground
Understanding Tools
Schema
A GraphQL schema is at the center of any
GraphQL server implementation and
describes the functionality available to the
clients which connect to it.
Type
GraphQL is a strongly typed language.
Type System defines various data types that
can be used in a GraphQL application.
The type system helps to define the
schema, which is a contract between client
and server.
Types & Schema
List of Types
❏ Scalar Type
❏ Object Type
❏ Query Type
❏ Mutation Type
❏ Interface Type
❏ Union Type
❏ Enum Type
❏ Input Type
Scalar types represent primitive leaf values in a GraphQL
type system.
GraphQL responses take the form of a hierarchical tree; the
leaves on these trees are GraphQL scalars.
Scalar Type
Custom Scalars
❏ EmailAddress
❏ USCurrency
❏ PhoneNumber
❏ URL
❏ DateTime
Built‐in Scalars
❏ Int
❏ Float
❏ String
❏ Boolean
❏ ID
Syntax
field: data_type
The object type is the most common type used
in a schema and represents a group of fields.
Each field inside an object type maps to another
type, thereby allowing nested types.
In other words, an object type is composed of
multiple scalar types or object types.
Object Type
Syntax
type object_type_name
{
field1: data_type
field2:data_type
....
fieldn:data_type
}
Entry point type to other specific types
A GraphQL query is used to read or fetch values.
It is not mandatory to pass “query” word in each
query
Query Type
Syntax 1
query query_name{
someField }
Syntax 2
{ someField }
Mutation is also an entry point type
It can be used to insert, update, or delete data.
Mutation also has a returned value, just like
query
Mutation Type
Syntax
mutation{
someEditOperation(dataField:"val
ueOfField"):returnType
}
In the GraphQL schema language, input types
look exactly the same as regular object types,
but with the keyword input instead of type:
Mostly it is used with mutation type for data
operation like add,edit and delete.
Input Type
Syntax
Input object_input_name
{
field1: data_type
field2:data_type
....
fieldn:data_type
}
Also called Enums, enumeration types are a
special kind of scalar that is restricted to a
particular set of allowed values.
It is used for fix data. For e.g weekdays, months,
and measurements Units.
Enum Type
Syntax
Enum object_enum_name
{
Data
Data
....
Data
}
Syntax & Language
At its simplest, GraphQL is about asking for specific fields on objects.
Fields
GraphQL Argument is very useful for data fetching.
We can define any number of arguments.
It helps to get specific data fetching like
Page limit, filter option.
Arguments
Aliases
It used for rename the result of a field to anything you want.
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 ...
Fragments
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.
Resolver
GraphQL APIs are required to be self-documenting.
According to the specification, every GraphQL API needs to respond to queries about its own
structure.
This system is called introspection, and an introspection query starts with the __schema field
present on every GraphQL API that hasn’t intentionally disabled it.
Introspection
❏ PHP Sample Example
❏ Shopify
❏ Movies
Live Example
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
❏ https://www.howtographql.com/ - How to GraphQL
Question?
Thanks!
Try GraphQL,
You'll like it.

More Related Content

What's hot

Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQL
Amazon Web Services
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
Josh Price
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
Vibhor Grover
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
Serge Huber
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SF
Amazon Web Services
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
Rafael Wilber Kerr
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
Amazon Web Services
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
Nikolas Burk
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
Tomasz Bak
 
Graphql
GraphqlGraphql
Graphql
Niv Ben David
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
Sashko Stubailo
 
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
luisw19
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
Virbhadra Ankalkote
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
GreeceJS
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
VMware Tanzu
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Hafiz Ismail
 
GraphQL
GraphQLGraphQL
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
Tomasz Bak
 
Intro GraphQL
Intro GraphQLIntro GraphQL
Intro GraphQL
Simona Cotin
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
Adam Paxton
 

What's hot (20)

Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQL
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SF
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
Graphql
GraphqlGraphql
Graphql
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
 
GraphQL
GraphQLGraphQL
GraphQL
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
 
Intro GraphQL
Intro GraphQLIntro GraphQL
Intro GraphQL
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
 

Similar to Introduction to GraphQL

Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
Andrew Rota
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
Andrew Rota
 
Apollo Server
Apollo ServerApollo Server
Apollo Server
NodeXperts
 
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQL
Taikai
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
Cédric GILLET
 
PHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLitePHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLite
JEAN-GUILLAUME DUJARDIN
 
Let's talk about GraphQL
Let's talk about GraphQLLet's talk about GraphQL
Let's talk about GraphQL
Commit Software Sh.p.k.
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptx
Knoldus Inc.
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
Mohammed Shaban
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQL
VMware Tanzu
 
Hands On - GraphQL
Hands On - GraphQLHands On - GraphQL
Hands On - GraphQL
Breno Henrique de Lima Freitas
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
Knoldus Inc.
 
GraphQl Introduction
GraphQl IntroductionGraphQl Introduction
GraphQl Introduction
AbhayKumarAgrawal1
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
Knoldus Inc.
 
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
 
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
GreeceJS
 
Attacking GraphQL
Attacking GraphQLAttacking GraphQL
Attacking GraphQL
KavishaSheth1
 
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Ayla Khan
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
WSO2
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
Valentin Buryakov
 

Similar to Introduction to GraphQL (20)

Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
 
Apollo Server
Apollo ServerApollo Server
Apollo Server
 
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQL
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
PHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLitePHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLite
 
Let's talk about GraphQL
Let's talk about GraphQLLet's talk about GraphQL
Let's talk about GraphQL
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptx
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQL
 
Hands On - GraphQL
Hands On - GraphQLHands On - GraphQL
Hands On - GraphQL
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
GraphQl Introduction
GraphQl IntroductionGraphQl Introduction
GraphQl Introduction
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
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)
 
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
 
Attacking GraphQL
Attacking GraphQLAttacking GraphQL
Attacking GraphQL
 
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
 
Exposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIsExposing GraphQLs as Managed APIs
Exposing GraphQLs as Managed APIs
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 

Recently uploaded

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Introduction to GraphQL

  • 1. A Query Language for your API GraphQL Bhargav Anadkat Twitter @bhargavlalo
  • 2. WHAT TO EXPECT AHEAD... ❏ Introduction ❏ Start with Example ❏ REST Limitations ❏ Why choose GraphQL over REST? ❏ What is GraphQL? ❏ Who uses GraphQL? ❏ Language Supported ❏ Install & Configure in NodeJs ❏ Install & Configure in .Net/C# ❏ Install & Configure in PHP ❏ Understanding Tools ❏ Types & Schema ❏ Scalar Type ❏ Object Type ❏ Query Type ❏ Mutation Type ❏ Input Type ❏ Enum Type ❏ Syntax & Language ❏ Fields ❏ Arguments ❏ Aliases ❏ Fragments ❏ Resolver ❏ Introspection ❏ Live Example ❏ PHP Sample ❏ Shopify ❏ Movies ❏ Further reading ❏ Questions
  • 3. Let’s start with an Example You have an API for music albums and songs: Album: { “id” : 321 “artist”: “David Bowie”, “name”: “Aladdin Sane”, “releaseYear”: 1973, “songIDs”: [111,112,113,114,....], … } Song: { “id” : 116 “artist”: “David Bowie”, “name”: “Time”, “album” : “Aladdin Sane”, “duration”: “5:15”, “trackNumber”: 6, ... } And now you want to get all of an artist’s albums with their songs lists
  • 4. 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. 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
  • 7. GraphQL is a modern query language for the API. It allows the front-end developer, to write queries that have the exact data shape they want. GraphQL is developed by Facebook. GraphQL was developed internally by Facebook in 2012 It's open source version publicly released in 2015 and current stable version released in June 2018 GraphQL official website is https://graphql.org/ GraphQL official git repository is https://github.com/graphql/graphql-spec What is GraphQL?
  • 9. Language Supported by GraphQL ❏ C# / .NET ❏ Clojure ❏ Elixir ❏ Erlang ❏ Go ❏ Groovy ❏ Java ❏ JavaScript ❏ PHP ❏ Python ❏ Scala ❏ Ruby
  • 10. Node.JS NPM package Install npm init npm install graphql --save Install & Configure Node.JS
  • 11. .Net/C# GraphQL nuGet library ❏ graphql-dotnet: GraphQL for .NET ❏ graphql-net: Convert GraphQL to IQueryable ❏ Hot Chocolate: GraphQL Server for .net core and .net classic Install & Configure in .Net/C#
  • 12. PHP Composer Library ❏ graphql-php: A PHP port of GraphQL reference implementation ❏ graphql-relay-php: A library to help construct a graphql-php server supporting react-relay. Install & Configure in PHP
  • 13. GraphiQL Install NodeJs express Tool https://github.com/graphql/graphiql ChromeiQL Install Chrome Browser Extension https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij?hl= en GraphQL Playground Install EXE https://github.com/prisma/graphql-playground Understanding Tools
  • 14. Schema A GraphQL schema is at the center of any GraphQL server implementation and describes the functionality available to the clients which connect to it. Type GraphQL is a strongly typed language. Type System defines various data types that can be used in a GraphQL application. The type system helps to define the schema, which is a contract between client and server. Types & Schema List of Types ❏ Scalar Type ❏ Object Type ❏ Query Type ❏ Mutation Type ❏ Interface Type ❏ Union Type ❏ Enum Type ❏ Input Type
  • 15. Scalar types represent primitive leaf values in a GraphQL type system. GraphQL responses take the form of a hierarchical tree; the leaves on these trees are GraphQL scalars. Scalar Type Custom Scalars ❏ EmailAddress ❏ USCurrency ❏ PhoneNumber ❏ URL ❏ DateTime Built‐in Scalars ❏ Int ❏ Float ❏ String ❏ Boolean ❏ ID Syntax field: data_type
  • 16. The object type is the most common type used in a schema and represents a group of fields. Each field inside an object type maps to another type, thereby allowing nested types. In other words, an object type is composed of multiple scalar types or object types. Object Type Syntax type object_type_name { field1: data_type field2:data_type .... fieldn:data_type }
  • 17. Entry point type to other specific types A GraphQL query is used to read or fetch values. It is not mandatory to pass “query” word in each query Query Type Syntax 1 query query_name{ someField } Syntax 2 { someField }
  • 18. Mutation is also an entry point type It can be used to insert, update, or delete data. Mutation also has a returned value, just like query Mutation Type Syntax mutation{ someEditOperation(dataField:"val ueOfField"):returnType }
  • 19. In the GraphQL schema language, input types look exactly the same as regular object types, but with the keyword input instead of type: Mostly it is used with mutation type for data operation like add,edit and delete. Input Type Syntax Input object_input_name { field1: data_type field2:data_type .... fieldn:data_type }
  • 20. Also called Enums, enumeration types are a special kind of scalar that is restricted to a particular set of allowed values. It is used for fix data. For e.g weekdays, months, and measurements Units. Enum Type Syntax Enum object_enum_name { Data Data .... Data }
  • 22. At its simplest, GraphQL is about asking for specific fields on objects. Fields
  • 23. GraphQL Argument is very useful for data fetching. We can define any number of arguments. It helps to get specific data fetching like Page limit, filter option. Arguments
  • 24. Aliases It used for rename the result of a field to anything you want.
  • 25. 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 ... Fragments
  • 26. 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. Resolver
  • 27. GraphQL APIs are required to be self-documenting. According to the specification, every GraphQL API needs to respond to queries about its own structure. This system is called introspection, and an introspection query starts with the __schema field present on every GraphQL API that hasn’t intentionally disabled it. Introspection
  • 28. ❏ PHP Sample Example ❏ Shopify ❏ Movies Live Example
  • 29. 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 ❏ https://www.howtographql.com/ - How to GraphQL