Introduction to GraphQL
Course: Internet Programming Term: Spring-2017 By: Sangeeta Ashrit
Agenda
• Introduction toGraphQL
• History of GraphQL
• Queries & Mutations
• Schemas & Types
• Validations & Executions
• Compared toREST
• Demo Examples
• Q&A
• Facebook use to have web
framework for mobile apps.
History of GraphQL
Facebook Current Native App :
Today, Facebook gets more than260 billion requests/day
What isGraphQL?
What is GraphQL ?
• GraphQL is a query language
• Specification for a server to execute queries
What Graph is NOT !
• Its not a database
• Not a library
• Not a storage engine
• Not language specific
How GraphQL works?
iOS App
Android App
Web App
Desktop App
GraphQL
Server
Data
Data
GraphQL
Queries
JSON
Payload
1
2
GraphQL Query Example
Schemas & Types
• Type System
• Type Language
• Enumerations, Lists, Interface creation
• Aliases
• Fragments
Schemas & Types Explanation
Type System:
Schemas & Types Explanation
Aliases:
Schemas & Types Explanation
Fragments:
Schemas & Types Explanation
Fragments:
Grace
Validations
1.Minimal code changes to adapt
Other Benefits of GraphQL
Other Benefits of GraphQL
2.No need to maintain versioning informations
Other Benefits of GraphQL
REST Vs GraphQL
• Shopify claims : As application grows larger, REST architecture often becomes
unmanageable
• Using REST, over fetching/under fetching of data becomes part of the application
development.
• Handling custom endpoints, multiple end points can be time consuming/costly
effort.
Custom
Endpoint 1
Custom
Endpoint2
2
Custom
Endpoint 3
Custom
Endpoint 4
Custom
Endpoint 5
Custom
Endpoint 6
View 1 View 2 View 3 View 4 View 5 View 6
REST: Custom End Points
GraphQL:
GraphQL
View 1 View 2 View ‘n’
Advantages
• What you see is what you get
• Client specificdata
• Application layerprotocol
• Strong typed
• Self documenting
• Existing backendAPIs
• RFC - http://facebook.github.io/graphql
• Extra powers with Relay and React
• Introspection
• Active community
Disadvantages
• No select *
• Args can become enormous
• Boilerplate
Who’s Using GraphQL:
References:
• http://graphql.org/graphql-js/
• https://facebook.github.io/graphql/
• http://graphql.org/graphql-js/running-an-express-graphql-server/
• https://www.youtube.com/watch?v=WQLzZf34FJ8
Thank you!
Questions?
Sangeeta Ashrit
City College of New York
sangeeta2288

Introduction to GraphQL