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
82
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
63
Hello World 2018 - Understanding attacker behaviors, motivations and common ways of operation
helloworldconf
0
70
Hello World 2018 - We need to talk about Preact
helloworldconf
1
78
Hello World 2018 - Why Ruby?
helloworldconf
0
47
Hello World 2018 - Recent Advances in Machine Learning
helloworldconf
0
67
Hello World 2018 - Quality from the start
helloworldconf
0
33
Hello World 2017 - React Native
helloworldconf
0
110
Hello World 2017 - Testing & QA - Carreira Profissional?
helloworldconf
0
83
Other Decks in Programming
See All in Programming
Namespace and Its Future
tagomoris
6
700
より安全で効率的な Go コードへ: Protocol Buffers Opaque API の導入
shwatanap
2
360
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
400
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
540
ぬるぬる動かせ! Riveでアニメーション実装🐾
kno3a87
1
230
Kiroで始めるAI-DLC
kaonash
2
610
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
870
概念モデル→論理モデルで気をつけていること
sunnyone
3
290
Performance for Conversion! 分散トレーシングでボトルネックを 特定せよ
inetand
0
2.4k
旅行プランAIエージェント開発の裏側
ippo012
2
920
AI時代のUIはどこへ行く?
yusukebe
18
9k
@Environment(\.keyPath)那么好我不允许你们不知道! / atEnvironment keyPath is so good and you should know it!
lovee
0
120
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
431
66k
Faster Mobile Websites
deanohume
309
31k
Code Reviewing Like a Champion
maltzj
525
40k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Side Projects
sachag
455
43k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Being A Developer After 40
akosma
90
590k
Writing Fast Ruby
sferik
628
62k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Documentation Writing (for coders)
carmenintech
74
5k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
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