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

Mais conteúdo relacionado

Mais procurados

GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
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 toolsSashko Stubailo
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQLSquareboat
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQLMuhilvarnan V
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLRodrigo Prates
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFAmazon 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
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL Josh Price
 
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 vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs RESTGreeceJS
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL StackSashko Stubailo
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservicesMohammed Shaban
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQLVMware Tanzu
 

Mais procurados (20)

GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
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
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SF
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
 
Graphql
GraphqlGraphql
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 vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
Intro GraphQL
Intro GraphQLIntro GraphQL
Intro GraphQL
 
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
 

Semelhante a 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 PHPAndrew Rota
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHPAndrew Rota
 
Modern APIs with GraphQL
Modern APIs with GraphQLModern APIs with GraphQL
Modern APIs with GraphQLTaikai
 
PHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLitePHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLiteJEAN-GUILLAUME DUJARDIN
 
Introduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxIntroduction to GraphQL Presentation.pptx
Introduction to GraphQL Presentation.pptxKnoldus Inc.
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLKnoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfKnoldus 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
 
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 APIsWSO2
 
GraphQL with Sangria
GraphQL with SangriaGraphQL with Sangria
GraphQL with SangriaKnoldus Inc.
 

Semelhante a 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
 
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
 
GraphQL with Sangria
GraphQL with SangriaGraphQL with Sangria
GraphQL with Sangria
 
Avro
AvroAvro
Avro
 

Último

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

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