Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to GraphQL
Search
Adrián Matellanes
September 23, 2017
Programming
4
760
Introduction to GraphQL
Learn about GraphQL, how it works, and how to use it.
Adrián Matellanes
September 23, 2017
Tweet
Share
More Decks by Adrián Matellanes
See All by Adrián Matellanes
Test-Driven Development
amatellanes
2
110
Practical Monitoring
amatellanes
0
77
Making code compatible with Python 2 and 3
amatellanes
0
1.2k
Python Gotchas
amatellanes
3
1.5k
Cómo construir un API del que tus padres se sientan orgullosos
amatellanes
4
1.2k
Unicode: WTF?
amatellanes
1
910
Málaga Python Meetup
amatellanes
0
140
Other Decks in Programming
See All in Programming
Haze - Real time background blurring
chrisbanes
1
520
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
190
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Go の GC の不得意な部分を克服したい
taiyow
3
800
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
790
선언형 UI에서의 상태관리
l2hyunwoo
0
180
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
testcontainers のススメ
sgash708
1
120
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
110
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Building an army of robots
kneath
302
44k
Gamification - CAS2011
davidbonilla
80
5.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Facilitating Awesome Meetings
lara
50
6.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Transcript
Introduction to GraphQL
GET https://2017.es.pycon.org/speakers/me { "name": "Adrián Matellanes", "roles": [ "Lead API
Developer", "Málaga Python Organizer" ], "worksAt": "Ebury", "twitter": "@_amatellanes", "github": "github.com/amatellanes" }
What’s GraphQL?
A programming language
A special type of database
A library
A Query Language for APIs
Why GraphQL?
Due to the nature of REST
REST Problems
GET /characters/1 { "name": "Jon Snow" }
"url": "http://anapioficeandfire.com/api/characters/583", "name": "Jon Snow", "culture": "Northmen", "born": "In 283
AC", "titles": [ "Lord Commander of the Night's Watch" ], "aliases": [ "Lord Snow", "Ned Stark's Bastard", "The Snow of Winterfell", "The Bastard of Winterfell", "Lord Crow" ], "allegiances": [ "http://anapioficeandfire.com/api/houses/362" ], "books": [ "http://anapioficeandfire.com/api/books/5" ], "povBooks": [ "http://anapioficeandfire.com/api/books/1", "http://anapioficeandfire.com/api/books/2", "http://anapioficeandfire.com/api/books/3", "http://anapioficeandfire.com/api/books/8"
Round Trip and Repeat Trip Times
None
/episodes/1
/episodes/1 /characters/345 /characters/563 /characters/802 /characters/441 /characters/674
/episodes/1 /characters/345 /characters/563 /characters/802 /characters/441 /characters/674 /reviews/3512
Over/Under Fetching
/episodes/1?fields=characters(name,playedBy)
/episode_with_all_stuff /episode_with_amazing_pictures /episode_with_stuff_i_need_today /episode_with_stuff_for_mobile_app /episode_with_actors_and_reviews_and_images /episode_with_stuff_for_mobile_app_v2 /episode_with_actors_and_reviews_but_no_images
/episode_with_all_stuff /episode_with_amazing_pictures /episode_with_stuff_i_need_today /episode_with_stuff_for_mobile_app /episode_with_stuff_for_mobile_app_v2 /episode_with_actors_and_reviews_and_images /episode_with_actors_and_reviews_but_no_images
None
https://code.facebook.com/projects/
Created July 1, 2015 Updated September 20, 2017 381 Forks
6,078 Stars 302 Commits 82 Open Issues https://github.com/facebook/graphql
None
“You will receive what you ask for no more, no
less.” - Mark Allen
None
None
None
None
None
None
None
None
None
None
None
GraphQL vs. REST
REST Model
Client /books /characters /houses Databases Services External APIs
GraphQL Model
Client Databases Services External APIs /graphql/
Anatomy of a GraphQL
{ me { name } }
{ me { name } } { "me": { "name":
"Jon Snow" } }
Scalar types
Int Float String Boolean ID Date enum
GraphQL Schema Definition Language
type Query { allCharacters: [Character]! character(id: ID!): Character }
type Query { allCharacters: [Character]! character(id: ID!): Character } Root
Type
type Query { allCharacters: [Character]! character(id: ID!): Character } Root
Fields
type Query { allCharacters: [Character]! character(id: ID!): Character } Arguments
type Query { allCharacters: [Character]! character(id: ID!): Character } Return
Types
type Character { name: String! house: House! } type House
{ name: String! words: String! members: [Character]! }
type Character { name: String! house: House! } type House
{ name: String! words: String! members: [Character]! } Object Type
type Character { name: String! house: House! } type House
{ name: String! words: String! members: [Character]! } Fields
type Character { name: String! house: House! } type House
{ name: String! words: String! members: [Character]! } Return Types
Queries for fetching data from the server
query CharactersNameAndHouse { allCharacters { name house { words }
} }
query CharactersNameAndHouse { allCharacters { name house { words }
} } Operation Type
query CharactersNameAndHouse { allCharacters { name house { words }
} } Operation Name
query CharactersNameAndHouse { allCharacters { name house { words }
} } Selection Set
query CharactersNameAndHouse { allCharacters { name house { words }
} } Fields
query CharactersNameAndHouse { allCharacters { name house { words }
} } { "data": { "allCharacters": [ { "name": "Daenerys Targaryen", "house": { "words": "Fire and Blood" } }, { "name": "Jon Snow", "house": { "words": "Winter Is Coming" } } ] } }
query { character(name: "Hodor") { name house { words }
} } Arguments
query CharacterByName($name: String!) { character(name: $name) { name } }
{ "name": "Hodor" } Variables
query { character(name: "Hodor") { ...CharacterFragment } } fragment CharacterFragment
on Character { name house { words } } Fragments
{ character(name: "Hodor") { ... on Character { name house
{ words } } } } Inline Fragments
Mutations for manipulating data and fetch the updated result
type Mutation { createCharacter(name: String!): Character }
mutation CharacterMutation { createCharacter(name: "Sansa Stark") { name } }
{ "data": { "createCharacter": { "name": "Sansa Stark" } } }
Subscriptions for real-time updates
type Subscription { newCharacter: Character! }
subscription NewCharacterSubscription { newCharacter { name } } { "data":
{ "newCharacter": { "name": "Tyrion Lannister" } } }
Query Execution
{ getHouse(id: 5) { name words members { name }
} }
name words members getHouse(id: 5) { name, words, members }
[ { name }, { name } ] name name
QUERY name words members getHouse(id: 5) { name, words, members
} [ { name }, { name } ] name name
QUERY getHouse(id: 5) { name, words, members } HOUSE name
words members [ { name }, { name } ] name name
QUERY getHouse(id: 5) { name, words, members } HOUSE name
words members [ { name }, { name } ] CHARACTER name name
Clients with Super Powers
Introspection Queries
{ "data": { "__type": { "name": "Book", "kind": "OBJECT", "fields":
[ { "name": "title", "type": { "name": "String" } } ] } } } { __type(name: "Book") { name kind fields { name type { name } } } }
None
GraphiQL
None
Graphene GraphQL framework for Python
Created September 24, 2015 Updated September 20, 2017 229 Forks
2,356 Stars 1,219 Commits 87 Open Issues https://github.com/graphql-python/graphene
None
None
"It’s important to understand that it isn’t all or nothing.
GraphQL is in our future, but it isn’t our exclusive future."
Thank you!