SlideShare a Scribd company logo
1 of 59
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
03.04.2019
O S L O
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
0 to 100 with GraphQL:
Rapid Development Techniques for APIs
{
"name": "Sébastien Stormacq",
"role": ”Technical Evangelist",
"company": "Amazon Web Services”,
"twitter": ”@sebsto”,
”github": ”sebsto”
}
B A R 4
O S L O
03.04.2019
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
This talk is for
developers
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
This talk is for
developers
< frontend | backend >
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How to you prototype API ?
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Congratulations !
You’ve just been hired.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Today’s mobile experience is lacking
Mobile website, no native apps
Slow to book, low conversion rates
Backend built for high-speed desktops
!
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Your job is to define tomorrow’s experience
Digital agencies hired for design
First prototype in 4 weeks
Must use real data, no mockup
!
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Our Goal
Enable backend services for prototype
Allow design to evolve
Keeping up with day-to-day job
!
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
{
"_id": 3,
"name": "ElastiLodge South Zanetown",
"image": "https://placehold.it/300x300.png",
"description": "Sint nostrum vel quibusdam quia
reprehenderit cum exercitationem quia ea.",
"location": "South Zanetown",
"manager": {
"name": "Florentino Jacobi",
"email": "florentino.jacobi@elastilodge.com"
},
"timeZone": "US/Central",
"phoneNumber": "802-918-3262",
"category": 5,
Legacy REST API
"address": {
"street": "410 Simonis Forest",
"zip": "07545-2308",
"city": "South Zanetown",
"country": "Virgin Islands, British"
},
"deskHours": "24 hours",
"amenities": [ ... ],
"restaurants": [ ... ]
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What are the challenges of REST API
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
/posts /comments /authors
REST API
Chatty & Over fetching
{
"posts" : [
{
"id" : 1,
"content" : "the quick brown fox jumps over the…",
"author" : "/authors/123",
"created" : 1550486509,
"comments" : "/posts/1/comments",
...
},
{
"id" : 2,
"content" : "the quick brown fox jumps over…",
"author" : "/authors/123"
"created" : 1550486509,
"comments" : "/posts/2/comments",
...
}
]
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Introducing GraphQL
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL is a query language for
your API, and a server-side
runtime for executing queries by
using a type system you define
for your data. https://graphql.org
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Why GraphQL ?
posts comments authors
GraphQL API
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How does GraphQL work?
type Query {
getTodos: [Todo]
}
type Todo {
id: ID!
name: String
description: String
priority: Int
duedate: String
}
Model data with
application schema
query {
getTodos {
id
name
priority
}
}
Client requests
what it needs
{
"id": "1",
"name": "Get Milk",
"priority": "1"
},
{
"id": "2",
"name": "Go to gym",
"priority": "5"
},…
Only that data is
returned
© 2019, 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: “harry potter”) {
title
}
}
mutation {
create(title: “new book”) {
id
}
}
subscription {
onCreate {
id
title
}
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Is REST dead then?
When data drives UI
Structured data
Query-driven
Client-driven development
Use GraphQL
When you leverage HTTP
Caching, Content types
Hypermedia (HATEOAS)
For resources (eg Amazon S3)
Use REST
Pick the appropriate protocol for your use case
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How to deploy GraphQL API ?
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS App Sync
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 facade for any
AWS service
Conflict detection and
resolution in the cloud
Enterprise security features:
IAM, Amazon Cognito, OIDC,
API keys
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AppSync Data Sources
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AppSync Resolvers
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Hello AWS AppSync
KEEP
CALM
and
WATCH
the
DEMO
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Prototype : Phase #1
Hotel Detail
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Hotel Detail: Design
What data is required?
Can we use existing data sources?
How can we enable via AppSync?
Challenges? Missing data?
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mapping to Legacy API {
"_id": 3,
"image": "https://placehold.it/300x300.png",
"name": "EL Resort & Spa",
"description": "...",
"location": "Fiji",
"manager": {
"name": "Florentino Jacobi",
"email": "florentino.jacobi@elastilodge.com"
},
"timeZone": "US/Central",
"address": {
"street": "123 Main St",
”postalcode": "07545",
"city": "Momi Bay",
"country": "Fiji"
},
"phoneNumber": "1-888-123-4567",
"category": 5,
"deskHours": "24 hours",
"amenities": [ ... ],
"restaurants": [ ... ]
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mapping to Legacy API {
"_id": 3,
"image": "https://placehold.it/300x300.png",
"name": "EL Resort & Spa",
"description": "...",
"location": "Fiji",
"manager": {
"name": "Florentino Jacobi",
"email": "florentino.jacobi@elastilodge.com"
},
"timeZone": "US/Central",
"address": {
"street": "123 Main St",
”postalcode": "07545",
"city": "Momi Bay",
"country": "Fiji"
},
"phoneNumber": "1-888-123-4567",
"category": 5,
"deskHours": "24 hours",
"amenities": [ ... ],
"restaurants": [ ... ]
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Hotel Detail: GraphQL Schema
type Hotel {
hotelId: ID!
name: String!
image: String
location: String!
phoneNumber: AWSPhone!
address: Address!
...
}
type Query {
listHotels(offset: String, limit: Int)
getHotel(hotelId: ID!)
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Hotel Detail: Resolvers
## Resolver: Request Mapping ##
{
"version": "2018-05-29",
"method": "GET",
"resourcePath": "/hotels/${ctx.args.hotelId}",
"params": {
"headers": {
"Content-Type": "application/json"
}
},
}
## Resolver: Response Mapping ##
#if($ctx.result.statusCode == 200)
## If response is 200, return the body.
## Could also filter result...
$ctx.result.body
#else
## If not 200, append response to error
$utils.appendError($ctx.result.body)
#end
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Hotel Detail: Result
query {
getHotel(hotelId: 3) {
name
location
image
phoneNumber
address {
street
city
}
amenities
}
}
{
"name": "ElastiLodge North Rodgerstad",
"location": "North Rodgerstad",
"image": "/300x300.png",
"phoneNumber": "(214) 210-4674",
"address": {
"street": "123 Main St",
"city": "North Rodgerstad"
},
"amenities": [ ... ]
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mobile Code – Initialize App Sync Client
do {
// create app sync configuration (cache, service config etc)
let config = …
// client initialization
let appSyncClient = try AWSAppSyncClient(appSyncConfig: config)
} catch {
fatalError("Error initializing appsync client. (error)")
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mobile Code – Run a Query
// call a GraphQL Query
appSyncClient?.fetch(query: GetHotelQuery(hotelId: hotelId),
cachePolicy: .fetchIgnoringCacheData)
{(result, error) in
guard let r = result, error == nil else {
print(error?.localizedDescription ?? "")
return
}
// use the data in the GUI
self.hotelDetails = r.data?.getHotel
…
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mobile App – Phase 1
KEEP
CALM
and
WATCH
the
DEMO
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservations
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservations: Design
What data is required?
Can we use existing data sources?
How can we enable via AppSync?
Challenges?
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservations: GraphQL Schema
type Reservation {
confirmationNumber: ID!
hotel: Hotel!
guest: User!
startDate: AWSDate!
endDate: AWSDate!
rate: Int!
}
type Query {
...
reservations(guestId : ID!):[Reservation]
}
type Mutation {
createReservation(input:ReservationInput)
deleteReservation(confNum: ID!)
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservations: Query Resolver - Input
#set( $todayString = $util.time.nowISO8601().substring(0, 10) )
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression": "guestId = :gId AND startDate > :startDate",
"expressionValues": {
":gId": $util.dynamodb.toDynamoDBJson($ctx.identity.sub),
":startDate": $util.dynamodb.toDynamoDBJson($todayString)
}
}
}
Note: assumes user is logged in via AWS Cognito User Pool. Details are outside our scope.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservations: Query Resolver - Output
$util.toJson($ctx.result.items)
Note: assumes user is logged in via AWS Cognito User Pool. Details are outside our scope.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservations: Result
query {
guestReservations {
confirmationNumber
hotel {
hotelId
name
image
phoneNumber
}
startDate
endDate
}
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Extending Reservation Workflow
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Subscription Query
subscription ReservationSubscription {
createReservationEvent(guestId:1) {
confirmationNumber
}
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Mobile Code – Subscribe to changes
let sub = CreateReservationEventSubscription(guestId: userId)
newReservationSubscription = try appSyncClient?.subscribe(subscription: sub,
resultHandler: { (result, transaction, error) in
// check for error
// store a reference to the new booking into our cache
transaction?.update(query: GuestReservationsQuery(guestId: userId)) {
(data: inout GuestReservationsQuery.Data) in
data.guestReservations?.append(bookingToAdd)
// consume the data in the UI
self.bookingDetails?.append(bookingToAdd)
}
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Reservation Subscriptions
KEEP
CALM
and
WATCH
the
DEMO
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive Rates
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive Rates: Design
R&D is building an adaptive rate capability
Delivered via Amazon SageMaker API
How do we add today’s rate to our existing
API?
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive Rates: Evolving our GraphQL API
GraphQL supports multiple data
sources per query:
1. Add new field
2. Configure new Data Source
and Resolvers
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive Rates: GraphQL Types and Resolvers
type Hotel {
hotelId: ID!
name: String!
location: String!
...
rate: Rate
}
type Rate {
hotelId: ID!
rate: Int!
currency: String!
date: AWSDate!
}
## rate Field Resolver: Request Mapping ##
{
"version": "2018-05-29",
"method": "GET",
"resourcePath":
"/rd/rates/${ctx.source.hotelId}",
"params": {
"headers": {
"Content-Type": "application/json"
}
}
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Adaptive Rates: Result
query {
getHotel(hotelId: 3) {
name
location
image
phoneNumber
address {
street
city
}
amenities
rate {
currency
rate
}
}
}
{
"name": "ElastiLodge North Rodgerstad",
"location": "North Rodgerstad",
"image": "https://placehold.it/300x300.png",
"phoneNumber": "(214) 210-4674",
"address": {
"street": "",
"city": ""
},
"amenities": [ ... ],
"rate": {
"currency": "USD",
"rate": 312
}
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Field-level resolution
KEEP
CALM
and
WATCH
the
DEMO
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What did we just did ?
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What did we accomplish today?
Built a rich, flexible, mobile-ready API
Incorporated legacy, new, and prototype features in a single endpoint
Evolved API as requirements changed
No coding required!
Well, there were a few Velocity Templates
AWS Console includes starter / boilerplate templates
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Amplify CLI
Toolchain for developers
Enables you to prototype and
build quickly
Built-in GraphQL Transformer
Converts schema to CloudFormation
templates and builds cloud resources
$ amplify api add
# create GraphQL schema
# for example:
type Hotel @model @searchable {
name: String!
location: String!
...
}
https://github.com/aws-amplify/amplify-cli
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Backend Engineer: Hmm. So you’re saying this
“GraphQL” will allow any web or native engineer to
arbitrarily query basically any field in any backend
service, recursively, however they want, without any
backend engineers involved?
Frontend Engineer: Yeah, right? It’s amazing!
[…silence…]
Backend Engineer: Guards, seize this person.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Real world pitfalls
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Code presented today
https://github.com/sebsto/reinvent2018-mob320
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Great GraphQL Podcasts
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
{
"name": "Sébastien Stormacq",
"role": ”Technical Evangelist",
"company": "Amazon Web Services”,
"twitter": ”@sebsto”,
”github": ”sebsto”
}
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Please complete the session
survey in the mobile app.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

More Related Content

Similar to 0 to 100kmh with GraphQL. Rapid API Prototyping usingserverless backend in the cloud.pdf

Rapid API Prototyping Using Serverless Backend in the Cloud
Rapid API Prototyping Using Serverless Backend in the CloudRapid API Prototyping Using Serverless Backend in the Cloud
Rapid API Prototyping Using Serverless Backend in the CloudAmazon Web Services
 
0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...
0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...
0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...Amazon Web Services
 
Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018
Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018
Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018Amazon Web Services
 
Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...
Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...
Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...Amazon Web Services
 
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS AmplifyTake Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS AmplifyAmazon Web Services
 
AppSync in real world - pitfalls, unexpected benefits & lessons learnt
AppSync in real world - pitfalls, unexpected benefits & lessons learntAppSync in real world - pitfalls, unexpected benefits & lessons learnt
AppSync in real world - pitfalls, unexpected benefits & lessons learntAWS User Group Bengaluru
 
Simplify your Web & Mobile applications with cloud-based serverless backends
Simplify your Web & Mobile applicationswith cloud-based serverless backendsSimplify your Web & Mobile applicationswith cloud-based serverless backends
Simplify your Web & Mobile applications with cloud-based serverless backendsSébastien ☁ Stormacq
 
Automate your Amazon SageMaker Workflows (July 2019)
Automate your Amazon SageMaker Workflows (July 2019)Automate your Amazon SageMaker Workflows (July 2019)
Automate your Amazon SageMaker Workflows (July 2019)Julien SIMON
 
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
 
Serverless APIs and you
Serverless APIs and youServerless APIs and you
Serverless APIs and youJames Beswick
 
AWS Neptune - A Fast and reliable Graph Database Built for the Cloud
AWS Neptune - A Fast and reliable Graph Database Built for the CloudAWS Neptune - A Fast and reliable Graph Database Built for the Cloud
AWS Neptune - A Fast and reliable Graph Database Built for the CloudAmazon Web Services
 
"Integrate your front end apps with serverless backend in the cloud", Sebasti...
"Integrate your front end apps with serverless backend in the cloud", Sebasti..."Integrate your front end apps with serverless backend in the cloud", Sebasti...
"Integrate your front end apps with serverless backend in the cloud", Sebasti...Provectus
 
AI Services and Serverless Workshop
AI Services and Serverless WorkshopAI Services and Serverless Workshop
AI Services and Serverless WorkshopBoaz Ziniman
 
Simplify Your Front End Apps with Serverless Backend in the Cloud.
Simplify Your Front End Apps with Serverless Backend in the Cloud.Simplify Your Front End Apps with Serverless Backend in the Cloud.
Simplify Your Front End Apps with Serverless Backend in the Cloud.Amazon Web Services
 
Securing SaaS Applications Built on Serverless Microservices - AWS Summit Sydney
Securing SaaS Applications Built on Serverless Microservices - AWS Summit SydneySecuring SaaS Applications Built on Serverless Microservices - AWS Summit Sydney
Securing SaaS Applications Built on Serverless Microservices - AWS Summit SydneyAmazon Web Services
 
IoT Building Blocks From Edge Devices to Analytics in the Cloud
IoT Building Blocks From Edge Devices to Analytics in the CloudIoT Building Blocks From Edge Devices to Analytics in the Cloud
IoT Building Blocks From Edge Devices to Analytics in the CloudAmazon Web Services
 
Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018
Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018
Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018Amazon Web Services
 
Build your APPs in Lean and Agile Way using AWS Amplify
Build your APPs in Lean and Agile Way using AWS AmplifyBuild your APPs in Lean and Agile Way using AWS Amplify
Build your APPs in Lean and Agile Way using AWS AmplifyAmazon Web Services
 
Add Intelligence to Applications with AWS AI Services
Add Intelligence to Applications with AWS AI ServicesAdd Intelligence to Applications with AWS AI Services
Add Intelligence to Applications with AWS AI ServicesNicholas Walsh
 

Similar to 0 to 100kmh with GraphQL. Rapid API Prototyping usingserverless backend in the cloud.pdf (20)

Rapid API Prototyping Using Serverless Backend in the Cloud
Rapid API Prototyping Using Serverless Backend in the CloudRapid API Prototyping Using Serverless Backend in the Cloud
Rapid API Prototyping Using Serverless Backend in the Cloud
 
0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...
0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...
0 to 60 with AWS AppSync: Rapid Development Techniques for Mobile APIs (MOB32...
 
Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018
Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018
Build a "Who's Who" App for Your Media Content (AIM409) - AWS re:Invent 2018
 
Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...
Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...
Migrate an existing application RESTful API’s to GraphQL using AWS Amplify an...
 
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS AmplifyTake Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
 
AppSync in real world - pitfalls, unexpected benefits & lessons learnt
AppSync in real world - pitfalls, unexpected benefits & lessons learntAppSync in real world - pitfalls, unexpected benefits & lessons learnt
AppSync in real world - pitfalls, unexpected benefits & lessons learnt
 
Simplify your Web & Mobile applications with cloud-based serverless backends
Simplify your Web & Mobile applicationswith cloud-based serverless backendsSimplify your Web & Mobile applicationswith cloud-based serverless backends
Simplify your Web & Mobile applications with cloud-based serverless backends
 
Automate your Amazon SageMaker Workflows (July 2019)
Automate your Amazon SageMaker Workflows (July 2019)Automate your Amazon SageMaker Workflows (July 2019)
Automate your Amazon SageMaker Workflows (July 2019)
 
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) ...
 
Serverless APIs and you
Serverless APIs and youServerless APIs and you
Serverless APIs and you
 
AWS Neptune - A Fast and reliable Graph Database Built for the Cloud
AWS Neptune - A Fast and reliable Graph Database Built for the CloudAWS Neptune - A Fast and reliable Graph Database Built for the Cloud
AWS Neptune - A Fast and reliable Graph Database Built for the Cloud
 
"Integrate your front end apps with serverless backend in the cloud", Sebasti...
"Integrate your front end apps with serverless backend in the cloud", Sebasti..."Integrate your front end apps with serverless backend in the cloud", Sebasti...
"Integrate your front end apps with serverless backend in the cloud", Sebasti...
 
AI Services and Serverless Workshop
AI Services and Serverless WorkshopAI Services and Serverless Workshop
AI Services and Serverless Workshop
 
Simplify Your Front End Apps with Serverless Backend in the Cloud.
Simplify Your Front End Apps with Serverless Backend in the Cloud.Simplify Your Front End Apps with Serverless Backend in the Cloud.
Simplify Your Front End Apps with Serverless Backend in the Cloud.
 
Securing SaaS Applications Built on Serverless Microservices - AWS Summit Sydney
Securing SaaS Applications Built on Serverless Microservices - AWS Summit SydneySecuring SaaS Applications Built on Serverless Microservices - AWS Summit Sydney
Securing SaaS Applications Built on Serverless Microservices - AWS Summit Sydney
 
IoT Building Blocks From Edge Devices to Analytics in the Cloud
IoT Building Blocks From Edge Devices to Analytics in the CloudIoT Building Blocks From Edge Devices to Analytics in the Cloud
IoT Building Blocks From Edge Devices to Analytics in the Cloud
 
Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018
Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018
Executing a Large Scale Migration to AWS (ENT337-R2) - AWS re:Invent 2018
 
Build your APPs in Lean and Agile Way using AWS Amplify
Build your APPs in Lean and Agile Way using AWS AmplifyBuild your APPs in Lean and Agile Way using AWS Amplify
Build your APPs in Lean and Agile Way using AWS Amplify
 
Simplify front end apps.pdf
Simplify front end apps.pdfSimplify front end apps.pdf
Simplify front end apps.pdf
 
Add Intelligence to Applications with AWS AI Services
Add Intelligence to Applications with AWS AI ServicesAdd Intelligence to Applications with AWS AI Services
Add Intelligence to Applications with AWS AI Services
 

More from 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
 

More from 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
 

0 to 100kmh with GraphQL. Rapid API Prototyping usingserverless backend in the cloud.pdf

  • 1. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 03.04.2019 O S L O
  • 2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 0 to 100 with GraphQL: Rapid Development Techniques for APIs { "name": "Sébastien Stormacq", "role": ”Technical Evangelist", "company": "Amazon Web Services”, "twitter": ”@sebsto”, ”github": ”sebsto” } B A R 4 O S L O 03.04.2019
  • 3. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. This talk is for developers
  • 4. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. This talk is for developers < frontend | backend >
  • 5. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. How to you prototype API ?
  • 6. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Congratulations ! You’ve just been hired.
  • 7. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 8. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Today’s mobile experience is lacking Mobile website, no native apps Slow to book, low conversion rates Backend built for high-speed desktops !
  • 9. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Your job is to define tomorrow’s experience Digital agencies hired for design First prototype in 4 weeks Must use real data, no mockup !
  • 10. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Our Goal Enable backend services for prototype Allow design to evolve Keeping up with day-to-day job !
  • 11. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. { "_id": 3, "name": "ElastiLodge South Zanetown", "image": "https://placehold.it/300x300.png", "description": "Sint nostrum vel quibusdam quia reprehenderit cum exercitationem quia ea.", "location": "South Zanetown", "manager": { "name": "Florentino Jacobi", "email": "florentino.jacobi@elastilodge.com" }, "timeZone": "US/Central", "phoneNumber": "802-918-3262", "category": 5, Legacy REST API "address": { "street": "410 Simonis Forest", "zip": "07545-2308", "city": "South Zanetown", "country": "Virgin Islands, British" }, "deskHours": "24 hours", "amenities": [ ... ], "restaurants": [ ... ] }
  • 12. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. What are the challenges of REST API
  • 13. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. /posts /comments /authors REST API Chatty & Over fetching { "posts" : [ { "id" : 1, "content" : "the quick brown fox jumps over the…", "author" : "/authors/123", "created" : 1550486509, "comments" : "/posts/1/comments", ... }, { "id" : 2, "content" : "the quick brown fox jumps over…", "author" : "/authors/123" "created" : 1550486509, "comments" : "/posts/2/comments", ... } ] }
  • 14. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Introducing GraphQL
  • 15. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. https://graphql.org
  • 16. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why GraphQL ? posts comments authors GraphQL API
  • 17. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. How does GraphQL work? type Query { getTodos: [Todo] } type Todo { id: ID! name: String description: String priority: Int duedate: String } Model data with application schema query { getTodos { id name priority } } Client requests what it needs { "id": "1", "name": "Get Milk", "priority": "1" }, { "id": "2", "name": "Go to gym", "priority": "5" },… Only that data is returned
  • 18. © 2019, 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: “harry potter”) { title } } mutation { create(title: “new book”) { id } } subscription { onCreate { id title } }
  • 19. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Is REST dead then? When data drives UI Structured data Query-driven Client-driven development Use GraphQL When you leverage HTTP Caching, Content types Hypermedia (HATEOAS) For resources (eg Amazon S3) Use REST Pick the appropriate protocol for your use case
  • 20. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. How to deploy GraphQL API ?
  • 21. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS App Sync 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 facade for any AWS service Conflict detection and resolution in the cloud Enterprise security features: IAM, Amazon Cognito, OIDC, API keys
  • 22. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AppSync Data Sources
  • 23. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AppSync Resolvers
  • 24. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hello AWS AppSync KEEP CALM and WATCH the DEMO
  • 25. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Prototype : Phase #1 Hotel Detail
  • 26. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hotel Detail: Design What data is required? Can we use existing data sources? How can we enable via AppSync? Challenges? Missing data?
  • 27. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mapping to Legacy API { "_id": 3, "image": "https://placehold.it/300x300.png", "name": "EL Resort & Spa", "description": "...", "location": "Fiji", "manager": { "name": "Florentino Jacobi", "email": "florentino.jacobi@elastilodge.com" }, "timeZone": "US/Central", "address": { "street": "123 Main St", ”postalcode": "07545", "city": "Momi Bay", "country": "Fiji" }, "phoneNumber": "1-888-123-4567", "category": 5, "deskHours": "24 hours", "amenities": [ ... ], "restaurants": [ ... ] }
  • 28. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mapping to Legacy API { "_id": 3, "image": "https://placehold.it/300x300.png", "name": "EL Resort & Spa", "description": "...", "location": "Fiji", "manager": { "name": "Florentino Jacobi", "email": "florentino.jacobi@elastilodge.com" }, "timeZone": "US/Central", "address": { "street": "123 Main St", ”postalcode": "07545", "city": "Momi Bay", "country": "Fiji" }, "phoneNumber": "1-888-123-4567", "category": 5, "deskHours": "24 hours", "amenities": [ ... ], "restaurants": [ ... ] }
  • 29. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hotel Detail: GraphQL Schema type Hotel { hotelId: ID! name: String! image: String location: String! phoneNumber: AWSPhone! address: Address! ... } type Query { listHotels(offset: String, limit: Int) getHotel(hotelId: ID!) }
  • 30. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hotel Detail: Resolvers ## Resolver: Request Mapping ## { "version": "2018-05-29", "method": "GET", "resourcePath": "/hotels/${ctx.args.hotelId}", "params": { "headers": { "Content-Type": "application/json" } }, } ## Resolver: Response Mapping ## #if($ctx.result.statusCode == 200) ## If response is 200, return the body. ## Could also filter result... $ctx.result.body #else ## If not 200, append response to error $utils.appendError($ctx.result.body) #end
  • 31. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Hotel Detail: Result query { getHotel(hotelId: 3) { name location image phoneNumber address { street city } amenities } } { "name": "ElastiLodge North Rodgerstad", "location": "North Rodgerstad", "image": "/300x300.png", "phoneNumber": "(214) 210-4674", "address": { "street": "123 Main St", "city": "North Rodgerstad" }, "amenities": [ ... ] }
  • 32. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mobile Code – Initialize App Sync Client do { // create app sync configuration (cache, service config etc) let config = … // client initialization let appSyncClient = try AWSAppSyncClient(appSyncConfig: config) } catch { fatalError("Error initializing appsync client. (error)") }
  • 33. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mobile Code – Run a Query // call a GraphQL Query appSyncClient?.fetch(query: GetHotelQuery(hotelId: hotelId), cachePolicy: .fetchIgnoringCacheData) {(result, error) in guard let r = result, error == nil else { print(error?.localizedDescription ?? "") return } // use the data in the GUI self.hotelDetails = r.data?.getHotel … }
  • 34. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mobile App – Phase 1 KEEP CALM and WATCH the DEMO
  • 35. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservations
  • 36. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservations: Design What data is required? Can we use existing data sources? How can we enable via AppSync? Challenges?
  • 37. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservations: GraphQL Schema type Reservation { confirmationNumber: ID! hotel: Hotel! guest: User! startDate: AWSDate! endDate: AWSDate! rate: Int! } type Query { ... reservations(guestId : ID!):[Reservation] } type Mutation { createReservation(input:ReservationInput) deleteReservation(confNum: ID!) }
  • 38. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservations: Query Resolver - Input #set( $todayString = $util.time.nowISO8601().substring(0, 10) ) { "version": "2017-02-28", "operation": "Query", "query": { "expression": "guestId = :gId AND startDate > :startDate", "expressionValues": { ":gId": $util.dynamodb.toDynamoDBJson($ctx.identity.sub), ":startDate": $util.dynamodb.toDynamoDBJson($todayString) } } } Note: assumes user is logged in via AWS Cognito User Pool. Details are outside our scope.
  • 39. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservations: Query Resolver - Output $util.toJson($ctx.result.items) Note: assumes user is logged in via AWS Cognito User Pool. Details are outside our scope.
  • 40. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservations: Result query { guestReservations { confirmationNumber hotel { hotelId name image phoneNumber } startDate endDate } }
  • 41. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Extending Reservation Workflow
  • 42. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Subscription Query subscription ReservationSubscription { createReservationEvent(guestId:1) { confirmationNumber } }
  • 43. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mobile Code – Subscribe to changes let sub = CreateReservationEventSubscription(guestId: userId) newReservationSubscription = try appSyncClient?.subscribe(subscription: sub, resultHandler: { (result, transaction, error) in // check for error // store a reference to the new booking into our cache transaction?.update(query: GuestReservationsQuery(guestId: userId)) { (data: inout GuestReservationsQuery.Data) in data.guestReservations?.append(bookingToAdd) // consume the data in the UI self.bookingDetails?.append(bookingToAdd) } }
  • 44. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Reservation Subscriptions KEEP CALM and WATCH the DEMO
  • 45. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive Rates
  • 46. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive Rates: Design R&D is building an adaptive rate capability Delivered via Amazon SageMaker API How do we add today’s rate to our existing API?
  • 47. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive Rates: Evolving our GraphQL API GraphQL supports multiple data sources per query: 1. Add new field 2. Configure new Data Source and Resolvers
  • 48. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive Rates: GraphQL Types and Resolvers type Hotel { hotelId: ID! name: String! location: String! ... rate: Rate } type Rate { hotelId: ID! rate: Int! currency: String! date: AWSDate! } ## rate Field Resolver: Request Mapping ## { "version": "2018-05-29", "method": "GET", "resourcePath": "/rd/rates/${ctx.source.hotelId}", "params": { "headers": { "Content-Type": "application/json" } } }
  • 49. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Adaptive Rates: Result query { getHotel(hotelId: 3) { name location image phoneNumber address { street city } amenities rate { currency rate } } } { "name": "ElastiLodge North Rodgerstad", "location": "North Rodgerstad", "image": "https://placehold.it/300x300.png", "phoneNumber": "(214) 210-4674", "address": { "street": "", "city": "" }, "amenities": [ ... ], "rate": { "currency": "USD", "rate": 312 } }
  • 50. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Field-level resolution KEEP CALM and WATCH the DEMO
  • 51. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. What did we just did ?
  • 52. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. What did we accomplish today? Built a rich, flexible, mobile-ready API Incorporated legacy, new, and prototype features in a single endpoint Evolved API as requirements changed No coding required! Well, there were a few Velocity Templates AWS Console includes starter / boilerplate templates
  • 53. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Amplify CLI Toolchain for developers Enables you to prototype and build quickly Built-in GraphQL Transformer Converts schema to CloudFormation templates and builds cloud resources $ amplify api add # create GraphQL schema # for example: type Hotel @model @searchable { name: String! location: String! ... } https://github.com/aws-amplify/amplify-cli
  • 54. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Backend Engineer: Hmm. So you’re saying this “GraphQL” will allow any web or native engineer to arbitrarily query basically any field in any backend service, recursively, however they want, without any backend engineers involved? Frontend Engineer: Yeah, right? It’s amazing! […silence…] Backend Engineer: Guards, seize this person.
  • 55. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Real world pitfalls
  • 56. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Code presented today https://github.com/sebsto/reinvent2018-mob320
  • 57. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Great GraphQL Podcasts
  • 58. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Thank you! © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. { "name": "Sébastien Stormacq", "role": ”Technical Evangelist", "company": "Amazon Web Services”, "twitter": ”@sebsto”, ”github": ”sebsto” }
  • 59. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Please complete the session survey in the mobile app. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.