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 your API
Search
Hello World Tech Conference
February 15, 2018
Programming
1
77
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
100
Hello World 2018 - Introduction to Swift
helloworldconf
0
57
Hello World 2018 - Understanding attacker behaviors, motivations and common ways of operation
helloworldconf
0
59
Hello World 2018 - We need to talk about Preact
helloworldconf
1
75
Hello World 2018 - Why Ruby?
helloworldconf
0
39
Hello World 2018 - Recent Advances in Machine Learning
helloworldconf
0
59
Hello World 2018 - Quality from the start
helloworldconf
0
29
Hello World 2017 - React Native
helloworldconf
0
110
Hello World 2017 - Testing & QA - Carreira Profissional?
helloworldconf
0
76
Other Decks in Programming
See All in Programming
How to improve maintainability and readability of your automated tests? ( #scrumniigata )
teyamagu
PRO
1
130
slow types ってなんだろう?
karad
0
210
How to implement a RubyVM with PHP?
memory1994
PRO
2
410
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
2
140
TypeScriptでもLLMアプリケーション開発 / LLM Application In Typescript
rkaga
5
1.3k
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
74k
JavaScript Closure
asoluka
0
2k
TypeScript Custom GitHub Action Development Tips
peaceiris
2
460
Namespace, What and Why
tagomoris
3
690
freeeのエンジニアが 就活で出そうな コーディングテストを 解説してみる
freee
1
170
欠陥を早期に発見するための Software Engineer in Test とその重要性 / What is Software Engineer in Test and How they works
orgachem
PRO
17
2.4k
Amazon Aurora Serverless v2が意外と高かった話と、AWS Database Migration Serviceの話
satoshi256kbyte
1
110
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
33
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
12
1.1k
Writing Fast Ruby
sferik
622
60k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
23
1.7k
Being A Developer After 40
akosma
67
580k
How to name files
jennybc
65
94k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
245
20k
RailsConf 2023
tenderlove
9
580
How to train your dragon (web standard)
notwaldorf
75
5.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
17
2.7k
Designing Experiences People Love
moore
136
23k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
123
39k
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