GraphQL…
What’s up with 
that?
by Martin Heidegger
Why me?
Martin Heidegger
https://github.com/martinheidegger
±15 years experience

Webservices, Rest, RPC, JSON(p),
Keep-Alive Communication,
Dynamic JavaScript, HTML-based
Protocols
6 months GraphQL project

PostgraphQL contributor
Hello!
We are awesome!
Please, start!
Start already!
• What problem does GraphQL solve?
• What is GraphQL?
• How is it solved?
• Try out some GraphQL
• Is it the future?
in the next 15 minutes…
Show us the
Problem!
Data
Device
Device
GraphQL…
What’s up with
that?
GraphQL…
What’s up with
that?
Server
Server
Server
Server
Server Devices
Server Devices
Connection
Server Devices
Connection
Devices
Connection
Devices
Connection
Bottleneck!
Devices
Connection
Devices
Connection
Devices
Connection
Select
Less abstract
please!
Filtering
VS
Little data Lots of data
What is
GraphQL?
GraphQL is not…
… a server
… a database
… a client
… finalized
… a crazy monkey
GraphQL
GraphQL
Graph

Query

Language
language

is for

talking
language

is for

talking
GraphQL is…
… a language specification
… modern
… for clients (that can make mistakes)
… for servers (that can make mistakes)
… a crazy monkey
We want some
Background!
https://avatars2.githubusercontent.com/u/914122?v=3&s=460
GraphQL ❤ URLs!
https://en.wikipedia.org/wiki/URL
How? Server Object
Parameters
https://en.wikipedia.org/wiki/SQL

https://en.wikipedia.org/wiki/Join_(SQL)
SELECT users.id, users.name, users.email
FROM users
WHERE id=“leichtgewicht”
GraphQL 💪 == 💪 SQL
SELECT users.id, users.name, users.email, files.url
FROM users
WHERE id=“leichtgewicht”
INNER JOIN files
ON users.avatarID = files.id
https://en.wikipedia.org/wiki/SQL

https://en.wikipedia.org/wiki/Join_(SQL)
GraphQL 💪 == 💪 SQL
WSDL 💡→ GraphQL💡
https://en.wikipedia.org/wiki/Web_Services_Description_Language
<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://www.w3.org/ns/wsdl"
targetNamespace=“http://www.tmsws.com/wsdl20sample”>
<documentation>This is a sample WSDL 2.0 document.</documentation>
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/wsdl20sample">
<xs:element name="request"> ... </xs:element>
<xs:element name="response"> ... </xs:element>
</xs:schema>
</types>
<interface name="Interface1">
<fault name="Error1" element="tns:response"/>
<operation name="Get" pattern="http://www.w3.org/ns/wsdl/in-out">
<input messageLabel="In" element="tns:request"/>
<output messageLabel="Out" element="tns:response"/>
</operation>
</interface>
<service name="Service1" interface="tns:Interface1">
<endpoint name="HttpEndpoint"
binding="tns:HttpBinding"
address="http://www.example.com/rest/"/>
Show us
GraphQL already!
One URL per set!
curl -X POST https://api.github.com/graphql
One URL per set!
curl -X POST https://api.github.com/graphql
+ all advantages of http (proxy-able, works in browser)
+ easy setup like SQL
+ security through http headers
- not human friendly (like REST)
GET PUT DELETE HEAD PATCH
OPTIONS POST✅ CONNECT
Everything is
POST
GET PUT DELETE HEAD PATCH
OPTIONS POST✅ CONNECT
+ no old data, ever! (no caching)
+ secure
- not human friendly (can not send a request to anyone)
Everything is
POST
JSON based
transport
{
"query": "...",
"operationName": "...",
"variables": {
"myVariable": “…”,
…
}
}
{
"data": { ... },
"errors": [ ... ]
}
Request Response
JSON based
transport
+ Quick & Easy in the browser
+ human readable
{
"query": "...",
"operationName": "...",
"variables": {
"myVariable": “…”,
…
}
}
{
"data": { ... },
"errors": [ ... ]
}
Request Response
JSON based
transport
+ Quick & Easy in the browser
+ human readable
- Not friendly for binary data
{
"query": "...",
"operationName": "...",
"variables": {
"myVariable": “…”,
…
}
}
{
"data": { ... },
"errors": [ ... ]
}
Request Response
JSON based
transport
+ Quick & Easy in the browser
+ human readable
- Not friendly for binary data
{
"query": "...",
"operationName": "...",
"variables": {
"myVariable": “…”,
…
}
}
Request {
"data": { ... },
"errors": [ ... ]
}
Response
Request {
"data": { ... },
"errors": [ ... ]
}
Response{
"query": “{
user {
name
}
}”,
}
Request {
"data": { ... },
"errors": [ ... ]
}
Response{
"query": “{
user {
name
}
}”,
}
Graph
Query Language
Request {
"data": { ... },
"errors": [ ... ]
}
Response{
"query": “{
user {
name
}
}”,
}
+ simple (few rules)
+ space efficient
Graph
Query Language
Request {
"data": { ... },
"errors": [ ... ]
}
Response{
"query": “{
user {
name
}
}”,
}
+ simple (few rules)
+ space efficient
- something you need to learn
Graph
Query Language
Concept
{
field
field
…
}
Concept
query {
field
field
…
}
a simple query
{
"query": “{
user {
name
}
}”,
}
basic
Concept
{
field
field
…
}
Query Language Query
query {
serverName
serverIp
}
Concept
query {
field
field
…
}
basic
Query Language Query
query {
serverName
serverIp
}
Example Response
{
“data”: {
“serverName”: “www.scrapbox.io",
“serverIp”: “127.0.0.1”
}
}
basic
Query Language Query
query {
serverName
serverIp
}
Example Response
{
“data”: {
“serverName”: “www.scrapbox.io",
“serverIp”: “127.0.0.1”
}
}
basic
Same Format
+ consistent
Query Language Query
query {
serverName
serverIp
}
Example Response
{
“data”: {
“serverName”: “www.scrapbox.io",
“serverIp”: “127.0.0.1”
}
}
basic
Same Format
+ consistent
+ easy to understand
Query Language Query
query {
serverName
serverIp
}
Example Response
{
“data”: {
“serverName”: “www.scrapbox.io",
“serverIp”: “127.0.0.1”
}
}
basic
Same Format
+ consistent
+ easy to understand
+ less bugs
Query Language Query
query {
serverName
serverIp
}
Example Response
{
“data”: {
“serverName”: “www.scrapbox.io",
“serverIp”: “127.0.0.1”
}
}
basic
SELECT apps.serverName,
apps.serverIp
FROM apps
WHERE id=“myApp””
SQL equivalent
child properties
Concept
{
field
field
…
}
Concept
query {
object {
field
field
…
}
}
deep fields

(aka. joins)
child properties
Concept
{
field
field
…
}
Query Language Query
query {
checkHealth {
healthy
message
}
}
Concept
query {
object {
field
field
…
}
}
child properties
Query Language Query
query {
checkHealth {
healthy
message
}
}
Example Response
{
“data”: {
“checkHealth”: {
“healthy”: true
“message”: “OK”
}
}
}
child properties
Query Language Query
query {
checkHealth {
healthy
message
}
}
Example Response
{
“data”: {
“checkHealth”: {
“healthy”: true
“message”: “OK”
}
}
}SQL equivalent
SELECT checkHealth.healthy,
checkHealth.message
FROM apps
WHERE id=“myApp””
INNER JOIN checkHealth
ON checkHealth.appId = apps.id
documented
by default
https://us-west-2.api.scaphold.io/graphql/zei-sca-git
documented
by default
https://us-west-2.api.scaphold.io/graphql/zei-sca-git
+ Introspection API
documented
by default
https://us-west-2.api.scaphold.io/graphql/zei-sca-git
+ Introspection API
+ GraphiQL viewer
documented
by default
https://us-west-2.api.scaphold.io/graphql/zei-sca-git
+ Introspection API
+ GraphiQL viewer
- Documentation
can be heavy
documented
by default
https://us-west-2.api.scaphold.io/graphql/zei-sca-git
+ Introspection API
+ GraphiQL viewer
- Documentation
can be heavy
- No http-GET
means no
caching
variants or
selections
Concept
{
field
field
…
}
Concept
query {
object (arg: value) {
field
field
…
}
}
parameters

(aka. query string)
https://myapi.com/object?arg=value
variants or
selections
Concept
{
field
field
…
}
Example Query
query {
getTeam (id: “VGVhbToxNjk=”)
name
createdAt
}
}
Concept
query {
object (arg: value) {
field
field
…
}
}
variants or
selections
Example Query
query {
getTeam (id: “VGVhbToxNjk=”) {
name
createdAt
}
}
Example Response
{
“data”: {
“getTeam”: {
“name”: “oslo”,
“createdAt”:
“2016-12-09T20:27:50.000Z”
}
}
}
https://xkcd.com/327/
prepared
statements
Concept
{
field
field
…
}
Concept
query ($arg: ArgType) {
object (arg: $arg) {
field
field
…
}
}
safe variables 

(aka. injection proof)
{
"query": "...",
"operationName": "...",
"variables": {
"myVariable": “…”,
…
}
}
prepared
statements
Concept
{
field
field
…
}
Example Query
query ($id: ID) {
getTeam (id: $id) {
name
createdAt
}
}
Variables{
“id”: “VGVhbToxNjk=”
}
Concept
query ($arg: ArgType) {
object (arg: $arg) {
field
field
…
}
}
prepared
statements
Example Query
query ($id: ID) {
getTeam (id: $id) {
name
createdAt
}
}
Variables{
“id”: “VGVhbToxNjk=”
}
Example Response
{
“data”: {
“getTeam”: {
“name”: “oslo”,
“createdAt”:
“2016-12-09T20:27:50.000Z”
}
}
}
more than
one item
Concept
{
field
field
…
}
Concept
query {
object (arg: value) {
field
field
…
}
}
result list 

(aka. arrays)
more than
one item
Concept
{
field
field
…
}
Example Query
{
viewer {
allTeams (first: 2) {
edges {
node {
id
name
}
}
}
}
}
Concept
query {
object (arg: value) {
field
field
…
}
}
more than
one item
Example Query
{
viewer {
allTeams (first: 2) {
edges {
node {
id
name
}
}
}
}
}
Example Response
{
"data": {
"viewer": {
"allTeams": {
"edges": [{
"node": {
"id": "VGVhbToxNjk=",
"name": "oslo"
}
}, {
"node": {
"id": "VGVhbToxNjg=",
"name": "london"
}
}] } } } }
namespaces
other than query
Concept
{
field
field
…
}
Concept
namespace myQuery ($arg: ArgType) {
object (arg: $arg) {
field
field
…
}
}
namespaces 

(aka. its all just names)
namespaces
other than query
Concept
{
field
field
…
}
Concept
namespace myQuery ($arg: ArgType) {
object (arg: $arg) {
field
field
…
}
}
Example Query
mutation ($input: UpdateTeamInput) {
updateTeam (input: $input) {
name
id
}
}
Variables{
“id”: “VGVhbToxNjk=”,
“name”: ”OSLO”
}
namespaces
other than query
Example Response
{
“data”: {
“updateTeam”: {
“changedTeam”: {
“id”: “VGVhbToxNjk=”,
“name”: “OSLO”
}
}
}
}
Example Query
mutation ($input: UpdateTeamInput) {
updateTeam (input: $input) {
name
id
}
}
Variables{
“id”: “VGVhbToxNjk=”,
“name”: ”OSLO”
}
Learn more!
http://graphql.org
What do we want?
GraphQL!
When do we want it?
NOW!
GraphQL Database aaS
https://graph.cool
https://scaphold.io
Many Frameworks
… and many more
Big Adopters
Talk about the
future!
Do you use Relay/GraphQL, Relay or something similar to get the data from
your backend?
“Not at this time. We may end up taking some
ideas from GraphQL/Relay and applying them
to our own internal API Infrastructure,
though.”
http://devnacho.com/2016/03/20/how-airbnb-uses-react/
March 2016 Leland Richardson (Airbnb Software Engineer)
the designer
is the enemy
of deadlines
Thanks!

20170624 GraphQL Presentation