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
740
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
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
140
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
330
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
1k
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
250
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.1k
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
Outline View in SwiftUI
1024jp
1
160
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.6k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
Java ジェネリクス入門 2024
nagise
0
610
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
BBQ
matthewcrist
85
9.3k
Building Your Own Lightsaber
phodgson
102
6.1k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Music & Morning Musume
bryan
46
6.1k
Producing Creativity
orderedlist
PRO
341
39k
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!