SlideShare a Scribd company logo
© 2019 Magento, Inc. Page | 1
Magento 2.3
Introduction to
GraphQL
© 2019 Magento, Inc.
.
Page | 2
Senior Software Engineer at BORN Group
https://www.linkedin.com/in/vishakha-borkar-9b96bb61
Vishakha Borkar
© 2019 Magento, Inc. Page | 3
Agenda
© 2019 Magento, Inc. Page | 4
Agenda
• Challenges with REST
• History and Adoption
• What is GraphQL?
• GraphQL v/s REST
• GraphQL Query Language
• GraphQL in Magento
• Magento GraphQL Implemenation
• GraphQL: Fetch combined/nested data
• GraphQL Mutations
• GraphQL Fragementation
•
© 2019 Magento, Inc. Page | 5
Challenges with REST
© 2019 Magento, Inc. Page | 6
Challenges with REST
 Increased mobile usage creates need for efficient data loading
 Variety of different frontend frameworks and platforms
 Fast development & expectation for rapid feature development
© 2019 Magento, Inc. Page | 7
History and Adoption
© 2019 Magento, Inc. Page | 8
History and Adoption
 Facebook started using GraphQL in 2012 in their native mobile apps
 Initially used and introduced with React.js
 Can be used everywhere a client needs to communicate with API
 Used by many companies. To name a few GitHub, Twitter, Yelp,
Coursea and Shopify
© 2019 Magento, Inc. Page | 9
What is GraphQL?
© 2019 Magento, Inc. Page | 10
What is GraphQL?
• GraphQL is a very powerful and strongly typed query
language.
• Used to communicate data between client and server.
GraphQL provides a complete and understandable description
of the data in your API
• Gives clients the power to ask for exactly what they need,
making it easier to evolve APIs over time
• Enables powerful development tools and thus making
GraphQL a more flexible & efficient approach than REST API.
© 2019 Magento, Inc. Page | 11
GraphQL v/s REST
© 2019 Magento, Inc. Page | 12
GraphQL v/s REST
REST GraphQL
Data Fetching Gathers data by accessing
multiple endpoints
Single query to the GraphQL server that
includes the concrete data requirements
Over- and Underfetching of
data
One of the most common
problems with REST is that
of over- and underfetching
Unlike traditional APIs, GraphQL exposes all
of the data from a single endpoint.
Rapid Product Iterations on
the Frontend
With every change that is
made to the UI, there is a
high risk that now there is
more (or less) data required
than before
changes on the client-side can be made
without any extra work on the server
Type System N/A GraphQL Schema Definition Language (SDL)
Insightful Analytics on the
Backend
Over- and Underfetching of
data are the drawbacks
Fine-grained insights about the data that’s
requested on the backend
© 2019 Magento, Inc. Page | 13
GraphQL Query
Language
© 2019 Magento, Inc. Page | 14
GraphQL Query Language
 GraphQL is an open-source query language for APIs (not databases)
developed by Facebook
 GraphQL query performs the READ operation in a GraphQL API
 It is replacement of REST
 Server-side runtime for executing queries by using a type system you
define for your data
 It is not tied to any specific database or storage engine
© 2019 Magento, Inc. Page | 15
User get what they want
© 2019 Magento, Inc. Page | 16
GraphQL in Magento
2.3
© 2019 Magento, Inc. Page | 17
Why Magento2.3 introduced GraphQL?
 GraphQL is a powerful query
language for API´s and convenient
for javascript or Progressive Web
App solutions.
 With the rise of PWA, there is a
need to get smaller amounts of
data and to make fewer API
requests.
 Allowing the requestor to request a
limited subset of attributes and
Significantly smaller responses
 Continued...
© 2019 Magento, Inc. Page | 18
 To support GraphQL, Magento is writing
an entirely new layer that interfaces
directly to the Query API
 The GraphQL implementation will be the
base on how a PWA frontend will retrieve
the data it needs
© 2019 Magento, Inc. Page | 19
Modules
© 2019 Magento, Inc. Page | 20
Current Status
Done In Progress
 Products
 Categories
 Customer
 Cms
 Coupons
 Store Config
 Shopping Cart
 Checkout
 My Account
 Wishlist
 Send to friend
© 2019 Magento, Inc. Page | 21
Magento’s GraphQL implementation
(Basic module creation)
© 2019 Magento, Inc. Page | 22
Module Structure
© 2019 Magento, Inc. Page | 23
 Defines the structure of queries.
 Determines which attributes to make available for GraphQL queries.
You can define separate lists of attributes for queries and results.
 Points to the resolvers that verify and process the query data and
response
 Serves as the source for displaying the schema in a GraphQL
browser
<module_root>/etc/schema.graphqls
© 2019 Magento, Inc. Page | 24
<module_root>/etc/schema.graphqls
© 2019 Magento, Inc. Page | 25
<module_root>/Model/Resolver/Customer.php
© 2019 Magento, Inc. Page | 26
<module_root>/Model/Resolver/Customer.php
© 2019 Magento, Inc. Page | 27
<module_root>/Model/Resolver/Customer.php
© 2019 Magento, Inc. Page | 28
ChromeiQL
 Its a simple extension wrapper around the great GraphiQL
IDE allowing it to work with any GraphQL endpoint of your
choosing.
 As long as you are authorized to send requests to the
endpoint from your current browser session (cookies are
set etc.) you are good to use ChromeiQL.
© 2019 Magento, Inc. Page | 29
Some alternates to ChromeiQL
 Insomnia
 https://support.insomnia.rest/article/61-graphql
 Altair GraphQL Client – Mozilla addon
 https://addons.mozilla.org/en-US/firefox/addon/altair-graphql-client/
© 2019 Magento, Inc. Page | 30
Set endpoint url in ChromeiQL
© 2019 Magento, Inc. Page | 31
ChromeiQL Documentation Explorer
© 2019 Magento, Inc. Page | 32
Use “testcustomer” graphQL in ChromeiQL
© 2019 Magento, Inc. Page | 33
GraphQL: Fetch combined/nested data
© 2019 Magento, Inc. Page | 34
<module_root>/etc/schema.graphqls
© 2019 Magento, Inc. Page | 35
<module_root>/Model/Resolver/Store.php
© 2019 Magento, Inc. Page | 36
<Module_Name>/Model/Resolver/Store.php
© 2019 Magento, Inc. Page | 37
Use “pickUpStore” graphQL in ChromeiQL
© 2019 Magento, Inc. Page | 38
GraphQL API Authentication
© 2019 Magento, Inc. Page | 39
Apply authentication on GraphQL Access
© 2019 Magento, Inc. Page | 40
GraphQL access with authentication
© 2019 Magento, Inc. Page | 41
GraphQL access authentication failed
© 2019 Magento, Inc. Page | 42
GraphQL Mutations
© 2019 Magento, Inc. Page | 43
GraphQL Mutation
 GraphQL queries perform read operations, mutations change
the data
 Mutations are used to perform the Create, Update, delete
operation in GraphQl.
 It is similar to POST, PUT and DELETE in REST API
© 2019 Magento, Inc. Page | 44
Basic example of mutation
© 2019 Magento, Inc. Page | 45
Magento core - mutation example
(fetch customer’s token)
© 2019 Magento, Inc. Page | 46
vendor/magento/module-customer-graph-ql/etc/schema.graphqls
© 2019 Magento, Inc. Page | 47
vendor/magento/module-customer-graph-
ql/Model/Resolver/GenerateCustomerToken.php::resolve()
© 2019 Magento, Inc. Page | 48
GraphQL Fragements
© 2019 Magento, Inc. Page | 49
 A fragment is basically a reusable piece of query.
 In GraphQL, you often need to query for the same data fields in different
queries.
 By reusing this code, we can be more efficient with our time and reuse these
pieces of query logic
GraphQL Fragements
© 2019 Magento, Inc. Page | 50
Fetch customer and pickupStore data at once
© 2019 Magento, Inc. Page | 51
Thank you!
Vishakha Borkar
Born Commerce
© 2019 Magento, Inc. Page | 52
Question!

More Related Content

PPTX
GraphQL in Magento 2
PDF
Developing Faster with Swagger
PDF
GraphQL Fundamentals
PDF
Airflow for Beginners
PDF
How to GraphQL
PDF
Airflow introduction
PPTX
Introduction to angular with a simple but complete project
PDF
Introducing Apache Airflow and how we are using it
GraphQL in Magento 2
Developing Faster with Swagger
GraphQL Fundamentals
Airflow for Beginners
How to GraphQL
Airflow introduction
Introduction to angular with a simple but complete project
Introducing Apache Airflow and how we are using it

What's hot (20)

PPT
Angular 8
PDF
Airflow presentation
PPTX
Workmanager PPTX
PDF
Python SOLID
PPTX
RESTful API - Best Practices
PDF
Apache Airflow Architecture
PPTX
Angular modules in depth
PPTX
React js
PDF
PPTX
Spring boot
PDF
Apache Airflow
PPTX
What is Swagger?
PDF
Grafana 7.0
PPTX
Introduction to React JS for beginners
PPTX
OFI Overview 2019 Webinar
PPTX
Benefits of integration with the Mulesoft Anypoint Platform
PDF
SPRING - MAVEN - REST API (ITA - Luglio 2017)
PDF
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
PDF
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
PDF
Kubeflow
Angular 8
Airflow presentation
Workmanager PPTX
Python SOLID
RESTful API - Best Practices
Apache Airflow Architecture
Angular modules in depth
React js
Spring boot
Apache Airflow
What is Swagger?
Grafana 7.0
Introduction to React JS for beginners
OFI Overview 2019 Webinar
Benefits of integration with the Mulesoft Anypoint Platform
SPRING - MAVEN - REST API (ITA - Luglio 2017)
Kafka Streams vs. KSQL for Stream Processing on top of Apache Kafka
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
Kubeflow
Ad

Similar to Magento2.3 - GraphQL introduction (20)

PDF
Graphql Overview By Chirag Dodia
PDF
PHP, the GraphQL ecosystem and GraphQLite
PPTX
Introduction to GraphQL
PPTX
GraphQL - Tidepool Labs
PDF
Intro to GraphQL
PPTX
GraphQl Introduction
PDF
API Management for GraphQL
PPTX
Taking Control of your Data with GraphQL
PDF
GraphQL + relay
PDF
GraphQL Bangkok meetup 5.0
PPT
Graphql presentation
PDF
Graphql
PDF
London React August - GraphQL at The Financial Times - Viktor Charypar
PDF
GraphQL the holy contract between client and server
PDF
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
PDF
GraphQL over REST at Reactathon 2018
PDF
James Zetlen - PWA Studio Integration…With You
PDF
GraphQL - A love story
PDF
GraphQL vs REST_ Choosing the Best API for Shopify Headless Commerce Developm...
PDF
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
Graphql Overview By Chirag Dodia
PHP, the GraphQL ecosystem and GraphQLite
Introduction to GraphQL
GraphQL - Tidepool Labs
Intro to GraphQL
GraphQl Introduction
API Management for GraphQL
Taking Control of your Data with GraphQL
GraphQL + relay
GraphQL Bangkok meetup 5.0
Graphql presentation
Graphql
London React August - GraphQL at The Financial Times - Viktor Charypar
GraphQL the holy contract between client and server
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
GraphQL over REST at Reactathon 2018
James Zetlen - PWA Studio Integration…With You
GraphQL - A love story
GraphQL vs REST_ Choosing the Best API for Shopify Headless Commerce Developm...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation theory and applications.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation theory and applications.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Programs and apps: productivity, graphics, security and other tools
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Magento2.3 - GraphQL introduction

  • 1. © 2019 Magento, Inc. Page | 1 Magento 2.3 Introduction to GraphQL
  • 2. © 2019 Magento, Inc. . Page | 2 Senior Software Engineer at BORN Group https://www.linkedin.com/in/vishakha-borkar-9b96bb61 Vishakha Borkar
  • 3. © 2019 Magento, Inc. Page | 3 Agenda
  • 4. © 2019 Magento, Inc. Page | 4 Agenda • Challenges with REST • History and Adoption • What is GraphQL? • GraphQL v/s REST • GraphQL Query Language • GraphQL in Magento • Magento GraphQL Implemenation • GraphQL: Fetch combined/nested data • GraphQL Mutations • GraphQL Fragementation •
  • 5. © 2019 Magento, Inc. Page | 5 Challenges with REST
  • 6. © 2019 Magento, Inc. Page | 6 Challenges with REST  Increased mobile usage creates need for efficient data loading  Variety of different frontend frameworks and platforms  Fast development & expectation for rapid feature development
  • 7. © 2019 Magento, Inc. Page | 7 History and Adoption
  • 8. © 2019 Magento, Inc. Page | 8 History and Adoption  Facebook started using GraphQL in 2012 in their native mobile apps  Initially used and introduced with React.js  Can be used everywhere a client needs to communicate with API  Used by many companies. To name a few GitHub, Twitter, Yelp, Coursea and Shopify
  • 9. © 2019 Magento, Inc. Page | 9 What is GraphQL?
  • 10. © 2019 Magento, Inc. Page | 10 What is GraphQL? • GraphQL is a very powerful and strongly typed query language. • Used to communicate data between client and server. GraphQL provides a complete and understandable description of the data in your API • Gives clients the power to ask for exactly what they need, making it easier to evolve APIs over time • Enables powerful development tools and thus making GraphQL a more flexible & efficient approach than REST API.
  • 11. © 2019 Magento, Inc. Page | 11 GraphQL v/s REST
  • 12. © 2019 Magento, Inc. Page | 12 GraphQL v/s REST REST GraphQL Data Fetching Gathers data by accessing multiple endpoints Single query to the GraphQL server that includes the concrete data requirements Over- and Underfetching of data One of the most common problems with REST is that of over- and underfetching Unlike traditional APIs, GraphQL exposes all of the data from a single endpoint. Rapid Product Iterations on the Frontend With every change that is made to the UI, there is a high risk that now there is more (or less) data required than before changes on the client-side can be made without any extra work on the server Type System N/A GraphQL Schema Definition Language (SDL) Insightful Analytics on the Backend Over- and Underfetching of data are the drawbacks Fine-grained insights about the data that’s requested on the backend
  • 13. © 2019 Magento, Inc. Page | 13 GraphQL Query Language
  • 14. © 2019 Magento, Inc. Page | 14 GraphQL Query Language  GraphQL is an open-source query language for APIs (not databases) developed by Facebook  GraphQL query performs the READ operation in a GraphQL API  It is replacement of REST  Server-side runtime for executing queries by using a type system you define for your data  It is not tied to any specific database or storage engine
  • 15. © 2019 Magento, Inc. Page | 15 User get what they want
  • 16. © 2019 Magento, Inc. Page | 16 GraphQL in Magento 2.3
  • 17. © 2019 Magento, Inc. Page | 17 Why Magento2.3 introduced GraphQL?  GraphQL is a powerful query language for API´s and convenient for javascript or Progressive Web App solutions.  With the rise of PWA, there is a need to get smaller amounts of data and to make fewer API requests.  Allowing the requestor to request a limited subset of attributes and Significantly smaller responses  Continued...
  • 18. © 2019 Magento, Inc. Page | 18  To support GraphQL, Magento is writing an entirely new layer that interfaces directly to the Query API  The GraphQL implementation will be the base on how a PWA frontend will retrieve the data it needs
  • 19. © 2019 Magento, Inc. Page | 19 Modules
  • 20. © 2019 Magento, Inc. Page | 20 Current Status Done In Progress  Products  Categories  Customer  Cms  Coupons  Store Config  Shopping Cart  Checkout  My Account  Wishlist  Send to friend
  • 21. © 2019 Magento, Inc. Page | 21 Magento’s GraphQL implementation (Basic module creation)
  • 22. © 2019 Magento, Inc. Page | 22 Module Structure
  • 23. © 2019 Magento, Inc. Page | 23  Defines the structure of queries.  Determines which attributes to make available for GraphQL queries. You can define separate lists of attributes for queries and results.  Points to the resolvers that verify and process the query data and response  Serves as the source for displaying the schema in a GraphQL browser <module_root>/etc/schema.graphqls
  • 24. © 2019 Magento, Inc. Page | 24 <module_root>/etc/schema.graphqls
  • 25. © 2019 Magento, Inc. Page | 25 <module_root>/Model/Resolver/Customer.php
  • 26. © 2019 Magento, Inc. Page | 26 <module_root>/Model/Resolver/Customer.php
  • 27. © 2019 Magento, Inc. Page | 27 <module_root>/Model/Resolver/Customer.php
  • 28. © 2019 Magento, Inc. Page | 28 ChromeiQL  Its a simple extension wrapper around the great GraphiQL IDE allowing it to work with any GraphQL endpoint of your choosing.  As long as you are authorized to send requests to the endpoint from your current browser session (cookies are set etc.) you are good to use ChromeiQL.
  • 29. © 2019 Magento, Inc. Page | 29 Some alternates to ChromeiQL  Insomnia  https://support.insomnia.rest/article/61-graphql  Altair GraphQL Client – Mozilla addon  https://addons.mozilla.org/en-US/firefox/addon/altair-graphql-client/
  • 30. © 2019 Magento, Inc. Page | 30 Set endpoint url in ChromeiQL
  • 31. © 2019 Magento, Inc. Page | 31 ChromeiQL Documentation Explorer
  • 32. © 2019 Magento, Inc. Page | 32 Use “testcustomer” graphQL in ChromeiQL
  • 33. © 2019 Magento, Inc. Page | 33 GraphQL: Fetch combined/nested data
  • 34. © 2019 Magento, Inc. Page | 34 <module_root>/etc/schema.graphqls
  • 35. © 2019 Magento, Inc. Page | 35 <module_root>/Model/Resolver/Store.php
  • 36. © 2019 Magento, Inc. Page | 36 <Module_Name>/Model/Resolver/Store.php
  • 37. © 2019 Magento, Inc. Page | 37 Use “pickUpStore” graphQL in ChromeiQL
  • 38. © 2019 Magento, Inc. Page | 38 GraphQL API Authentication
  • 39. © 2019 Magento, Inc. Page | 39 Apply authentication on GraphQL Access
  • 40. © 2019 Magento, Inc. Page | 40 GraphQL access with authentication
  • 41. © 2019 Magento, Inc. Page | 41 GraphQL access authentication failed
  • 42. © 2019 Magento, Inc. Page | 42 GraphQL Mutations
  • 43. © 2019 Magento, Inc. Page | 43 GraphQL Mutation  GraphQL queries perform read operations, mutations change the data  Mutations are used to perform the Create, Update, delete operation in GraphQl.  It is similar to POST, PUT and DELETE in REST API
  • 44. © 2019 Magento, Inc. Page | 44 Basic example of mutation
  • 45. © 2019 Magento, Inc. Page | 45 Magento core - mutation example (fetch customer’s token)
  • 46. © 2019 Magento, Inc. Page | 46 vendor/magento/module-customer-graph-ql/etc/schema.graphqls
  • 47. © 2019 Magento, Inc. Page | 47 vendor/magento/module-customer-graph- ql/Model/Resolver/GenerateCustomerToken.php::resolve()
  • 48. © 2019 Magento, Inc. Page | 48 GraphQL Fragements
  • 49. © 2019 Magento, Inc. Page | 49  A fragment is basically a reusable piece of query.  In GraphQL, you often need to query for the same data fields in different queries.  By reusing this code, we can be more efficient with our time and reuse these pieces of query logic GraphQL Fragements
  • 50. © 2019 Magento, Inc. Page | 50 Fetch customer and pickupStore data at once
  • 51. © 2019 Magento, Inc. Page | 51 Thank you! Vishakha Borkar Born Commerce
  • 52. © 2019 Magento, Inc. Page | 52 Question!