GraphQL has become the API of choice for many leading technology companies. In 2018 AWS made its’ managed GraphQL service, AWS AppSync, generally available. In this talk we discussed:
* What GraphQL is
* Why it is being adopted
* What AWS AppSync is and how it works
* Where AWS AppSync fits into the broader AWS serverless landscape.
Presenter Bio: Peter Dyer is a Freelancer and https://www.fullsapps.com/ contributor. You can follow him on Twitter @peter_dyer.
More info about the event: https://www.linkedin.com/feed/update/urn:li:activity:6500574686257168384
Join www.ServerlessToronto.org community to learn how to leverage Serverless Architectures in order to innovate faster, and make your apps scalable & cost-effective!
3. Tuesday, Jan 29, 2019
1. Introduction
2. Community Open Mic
3. Presentation: Peter Dyer
GraphQL, AWS AppSync
and AWS Serverless
4. Networking
3
Serverless Toronto Meetup Agenda
6. Who am I
Peter
Twenty years working in software
● Majority for small software companies
● Majority as a technical product manager
Currently focused on fullstack development (opinionated about the stack)
7. Backend-as-a-Service / Serverless
I want interactive software in the hands of users ASAP
I want to take advantage of the code that others have written (services or libraries)
Humans are almost always the most expensive part of development
(At scale, things are different)
8. My view of Serverless
Authentication
Database
Storage
Hosting
Functions
APIs
Analytics
Machine Learning
Notifications
PubSub
Etc
10. What is GraphQL?
“A query language for your API”
Originated in Facebook (2012)
Open-source specification (2015)
“Competitor” to REST
Source: https://graphql.org/
11. Why GraphQL?
Ask for what you want, and get only that
Get many resources in a single request
Discoverability (documentation) is built in
Avoid API versioning
It’s just the API
12. Who is using GraphQL
● Netflix
● New York Times
● AirBnB
● Telus
● Etc
Source: https://graphql.org/
13. vs REST
In common
● HTTP
● JSON
● Just API
● Good tooling
GraphQL Improvements
● No over-fetching
● No under-fetching
● No (limited) need for versioning
● Documentation is built in
15. Star Wars - list people (just names)
REST
https://swapi.co/api/
people
Result: 7,447 characters (for page 1, 10 of 87
people)
GraphQL
https://graphql.github.io/swapi-graphql/
query {
allPeople {
people {
name
}
}
}
Result: 4,916 characters
16. Star Wars - name of Luke’s films
REST
https://swapi.co/api/
people/1
films/1/
films/2/
films/3/
films/6/
films/7/
Result: ~2,500 characters per request (6
requests)
GraphQL
https://graphql.github.io/swapi-graphql/
query {
person(id: "cGVvcGxlOjE=") {
name
filmConnection {
films {
title
}
}
}
}
Result: 492 characters
17. Star Wars - add shoe_size field to people
REST
Every ‘good’
implementation breaks, or
new API version
Someone needs to update
the documentation
GraphQL
Nothing breaks, anyone
who wants to can start
using the new field
Documentation has been
automatically updated
18. GraphQL terminology
● Type system
● Schema
● Queries
● Mutations
● Subscriptions
● Resolver
● Client & Server
21. AWS AppSync
Amazon’s GraphQL service
https://aws.amazon.com/appsync/
“AWS AppSync is a serverless back-end for mobile, web and enterprise
applications”
23. How it works
Resolvers "translate" GraphQL to do something with a "Data Source"
Data Sources = DynamoDB, Lambda, ElasticSearch, Aurora, HTTP
Translation via VTL (Apache Velocity Template Language)
25. Steps
1. Create Lambda function(s) that will “resolve” API request
a. Use Events to pass in arguments
2. Create AppSync API
3. Add Lambda function(s) as Data Sources to AppSync API
4. Create API schema (GraphQL schema)
5. Attach Resolvers and edit mappings
6. Test API
7. Use API
27. Where does AppSync fit in AWS Serverless
Short answer
Nowhere (it is not part of the documented reference architecture)
The real answer
Wherever you see API Gateway
Wherever an application needs to call an AWS back-end for something
AppSync is an API Proxy that leverages GraphQL instead of REST
31. AWS AppSync (hosted GraphQL) Alternatives
AWS is the only big 3 cloud vendor with a GraphQL service
GraphQL servers are easily deployed to a server or a PaaS
Google Firebase - deploy as a Function (performance?)
Prisma Cloud
For development (these are not managed services)
● https://codesandbox.io/s/apollo-server
● https://glitch.com/~apollo-launchpad
32. AWS Amplify Framework
Evolution of AWS Mobile Hub
Amazon's answer to Google Firebase
Goal - make it easy for application (front-end) developers to use (consume) back-
end resources
“The foundation for your cloud-powered mobile & web apps”