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
Hello World 2018 - GraphQL A query language for...
Search
Hello World Tech Conference
February 15, 2018
Programming
1
81
Hello World 2018 - GraphQL A query language for your API
Hello World Tech Conference
February 15, 2018
Tweet
Share
More Decks by Hello World Tech Conference
See All by Hello World Tech Conference
Hello World 2018 - Learn how to get that dream job at Google!
helloworldconf
0
110
Hello World 2018 - Introduction to Swift
helloworldconf
0
61
Hello World 2018 - Understanding attacker behaviors, motivations and common ways of operation
helloworldconf
0
69
Hello World 2018 - We need to talk about Preact
helloworldconf
1
77
Hello World 2018 - Why Ruby?
helloworldconf
0
45
Hello World 2018 - Recent Advances in Machine Learning
helloworldconf
0
65
Hello World 2018 - Quality from the start
helloworldconf
0
32
Hello World 2017 - React Native
helloworldconf
0
110
Hello World 2017 - Testing & QA - Carreira Profissional?
helloworldconf
0
82
Other Decks in Programming
See All in Programming
Claude Code で Astro blog を Pages から Workers へ移行してみた
codehex
0
180
Workers を定期実行する方法は一つじゃない
rokuosan
0
140
11年かかって やっとVibe Codingに 時代が追いつきましたね
yimajo
1
250
DynamoDBは怖くない!〜テーブル設計の勘所とテスト戦略〜
hyamazaki
0
190
SwiftでMCPサーバーを作ろう!
giginet
PRO
2
230
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
5
580
Google I/O Extended Incheon 2025 ~ What's new in Android development tools
pluu
1
250
STUNMESH-go: Wireguard NAT穿隧工具的源起與介紹
tjjh89017
0
270
React 使いじゃなくても知っておきたい教養としての React
oukayuka
18
5.5k
Strands Agents で実現する名刺解析アーキテクチャ
omiya0555
1
110
Vibe coding コードレビュー
kinopeee
0
420
202507_ADKで始めるエージェント開発の基本 〜デモを通じて紹介〜(奥田りさ)The Basics of Agent Development with ADK — A Demo-Focused Introduction
risatube
PRO
6
1.4k
Featured
See All Featured
Site-Speed That Sticks
csswizardry
10
760
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
RailsConf 2023
tenderlove
30
1.2k
GitHub's CSS Performance
jonrohan
1031
460k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
How STYLIGHT went responsive
nonsquared
100
5.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
183
54k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
19k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Transcript
GraphQL A query language for your API Porto, 15th Feb
2018 Alexis Mas - @_Axxiss
2 { "data": { "speaker": { "firstName": “Alexis", "lastName": “Mas",
"role": “Software Engineer", "company": “XING", "twitter": “@_Axxiss“ } } } query me { speaker { firstName lastName role company twitter } }
What is GraphQL? 3
GraphQL is a Specification http://facebook.github.io/graphql/October2016/
5 GraphQL is a query language for APIs and a
server-side runtime for fulfilling those queries with your existing data.
6 At its simplest, GraphQL is about asking for specific
fields on objects
7 Agnostic of its surroundings HTTP Web sockets SSH Web
service File Database
8 Powerful Tooling
9 •A specification •A query language for APIs •A server-side
runtime TL;DR: What is GraphQL?
10 How can we use it?
11 Queries Mutations
12 query Person { person(id: "cGVvcGxlOjE=") { name homeworld {
name } } } A query and its response { "data": { "person": { "name": "Luke Skywalker", "homeworld": { "name": "Tatooine" } } }, "errors": null, "extensions": null }
13 Anatomy of a query query Person { person(id: "cGVvcGxlOjE=")
{ name homeworld { name } } }
14 query Person { person(id: "cGVvcGxlOjE=") { name homeworld {
name } } } Operation definition Anatomy of a query
15 query Person { person(id: "cGVvcGxlOjE=") { name homeworld {
name } } } Operation definition Argument name & value Anatomy of a query
16 query Person { person(id: "cGVvcGxlOjE=") { name homeworld {
name } } } Operation definition Argument name & value Selection Anatomy of a query
17 Operation definition Argument name & value Selection Anatomy of
a query query Person { person(id: "cGVvcGxlOjE=") { name homeworld { name } } }
18 Running a query query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } POST https://a-graphql-service.com/api { "query": "query Person { … }" }
19 POST https://a-graphql-service.com/api { "query": "query Person { … }"
} Running a query { "data": { "person": { "name": "Luke Skywalker", "homeworld": { "name": "Tatooine" } } }, "errors": null, "extensions": null }
20 Ask what you need, get exactly that query Person
{ person(id: "cGVvcGxlOjE=") { name homeworld { name } } } { "data": { "person": { "name": "Luke Skywalker", "homeworld": { "name": "Tatooine" } } }, "errors": null, "extensions": null }
21 Let’s use variables •Avoid string manipulation •Use dynamic values
•Reuse existent queries query Person { person(id: "cGVvcGxlOjE=") { name homeworld { name } } }
22 $Variables query Person($personID: ID!) { person(id: "cGVvcGxlOjE=") { name
homeworld { name } } } Variable definition
23 $Variables query Person($personID: ID!) { person(id: $personID) { name
homeworld { name } } } Variable definition Variable reference
24 $Variables query Person($personID: ID!) { person(id: $personID) { name
homeworld { name } } } { "personID": "cGVvcGxlOjE=" } Variable definition Variable reference Variable value
25 $Variables query Person($personID: ID!) { person(id: $personID) { name
homeworld { name } } } { "personID": "cGVvcGxlOjE=" } Variable definition Variable reference Variable value
26 Running a query with variables POST https://a-graphql-service.com/api { "query":
"query Person($pers…", "variables": { "personID": "cGVvcGxlOjE" } } { "data": { "person": { "name": "Luke Skywalker", "homeworld": { "name": "Tatooine" } } }, "errors": null, "extensions": null }
27 Lets break it! query Person($personID: ID!) { pessoa(id: $personID)
{ name homeworld { name } } } { "personID": "cGVvcGxlOjE=" }
28 Something went wrong… { "errors": [ { “message": "Cannot
query field \"pessoa\" on type \”Root\”. Did you mean \”person\"?", "locations": [ { "line": 16, “column": 3 } ] } ] }
29
30 Mutation mutation UpdateName($input: UpdateNameInput) { updatePerson(input: $input) { name
homeworld { name } } } { “input”: { id: “cGVvcGxlOjE=“, name: “Korl Marcus“} }
31 Just another response { "data": { "person": { "name":
“Korl Marcus”, "homeworld": { "name": "Tatooine" } } }, “errors": null, “extensions”: null }
32 •Queries: fetch data •Mutations: change data •Use variables for
dynamic values TL;DR: How can we use it?
How does it work? 33
34 Use cases Single application API API Gateway
35
36 Client Engine Source (1) Send request (5) Send response
(2) Validate request (3) Get data (3) Get data (4) Aggregate data
37 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } }
38 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] }
39 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] }
40 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] }
41 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] }
42 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] }
43 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] }
44 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] } Scalars
45 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] } Scalars Objects
46 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] } Scalars Objects Non-null
47 The type system query Person { person(id: "cGVvcGxlOjE=") {
name homeworld { name } } } type Query { person(id: ID!): Person! } type Person { id: ID! name: String height: Int homeworld: Planet } type Planet { id: ID! name: String climates: [String] } Scalars Objects Non-null Lists
48 Scalars Int Float String Boolean ID Complex Object InputObject
Enum Interfaces
49 Wrapper types ID can be null? List can be
null? ID YES What list? ID! NO What list? [ID] YES YES [ID!] NO YES [ID]! YES NO [ID!]! NO NO
50 Client Engine Source (1) Send request (5) Send response
(2) Validate request (3) Get data (3) Get data (4) Aggregate data
Questions? Alexis Mas @_Axxiss
What now? 52
53 graphql.org/swapi-graphql
54 graphql.org howtographql.com YouTube: GraphQL Summit 2016 / 2017 GraphQL
Europe 2017
55
Thank you! Alexis Mas @_Axxiss