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
68
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
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
220
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
280
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
240
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
330
Goで作る、開発・CI環境
sin392
0
260
Hack Claude Code with Claude Code
choplin
6
2.4k
ご注文の差分はこちらですか? 〜 AWS CDK のいろいろな差分検出と安全なデプロイ
konokenj
3
470
NEWT Backend Evolution
xpromx
1
110
Deep Dive into ~/.claude/projects
hiragram
14
11k
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
12k
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
12
6.7k
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
900
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Music & Morning Musume
bryan
46
6.7k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
54k
We Have a Design System, Now What?
morganepeng
53
7.7k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
47
9.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
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