SlideShare uma empresa Scribd logo
1 de 117
Introduction to GraphQL
Rohan Deshpande ( @appwiz)
Principal Engineer, Amazon Web Services
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
graphql {
what
why
how
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What is GraphQL
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“GraphQL is a query language for
APIs and a runtime for fulfilling
those queries with your existing
data.”
https://graphql.org
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
GraphQL type system
• Object types
• Interfaces
• Unions
• Enumerations
• Fields
• Lists
• Scalars
• String
• Float
• Int
• Boolean
• ID
• Custom scalars e.g. Date
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
GraphQL operations
Queries
read data
Mutations
write data
Subscriptions
listen for data
query {
search(q: "name") {
title
author
}
}
mutation {
create(title: "book") {
id
}
}
subscription {
onCreate {
id
title
}
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2012
Development started
2015
Open sourced
2016 2017 2018
Evolving specification
Timeline not to scale
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Mobile usage in 2017
•📱 2+ billion smart phones1
•⏱ 1.6+ trillion hours2
2https://www.appannie.com/en/insights/market-data/trillion-dollar-app-economy-only-beginning/
1https://www.statista.com/statistics/330695/number-of-smartphone-users-worldwide/
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
http://
Desktop app
Alexa skill
Mobile app
http://
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
A new philosophy for APIs
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
App data challenges
Data
requirements
vary across
devices and
become harder
when multiple
users share
data
Users want
instant access
to data
Building
scalable data-
driven apps
without
learning
distributed
systems
concepts is
hard
Users want to
continue using
their apps even
with low or no
connectivity
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Why is GraphQL compelling?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Traditional data fetching
Data
 Trivial to set up
 Standard HTTP Calls
❌ Relationships
❌ Lists with reduced information
❌ Query support
❌ Ordering and pagination
❌ Notifications
/posts
/postInfo
/postJustTitle
/postsByAuthor
/postNameStartsX
/postByTag
/commentsOnPost
REST Endpoints
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
http://
Books
Reviews
Inventory
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
type Book {
uuid: ID
title: String
in_stock: Int
price: Float
...
}
getBook(uuid: "123")
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
logo
book title
book author
55
paperback
hardcover
$1015
$1425
only 2 left in stock
only 16 left in stock
✅ Type system
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
only 6 left in stock
get it today
only 3 left in stock
only 2 left in stock
book title
book title
logo
logo
🔎 search(q="book")
return ("123", "456", "789"...)
getBook("123")
return ("123", "book title", "author",
["123a", "123b"])
getInventory("123a")
return ("123", 2)
getReviews("123")
return ("4.4", 55)
getInventory("123b")
return ("123", 16)
getBook("456")
return ("456", "book title", "author",
["456a" ,"456b"])
getInventory("456a")
return ("456", -1)
getReviews("456")
return ("456", "4.3", 54)
getInventory("456b")
return ("456", 11)
only 6 left in stock
get it today
only 3 left in stock
only 2 left in stock
book title
book title
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
logo
logo
underfetching
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
🔎 search(q="book")
results: [
book: {
uuid: "123",
title: "book title",
author: "author",
review: { rating: 4.4, count: 55 },
items: [
{ uuid: "123a", remaining: 2 },
{ uuid: "123b", remaining: 16 }
]},
book: {
uuid: "456",
title: "book title",
author: "author",
review: { rating: 4.3, count: 54 },
items: [
{ uuid: "456a", remaining: -1 },
{ uuid: "456b", remaining: 11 }
]}
]
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
🔎 search(q="book")
results: [
book: {
uuid: "123",
title: "book title",
author: "author",
review: { rating: 4.4, count: 55 },
items: [
{ uuid: "123a", remaining: 2 },
{ uuid: "123b", remaining: 16 }
]},
book: {
uuid: "456",
title: "book title",
author: "author",
review: { rating: 4.3, count: 54 },
items: [
{ uuid: "456a", remaining: -1 },
{ uuid: "456b", remaining: 11 }
]}
]
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
🔎 mobile_search(q="book")
results: [
book: {
uuid: "123",
title: "book title",
author: "author",
review: { rating: 4.4, count: 55 },
uuids: [ "123a", "123b" ]
},
book: {
uuid: "456",
title: "book title",
author: "author",
review: { rating: 4.3, count: 54 },
uuids: [ "456a", "456b" ]
}
]
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
overfetching
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What we want
• Single endpoint to access data
• One request
• Only the fields that are asked
"exactfetching"
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
✅ Type system
✅ GraphQL Queries
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
title of review
lorem ipsum content of the
review. this is a great book!
Helpful Not helpful
6 people found this helpful
Reviews
query {
reviews {
helpful
}
}
POST /reviews/r1/helpful
{ "helpful": 7 }
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
title of review
lorem ipsum content of the
review. this is a great book!
Helpful Not helpful
6 people found this helpful
Reviews
mutation {
markReview(isHelpful: true) {
helpful
}
}
{ "helpful": 7 }
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
✅ Type system
✅ GraphQL Queries
✅ GraphQL Mutations
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Reviews
reviews { count rating }
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Reviews
reviews { count rating }
reviews { count rating }
reviews { count rating }
reviews { count rating }
reviews { count rating }
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Reviews
subscribe {
reviews(uuid:"123") {
count
rating
}
}
persistent connection
{ count: 55, rating: 4.4 }
{ count: 56, rating: 4.5 }
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
✅ Type system
✅ GraphQL Queries
✅ GraphQL Mutations
✅ GraphQL Subscriptions
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Open specification
http://facebook.github.io/graphql/draft/
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Features of GraphQL
• Strongly typed
• Code generation and introspection
• Queries, mutations, subscriptions
• Transport agnostic
• Client-specified shape of response
• Efficient
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Build a GraphQL API
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
Desktop app
Alexa skill
Mobile app
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Alexa skill
uuid qty
A123 10
B456 25
Books
Inventory
"Alexa, is <book> available?"
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
Desktop app
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
Search books
View reviews
Manage inventory
Manage reviews
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
Mobile app
Books
Reviews
Search books
View reviews
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
uuid title author created
A123 101 Dalmatians D. Smith 20150101
type Book {
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
}
uuid title author created
A123 101 Dalmatians D. Smith 20150101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
}
uuid title author created
A123 101 Dalmatians D. Smith 20150101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
uuid: ID
}
uuid title author created
A123 101 Dalmatians D. Smith 20150101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
uuid: ID
}
uuid title author created
A123 101 Dalmatians D. Smith 20150101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
uuid title author created
A123 101 Dalmatians D. Smith 20150101
type Book {
uuid: ID
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
uuid title author created
A123 101 Dalmatians D. Smith 20150101
type Book {
uuid: ID
title: String
author: String
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
http://
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Inventory {
uuid: ID
qty: Int
}
uuid qty
A123 10
B456 25
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
type Book {
uuid: ID
title: String
author: String
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Reading data 📖
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
search(q: "tale") {
uuid
title
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
search(q: "tale") {
uuid
title
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
[
{
"uuid": "B456"
"title": "A Tale of Two Kitties"
}
]
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook(uuid: "A123") {
uuid
title
reviews {
id
txt
stars
}
inventory {
qty
}
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
"uuid": "A123",
"title": "101 Dalmatians",
"reviews": [
id: "r1",
txt: "Spots everywhere!",
stars: 5
],
"inventory" {
"qty": 10
}
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Writing data 📝
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyMutation {
addStar(num: Int): Review
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
addStar(num: 1) {
stars
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
addStar(num: 1) {
stars
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
{
stars: 55
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Listening for data 🎧
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MySubscription {
onReview(uuid: ID): Review
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
onReview(uuid: "A123") {
uuid
id
stars
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
type MySubscription {
onReview(uuid: ID): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
onReview(uuid: "A123") {
uuid
id
stars
}
<listen>
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
type MySubscription {
onReview(uuid: ID): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
onReview(uuid: "A123") {
uuid
id
stars
}
{
"uuid": "A123",
"id": "r576",
"stars": 54
}
{
"uuid": "A123",
"id": "r9845",
"stars": 55
}
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
type MySubscription {
onReview(uuid: ID): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
type MySubscription {
onReview(uuid: ID): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type Review {
id: ID
uuid: String
stars: Int
txt: String
}
type Inventory {
uuid: ID
qty: Int
}
schema {
query: MyQuery
mutation: MyMutation
subscription: MySubscription
}
type MyQuery {
search(q: String): [Book]
getBook(uuid: ID): Book
}
type MyMutation {
addStar(num: Int): Review
}
type MySubscription {
onReview(uuid: ID): Review
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
Desktop app
Alexa skill
Mobile app
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
schema
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
How are queries executed?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyQuery {
getBook(uuid: ID): Book
}
Books
?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyQuery {
getBook(uuid: ID): Book
}
Books
resolver
f(x)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyQuery {
getBook(uuid: ID): Book
}
Books
var client = new DocumentClient();
var params = {
TableName: "Books"
};
client.getItem(params, onItem);
function onItem(err, data) {
if (data) {
//...
}
}
resolver
f(x)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
Books
Reviews
Inventory
type MyQuery {
getBook(uuid: ID): Book
}
GetBookResolver
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyQuery {
getBook(uuid: ID): Book
}
http://
Books
Reviews
Inventory
GetBookResolver
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
type MyQuery {
getBook(uuid: ID): Book
}
http://
Books
Reviews
Inventory
GetBookResolver
GetReviewsResolver
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
type MyQuery {
getBook(uuid: ID): Book
}
http://
Books
Reviews
Inventory
GetBookResolver
GetReviewsResolver
GetInventoryResolver
type Book {
uuid: ID
title: String
author: String
reviews: [Review]
inventory: Inventory
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook(uuid: "A123") {
uuid
title
reviews {
id
txt
stars
}
inventory {
qty
}
}
getBook
uuid title inventory
qty
reviews
id txt stars
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook
uuid title inventory
qty
reviews
id txt stars
GetBookResolver
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook
uuid title inventory
qty
reviews
id txt stars
GetBookResolver
GetReviewsResolver
GetInventoryResolver
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook
uuid title inventory
qty
reviews
id txt stars
GetBookResolver
GetReviewsResolver
GetInventoryResolver
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook(uuid: "A123") {
uuid
title
inventory
reviews
}
getBook
uuid title
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
http://
[
{
id: "r1", stars: 5, uuid: "A123",
txt: "Spots everywhere!"
},
{
id: "r2", stars: 4, uuid: "B456",
txt: "Purr-fect book!"
},
]
Desktop app
Alexa skill
Mobile app
uuid qty
A123 10
B456 25
Books
Reviews
Inventory
schema
f(x)
f(x)
f(x)
f(x)
uuid title author created
A123 101 Dalmatians D. Smith 20050101
B456 A Tale of Two Kitties S. Kelly 20060101
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
How do I
Run GraphQL in production
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
GraphQL sounds legit!
I want to run my own GraphQL server!!
endpoint auth
Security
f(x)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
resolver auth
Security
f(x)
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
getBook(uuid: "A123") {
uuid
title
qty
}
Security
{
uuid: "A123"
title: "101 Dalmatians"
qty: null
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Nested queries
query {
friends(id: "123") {
id
name
friends {
id
name
friends {
id
name
friends {
...
}
}
}
}
}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Query Execution
• 👋 Bounding
•✋ Throttling
• 👊 Batching
getBook(uuid: "A123") {
uuid
title
reviews {
id
txt
stars
}
price {
currency
}
inventory {
qty
}
}
http://
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
f(x)
Scaling subscriptions
…
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Focus on Apps
Not Infrastructure
AWS AppSync – managed GraphQL
http://
https://aws.amazon.com/appsync
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS AppSync
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Managed Serverless
GraphQL service
Connect to data sources
in your account
Add data sync, real-time
and offline capabilities for
any data source or API
GraphQL façade for
any AWS service
Conflict detection
and resolution in
the cloud
Enterprise security
features:
IAM, Cognito, OIDC,
API keys
Mix/Match Data Sources on GraphQL Types
Amazon DynamoDB
type Query {
listPosts: [Post]
searchPosts: [Post]
}
type Mutation {
addPost: Post
}
type Post {
id: ID!
content: String
description: String
ups: Int
downs: Int
}
Amazon Elasticsearch
listPosts
searchPosts
addPost
AWS AppSync benefits
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Clients receive the data
they ask for. Nothing
more, nothing less
Get many resources
from many data sources
with a single request
Self-documenting APIs
with Introspection
React Native, Android,
iOS, and Web (JS) using
the Apollo GraphQL
client
Data persistence across
application restarts
Write-through
mutations with
Optimistic UI
How does AppSync work?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon
Elasticsearch
Amazon
DynamoDB
AWS Lambda
Connect Data
Sources
AppSync Updates Data
in Real Time and Manages
Data when Offline
__________
______________
___________
_________
___________
____________
__________ NEW
Create, Import or Upload
GraphQL Schema
Data flow and security
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Request Template Response Template
Data Sources
1 2 3 4 5
GraphQL data flow in AWS AppSync
Fine-grained access control
Simple
Only users in certain groups can perform actions
#if($hasPermission || $ctx.result.public == 'yes')
$utils.toJson($ctx.result)
#else
$utils.unauthorized()
#end
Only users in certain groups can perform actions
#if($ctx.result["Owner"] == $ctx.identity.username)
$utils.toJson($context.result);
#else
$utils.unauthorized()
#end
Advanced
Only users in certain groups can perform actions
#foreach($group in $ctx.identity.claims.get("cognito:groups"))
#if($group == "Admin")
#set($inCognitoGroup = true)
#end
#end
#if($inCognitoGroup)
{
…write/read from datasource
}
#else
$utils.unauthorized()
#end
Access control checks
Real-time data
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon Elasticsearch
Amazon DynamoDB
Browser
Mobile
device WebSocket
servers
Web servers
PubSub
servers
Subscription
/search
/taps
/taps/:id
/m_search
AWS Lambda
Third-party service
…
Real-time app before AppSync
/graphql
AWS AppSync
Subscription Amazon Elasticsearch
Amazon DynamoDB
AWS Lambda
Third-party service
Real-time app with AppSync
• GraphQL subscriptions
• Event stream of mutation results
• Data synchronisation with MQTT + WebSockets
• Client managed WebSocket connection
• Automatic catch-up snapshots
Real-time updates
Offline data and conflicts
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Jane
Version : 2 Updated Document
Jane
Version : 2 Updated Document
Version : 3 Updated Document
Version : 1 New Document
Time
John
John
Jane goes offline
Jane comes back online
Version : 4 Updated Document
John
Jane
Data conflicts
• Conflict detection with optimistic version check
• Conflict resolution strategies:
• Client wins
• Server wins
• Silent reject
• Custom logic in AWS Lambda
• Client callback for conflict resolution is available
"condition" : {
"expression" : "someExpression"
"conditionalCheckFailedHandler" : {
"strategy" : "Custom",
"lambdaArn" : "arn:..."
}
}
Handle data conflicts in the cloud
• Offline is a write-through "Store"
• Persistent storage mediums back the Apollo
normalised cache
• Local Storage for web
• AsyncStorage for React Native
• SQLite on native platforms
• Database can be preloaded
• Offline client can be configured
• WiFi only
• WiFi and cellular
Offline capabilities – AppSync offline storage
AWS Amplify
CLI
Amazon DynamoDB
type Post
@model
@auth(rules:
[{allow: owner}])
@searchable{
id: ID!
content: String
description: String
ups: Int
downs: Int
}
Amazon Elasticsearch
searchPosts
Amazon
Cognito
User Pools
mutations
queries
createPost
readPost
updatePost
deletePost
AWS AppSync
GraphQL transformer
Let's build a GraphQL API with AWS AppSync
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Use GraphQL Use REST
When data drives UI
• Structured Data
• Complex Data
• Query-driven
• Real-time/Offline
Client-driven development
Pros: Contract-driven, Introspection,
Relations, Types
Conns: Not as ubiquitous as REST
When you leverage HTTP
• Caching
• Content Types
• Hypermedia (HATEOAS)
For Resources (e.g. Kinesis)
Pros: HTTP Client, Golden Standard,
HTTP/2 Performance gains
Conns: Over fetching/Under fetching
GraphQL or REST?
Bottom Line
It depends on the use case and, most importantly…
Good API Design!
GraphQL or REST?
Recap
• What is GraphQL
• Why was GraphQL created
• How to build a GraphQL API
• How to operate a GraphQL API in production
• We built a GraphQL API
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you
https://aws.amazon.com/appsync
follow me on twitter
@appwiz
🙏😀👏
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Mais conteúdo relacionado

Mais procurados

REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQLSquareboat
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQLTomasz Bak
 
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...luisw19
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaEdureka!
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQLAmazon Web Services
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsSashko Stubailo
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL Josh Price
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Hafiz Ismail
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & DevelopmentAshok Pundit
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practicesAnkita Mahajan
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITnamespaceit
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 

Mais procurados (20)

REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
 
Graphql
GraphqlGraphql
Graphql
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQL
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
 
Web api
Web apiWeb api
Web api
 
GraphQL
GraphQLGraphQL
GraphQL
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 

Semelhante a Introduction to GraphQL

Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFAmazon Web Services
 
Graph and Amazon Neptune - Bill Baldwin
Graph and Amazon Neptune - Bill BaldwinGraph and Amazon Neptune - Bill Baldwin
Graph and Amazon Neptune - Bill BaldwinAmazon Web Services
 
Graph & Amazon Neptune: Database Week SF
Graph & Amazon Neptune: Database Week SFGraph & Amazon Neptune: Database Week SF
Graph & Amazon Neptune: Database Week SFAmazon Web Services
 
Neptune, the Graph Database | AWS Floor28
Neptune, the Graph Database | AWS Floor28Neptune, the Graph Database | AWS Floor28
Neptune, the Graph Database | AWS Floor28Amazon Web Services
 
Graph & Neptune: Database Week San Francisco
Graph & Neptune: Database Week San FranciscoGraph & Neptune: Database Week San Francisco
Graph & Neptune: Database Week San FranciscoAmazon Web Services
 
Deep Dive on Amazon Neptune - AWS Online Tech Talks
Deep Dive on Amazon Neptune - AWS Online Tech TalksDeep Dive on Amazon Neptune - AWS Online Tech Talks
Deep Dive on Amazon Neptune - AWS Online Tech TalksAmazon Web Services
 
Understanding Graph Databases: AWS Developer Workshop at Web Summit
Understanding Graph Databases: AWS Developer Workshop at Web SummitUnderstanding Graph Databases: AWS Developer Workshop at Web Summit
Understanding Graph Databases: AWS Developer Workshop at Web SummitAmazon Web Services
 
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...Codemotion
 
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Amazon Web Services
 
Building Real-Time Serverless Backends with GraphQL | AWS Floor28
Building Real-Time Serverless Backends with GraphQL | AWS Floor28Building Real-Time Serverless Backends with GraphQL | AWS Floor28
Building Real-Time Serverless Backends with GraphQL | AWS Floor28Amazon Web Services
 
Build a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSyncBuild a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSyncAmazon Web Services
 
Building Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQLBuilding Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQLAmazon Web Services
 
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...Codemotion
 
Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018
Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018
Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018Amazon Web Services
 
Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...
Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...
Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...Amazon Web Services
 
Building Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQLBuilding Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQLAmazon Web Services
 

Semelhante a Introduction to GraphQL (20)

Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SF
 
Graph and Amazon Neptune - Bill Baldwin
Graph and Amazon Neptune - Bill BaldwinGraph and Amazon Neptune - Bill Baldwin
Graph and Amazon Neptune - Bill Baldwin
 
Graph & Amazon Neptune: Database Week SF
Graph & Amazon Neptune: Database Week SFGraph & Amazon Neptune: Database Week SF
Graph & Amazon Neptune: Database Week SF
 
Graph & Neptune
Graph & NeptuneGraph & Neptune
Graph & Neptune
 
Graph and Amazon Neptune
Graph and Amazon NeptuneGraph and Amazon Neptune
Graph and Amazon Neptune
 
Graph and Amazon Neptune
Graph and Amazon NeptuneGraph and Amazon Neptune
Graph and Amazon Neptune
 
Neptune, the Graph Database | AWS Floor28
Neptune, the Graph Database | AWS Floor28Neptune, the Graph Database | AWS Floor28
Neptune, the Graph Database | AWS Floor28
 
Graph & Neptune: Database Week San Francisco
Graph & Neptune: Database Week San FranciscoGraph & Neptune: Database Week San Francisco
Graph & Neptune: Database Week San Francisco
 
Graph and Neptune
Graph and NeptuneGraph and Neptune
Graph and Neptune
 
Deep Dive on Amazon Neptune - AWS Online Tech Talks
Deep Dive on Amazon Neptune - AWS Online Tech TalksDeep Dive on Amazon Neptune - AWS Online Tech Talks
Deep Dive on Amazon Neptune - AWS Online Tech Talks
 
Understanding Graph Databases: AWS Developer Workshop at Web Summit
Understanding Graph Databases: AWS Developer Workshop at Web SummitUnderstanding Graph Databases: AWS Developer Workshop at Web Summit
Understanding Graph Databases: AWS Developer Workshop at Web Summit
 
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
 
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
 
Building Real-Time Serverless Backends with GraphQL | AWS Floor28
Building Real-Time Serverless Backends with GraphQL | AWS Floor28Building Real-Time Serverless Backends with GraphQL | AWS Floor28
Building Real-Time Serverless Backends with GraphQL | AWS Floor28
 
Build a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSyncBuild a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSync
 
Building Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQLBuilding Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQL
 
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
Danilo Poccia - Real-Time Serverless Backends with GraphQL - Codemotion Berli...
 
Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018
Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018
Connecting the Unconnected using GraphDB - Tel Aviv Summit 2018
 
Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...
Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...
Build an Interactive Alexa Voice Experience for Multiple Screens (ALX314-R2) ...
 
Building Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQLBuilding Real-Time Serverless Backends with GraphQL
Building Real-Time Serverless Backends with GraphQL
 

Mais de Amazon Web Services

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Amazon Web Services
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Amazon Web Services
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateAmazon Web Services
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSAmazon Web Services
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Amazon Web Services
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Amazon Web Services
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...Amazon Web Services
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsAmazon Web Services
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareAmazon Web Services
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSAmazon Web Services
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAmazon Web Services
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareAmazon Web Services
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWSAmazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckAmazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...Amazon Web Services
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceAmazon Web Services
 

Mais de Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Introduction to GraphQL

  • 1. Introduction to GraphQL Rohan Deshpande ( @appwiz) Principal Engineer, Amazon Web Services © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 2. Agenda graphql { what why how } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 3. What is GraphQL © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 4. “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.” https://graphql.org © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 5. GraphQL type system • Object types • Interfaces • Unions • Enumerations • Fields • Lists • Scalars • String • Float • Int • Boolean • ID • Custom scalars e.g. Date © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 6. GraphQL operations Queries read data Mutations write data Subscriptions listen for data query { search(q: "name") { title author } } mutation { create(title: "book") { id } } subscription { onCreate { id title } } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 7. 2012 Development started 2015 Open sourced 2016 2017 2018 Evolving specification Timeline not to scale © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 8. Mobile usage in 2017 •📱 2+ billion smart phones1 •⏱ 1.6+ trillion hours2 2https://www.appannie.com/en/insights/market-data/trillion-dollar-app-economy-only-beginning/ 1https://www.statista.com/statistics/330695/number-of-smartphone-users-worldwide/ © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 9. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock
  • 10. http:// Desktop app Alexa skill Mobile app http:// © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock
  • 11. A new philosophy for APIs © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 12. App data challenges Data requirements vary across devices and become harder when multiple users share data Users want instant access to data Building scalable data- driven apps without learning distributed systems concepts is hard Users want to continue using their apps even with low or no connectivity © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 13. Why is GraphQL compelling? © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 14. Traditional data fetching Data  Trivial to set up  Standard HTTP Calls ❌ Relationships ❌ Lists with reduced information ❌ Query support ❌ Ordering and pagination ❌ Notifications /posts /postInfo /postJustTitle /postsByAuthor /postNameStartsX /postByTag /commentsOnPost REST Endpoints © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 15. logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock http:// Books Reviews Inventory © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 16. http:// type Book { uuid: ID title: String in_stock: Int price: Float ... } getBook(uuid: "123") © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. logo book title book author 55 paperback hardcover $1015 $1425 only 2 left in stock only 16 left in stock
  • 17. ✅ Type system © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 18. only 6 left in stock get it today only 3 left in stock only 2 left in stock book title book title logo logo 🔎 search(q="book") return ("123", "456", "789"...) getBook("123") return ("123", "book title", "author", ["123a", "123b"]) getInventory("123a") return ("123", 2) getReviews("123") return ("4.4", 55) getInventory("123b") return ("123", 16) getBook("456") return ("456", "book title", "author", ["456a" ,"456b"]) getInventory("456a") return ("456", -1) getReviews("456") return ("456", "4.3", 54) getInventory("456b") return ("456", 11) only 6 left in stock get it today only 3 left in stock only 2 left in stock book title book title © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. logo logo
  • 19. underfetching © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 20. 🔎 search(q="book") results: [ book: { uuid: "123", title: "book title", author: "author", review: { rating: 4.4, count: 55 }, items: [ { uuid: "123a", remaining: 2 }, { uuid: "123b", remaining: 16 } ]}, book: { uuid: "456", title: "book title", author: "author", review: { rating: 4.3, count: 54 }, items: [ { uuid: "456a", remaining: -1 }, { uuid: "456b", remaining: 11 } ]} ] © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 21. 🔎 search(q="book") results: [ book: { uuid: "123", title: "book title", author: "author", review: { rating: 4.4, count: 55 }, items: [ { uuid: "123a", remaining: 2 }, { uuid: "123b", remaining: 16 } ]}, book: { uuid: "456", title: "book title", author: "author", review: { rating: 4.3, count: 54 }, items: [ { uuid: "456a", remaining: -1 }, { uuid: "456b", remaining: 11 } ]} ] © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 22. 🔎 mobile_search(q="book") results: [ book: { uuid: "123", title: "book title", author: "author", review: { rating: 4.4, count: 55 }, uuids: [ "123a", "123b" ] }, book: { uuid: "456", title: "book title", author: "author", review: { rating: 4.3, count: 54 }, uuids: [ "456a", "456b" ] } ] © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 23. overfetching © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 24. What we want • Single endpoint to access data • One request • Only the fields that are asked "exactfetching" © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 25. ✅ Type system ✅ GraphQL Queries © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 26. title of review lorem ipsum content of the review. this is a great book! Helpful Not helpful 6 people found this helpful Reviews query { reviews { helpful } } POST /reviews/r1/helpful { "helpful": 7 } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 27. title of review lorem ipsum content of the review. this is a great book! Helpful Not helpful 6 people found this helpful Reviews mutation { markReview(isHelpful: true) { helpful } } { "helpful": 7 } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 28. ✅ Type system ✅ GraphQL Queries ✅ GraphQL Mutations © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 29. Reviews reviews { count rating } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 30. Reviews reviews { count rating } reviews { count rating } reviews { count rating } reviews { count rating } reviews { count rating } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 31. Reviews subscribe { reviews(uuid:"123") { count rating } } persistent connection { count: 55, rating: 4.4 } { count: 56, rating: 4.5 } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 32. ✅ Type system ✅ GraphQL Queries ✅ GraphQL Mutations ✅ GraphQL Subscriptions © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 33. Open specification http://facebook.github.io/graphql/draft/ © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 34. Features of GraphQL • Strongly typed • Code generation and introspection • Queries, mutations, subscriptions • Transport agnostic • Client-specified shape of response • Efficient © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 35. Build a GraphQL API © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 36. uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] Desktop app Alexa skill Mobile app uuid qty A123 10 B456 25 Books Reviews Inventory © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 37. Alexa skill uuid qty A123 10 B456 25 Books Inventory "Alexa, is <book> available?" uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 38. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] Desktop app uuid qty A123 10 B456 25 Books Reviews Inventory Search books View reviews Manage inventory Manage reviews uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 39. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] Mobile app Books Reviews Search books View reviews uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 40. uuid title author created A123 101 Dalmatians D. Smith 20150101 type Book { } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 41. type Book { } uuid title author created A123 101 Dalmatians D. Smith 20150101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 42. type Book { } uuid title author created A123 101 Dalmatians D. Smith 20150101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 43. type Book { uuid: ID } uuid title author created A123 101 Dalmatians D. Smith 20150101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 44. type Book { uuid: ID } uuid title author created A123 101 Dalmatians D. Smith 20150101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 45. uuid title author created A123 101 Dalmatians D. Smith 20150101 type Book { uuid: ID } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 46. uuid title author created A123 101 Dalmatians D. Smith 20150101 type Book { uuid: ID title: String author: String } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 47. type Review { id: ID uuid: String stars: Int txt: String } [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] http:// © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 48. type Inventory { uuid: ID qty: Int } uuid qty A123 10 B456 25 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 49. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] uuid qty A123 10 B456 25 Books Reviews Inventory type Book { uuid: ID title: String author: String } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 50. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] uuid qty A123 10 B456 25 Books Reviews Inventory type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 type Book { uuid: ID title: String author: String reviews: [Review] } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 51. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] uuid qty A123 10 B456 25 Books Reviews Inventory type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 52. Reading data 📖 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 53. type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 54. search(q: "tale") { uuid title } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 55. search(q: "tale") { uuid title } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } [ { "uuid": "B456" "title": "A Tale of Two Kitties" } ] © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 56. getBook(uuid: "A123") { uuid title reviews { id txt stars } inventory { qty } } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 57. { "uuid": "A123", "title": "101 Dalmatians", "reviews": [ id: "r1", txt: "Spots everywhere!", stars: 5 ], "inventory" { "qty": 10 } } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 58. Writing data 📝 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 59. type MyMutation { addStar(num: Int): Review } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 60. addStar(num: 1) { stars } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 61. addStar(num: 1) { stars } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } { stars: 55 } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 62. Listening for data 🎧 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 63. type MySubscription { onReview(uuid: ID): Review } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 64. onReview(uuid: "A123") { uuid id stars } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } type MySubscription { onReview(uuid: ID): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 65. onReview(uuid: "A123") { uuid id stars } <listen> type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } type MySubscription { onReview(uuid: ID): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 66. onReview(uuid: "A123") { uuid id stars } { "uuid": "A123", "id": "r576", "stars": 54 } { "uuid": "A123", "id": "r9845", "stars": 55 } type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } type MySubscription { onReview(uuid: ID): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 67. type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } type MySubscription { onReview(uuid: ID): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 68. type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type Review { id: ID uuid: String stars: Int txt: String } type Inventory { uuid: ID qty: Int } schema { query: MyQuery mutation: MyMutation subscription: MySubscription } type MyQuery { search(q: String): [Book] getBook(uuid: ID): Book } type MyMutation { addStar(num: Int): Review } type MySubscription { onReview(uuid: ID): Review } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 69. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] Desktop app Alexa skill Mobile app uuid qty A123 10 B456 25 Books Reviews Inventory schema uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 70. How are queries executed? © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 71. type MyQuery { getBook(uuid: ID): Book } Books ? © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 72. type MyQuery { getBook(uuid: ID): Book } Books resolver f(x) © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 73. type MyQuery { getBook(uuid: ID): Book } Books var client = new DocumentClient(); var params = { TableName: "Books" }; client.getItem(params, onItem); function onItem(err, data) { if (data) { //... } } resolver f(x) © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 74. http:// Books Reviews Inventory type MyQuery { getBook(uuid: ID): Book } GetBookResolver © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 75. type MyQuery { getBook(uuid: ID): Book } http:// Books Reviews Inventory GetBookResolver type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 76. type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } type MyQuery { getBook(uuid: ID): Book } http:// Books Reviews Inventory GetBookResolver GetReviewsResolver © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 77. type MyQuery { getBook(uuid: ID): Book } http:// Books Reviews Inventory GetBookResolver GetReviewsResolver GetInventoryResolver type Book { uuid: ID title: String author: String reviews: [Review] inventory: Inventory } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 78. getBook(uuid: "A123") { uuid title reviews { id txt stars } inventory { qty } } getBook uuid title inventory qty reviews id txt stars © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 79. getBook uuid title inventory qty reviews id txt stars GetBookResolver © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 80. getBook uuid title inventory qty reviews id txt stars GetBookResolver GetReviewsResolver GetInventoryResolver © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 81. getBook uuid title inventory qty reviews id txt stars GetBookResolver GetReviewsResolver GetInventoryResolver © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 82. getBook(uuid: "A123") { uuid title inventory reviews } getBook uuid title © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 83. http:// [ { id: "r1", stars: 5, uuid: "A123", txt: "Spots everywhere!" }, { id: "r2", stars: 4, uuid: "B456", txt: "Purr-fect book!" }, ] Desktop app Alexa skill Mobile app uuid qty A123 10 B456 25 Books Reviews Inventory schema f(x) f(x) f(x) f(x) uuid title author created A123 101 Dalmatians D. Smith 20050101 B456 A Tale of Two Kitties S. Kelly 20060101 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 84. How do I Run GraphQL in production © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 85. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. GraphQL sounds legit! I want to run my own GraphQL server!!
  • 86. endpoint auth Security f(x) © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 87. resolver auth Security f(x) © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 88. getBook(uuid: "A123") { uuid title qty } Security { uuid: "A123" title: "101 Dalmatians" qty: null } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 89. Nested queries query { friends(id: "123") { id name friends { id name friends { id name friends { ... } } } } } © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 90. Query Execution • 👋 Bounding •✋ Throttling • 👊 Batching getBook(uuid: "A123") { uuid title reviews { id txt stars } price { currency } inventory { qty } } http:// © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 91. f(x) Scaling subscriptions … © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 92. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Focus on Apps Not Infrastructure
  • 93. AWS AppSync – managed GraphQL http:// https://aws.amazon.com/appsync © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 94. AWS AppSync © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Managed Serverless GraphQL service Connect to data sources in your account Add data sync, real-time and offline capabilities for any data source or API GraphQL façade for any AWS service Conflict detection and resolution in the cloud Enterprise security features: IAM, Cognito, OIDC, API keys
  • 95. Mix/Match Data Sources on GraphQL Types Amazon DynamoDB type Query { listPosts: [Post] searchPosts: [Post] } type Mutation { addPost: Post } type Post { id: ID! content: String description: String ups: Int downs: Int } Amazon Elasticsearch listPosts searchPosts addPost
  • 96. AWS AppSync benefits © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Clients receive the data they ask for. Nothing more, nothing less Get many resources from many data sources with a single request Self-documenting APIs with Introspection React Native, Android, iOS, and Web (JS) using the Apollo GraphQL client Data persistence across application restarts Write-through mutations with Optimistic UI
  • 97. How does AppSync work? © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Elasticsearch Amazon DynamoDB AWS Lambda Connect Data Sources AppSync Updates Data in Real Time and Manages Data when Offline __________ ______________ ___________ _________ ___________ ____________ __________ NEW Create, Import or Upload GraphQL Schema
  • 98. Data flow and security © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 99. Request Template Response Template Data Sources 1 2 3 4 5 GraphQL data flow in AWS AppSync
  • 101. Simple Only users in certain groups can perform actions #if($hasPermission || $ctx.result.public == 'yes') $utils.toJson($ctx.result) #else $utils.unauthorized() #end Only users in certain groups can perform actions #if($ctx.result["Owner"] == $ctx.identity.username) $utils.toJson($context.result); #else $utils.unauthorized() #end Advanced Only users in certain groups can perform actions #foreach($group in $ctx.identity.claims.get("cognito:groups")) #if($group == "Admin") #set($inCognitoGroup = true) #end #end #if($inCognitoGroup) { …write/read from datasource } #else $utils.unauthorized() #end Access control checks
  • 102. Real-time data © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 103. Amazon Elasticsearch Amazon DynamoDB Browser Mobile device WebSocket servers Web servers PubSub servers Subscription /search /taps /taps/:id /m_search AWS Lambda Third-party service … Real-time app before AppSync
  • 104. /graphql AWS AppSync Subscription Amazon Elasticsearch Amazon DynamoDB AWS Lambda Third-party service Real-time app with AppSync
  • 105. • GraphQL subscriptions • Event stream of mutation results • Data synchronisation with MQTT + WebSockets • Client managed WebSocket connection • Automatic catch-up snapshots Real-time updates
  • 106. Offline data and conflicts © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 107. Jane Version : 2 Updated Document Jane Version : 2 Updated Document Version : 3 Updated Document Version : 1 New Document Time John John Jane goes offline Jane comes back online Version : 4 Updated Document John Jane Data conflicts
  • 108. • Conflict detection with optimistic version check • Conflict resolution strategies: • Client wins • Server wins • Silent reject • Custom logic in AWS Lambda • Client callback for conflict resolution is available "condition" : { "expression" : "someExpression" "conditionalCheckFailedHandler" : { "strategy" : "Custom", "lambdaArn" : "arn:..." } } Handle data conflicts in the cloud
  • 109. • Offline is a write-through "Store" • Persistent storage mediums back the Apollo normalised cache • Local Storage for web • AsyncStorage for React Native • SQLite on native platforms • Database can be preloaded • Offline client can be configured • WiFi only • WiFi and cellular Offline capabilities – AppSync offline storage
  • 111. Amazon DynamoDB type Post @model @auth(rules: [{allow: owner}]) @searchable{ id: ID! content: String description: String ups: Int downs: Int } Amazon Elasticsearch searchPosts Amazon Cognito User Pools mutations queries createPost readPost updatePost deletePost AWS AppSync GraphQL transformer
  • 112. Let's build a GraphQL API with AWS AppSync © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 113.
  • 114. Use GraphQL Use REST When data drives UI • Structured Data • Complex Data • Query-driven • Real-time/Offline Client-driven development Pros: Contract-driven, Introspection, Relations, Types Conns: Not as ubiquitous as REST When you leverage HTTP • Caching • Content Types • Hypermedia (HATEOAS) For Resources (e.g. Kinesis) Pros: HTTP Client, Golden Standard, HTTP/2 Performance gains Conns: Over fetching/Under fetching GraphQL or REST?
  • 115. Bottom Line It depends on the use case and, most importantly… Good API Design! GraphQL or REST?
  • 116. Recap • What is GraphQL • Why was GraphQL created • How to build a GraphQL API • How to operate a GraphQL API in production • We built a GraphQL API © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 117. Thank you https://aws.amazon.com/appsync follow me on twitter @appwiz 🙏😀👏 © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.