© 2019, Amazon Web Services, Inc. or its Affiliates.
Marcia Villalba – AWS Technical Evangelist
@mavi888uy
Serverless 🧡 GraphQL
A match made in heaven
Highload fwdays’19 – 5th Oct 2019
© 2019, Amazon Web Services, Inc. or its Affiliates.
About me
AWS since September 2019
Coding for more than 15 years
Serverless since 2016
Content creator
Before AWS I was working in gaming
© 2019, Amazon Web Services, Inc. or its Affiliates.
Speed to market
GraphQL? Serverless? 🤔
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless
Brief introduction
© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless promises
No managing infrastructure High availability built in
Pay for what you useScales automagically
© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless
Backend as a service
(BAAS)
Function as a service
(FAAS)
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Buildings blocks for serverless applications
Compute Storage Databases
API management Messaging Analytics
Orchestration Monitoring User Management
API Gateway
AWS Lambda
AppSync
Step functions Event Brigde
Amazon S3
Amazon SNS Amazon SQS
CloudWatch
DynamoDB
Amazon Kinesis Amazon Athena
Amazon Cognito
© 2019, Amazon Web Services, Inc. or its Affiliates.
What is GraphQL?
Let’s talk about the most important concepts
© 2019, Amazon Web Services, Inc. or its Affiliates.
GraphQL is a specification
Not a framework
Not a database
Not a server
© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql schema
Describe all the data the
client has available and what
the client can do using a type
system
© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql characteristics
Ask for what you need an get
exactly that.
No over fetching
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql characteristics
Get many resources in one request.
No under fetching
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql characteristics
Evolve your API without
versions
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql - Characteristics
Connect to multiple
datasources Heroes database
Planets HTTP service
Species non relational
database
© 2019, Amazon Web Services, Inc. or its Affiliates.
What are datasources?
• A Database
• Another service with an API
• A HTTP request that return data
• A call to a search service
• Can be anything!
© 2019, Amazon Web Services, Inc. or its Affiliates.
GraphQL query language
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql – Query Language
Everything is a type
Fields can be scalar or other types
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql – Query Language
There are special types
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql – Query Language
Entry point to the graphql query
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql – Query Language
The client can write a query like this And get exactly what it needs
© 2019, Amazon Web Services, Inc. or its Affiliates.
Graphql – Query Language
Very complete language
Read more about it here: https://graphql.org/learn/
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
Client
GraphQL
SQL datasource
1.
Create the schema.
Describe all the available types and
operations
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
Client
GraphQL
SQL datasource
2.
Define all your resolvers, to be able
to serve all the operations defined in
the schema
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
Client
GraphQL
SQL datasource
3.
The client makes a request
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
Client
GraphQL
SQL datasource
4.
GraphQL uses the request resolver to
translate the client query and get
data from the datasource Translate GraphQL query into
SELECT video_id, video_name FROM videos
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
Client
GraphQL
SQL datasource
5.
GraphQL uses the response resolver
to return data from the datasource
to the client
In this case the resolver will
translate SQL into JSON
© 2019, Amazon Web Services, Inc. or its Affiliates.
How GraphQL works?
Client
GraphQL
SQL datasource
6.
GraphQL returns the JSON response
to the client
© 2019, Amazon Web Services, Inc. or its Affiliates.
GraphQL
or REST
© 2019, Amazon Web Services, Inc. or its Affiliates.
So when to use GraphQL?
- Creating a single entry point for your clients
Client
GraphQL
Orders service
Customers service
Product service
© 2019, Amazon Web Services, Inc. or its Affiliates.
So when to use GraphQL?
- When you want to add more functionality to an old service
Client
GraphQL
Old customers service
© 2019, Amazon Web Services, Inc. or its Affiliates.
So when to use GraphQL?
- When you want to simplify a complex API
Client
GraphQL
Very complex API
© 2019, Amazon Web Services, Inc. or its Affiliates.
Implementing GraphQL
Implement your own GraphQL server
Use an existing GraphQL server library
Use an existing GraphQL platform
© 2019, Amazon Web Services, Inc. or its Affiliates.
Existing GraphQL platforms
Apollo Platform (https://www.apollographql.com/platform/)
GraphCMS (https://graphcms.com/)
GraphCool (https://www.graph.cool/)
AppSync (https://aws.amazon.com/appsync/)
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS AppSync
Serverless GraphQL platform
© 2019, Amazon Web Services, Inc. or its Affiliates.
Appsync
AWS AppSync is a managed service for application data using GraphQL
with real-time capabilities and offline programming model
Real time Offline support Support for many
different Databases
Fine grained access
control
© 2019, Amazon Web Services, Inc. or its Affiliates.
AppSync Security
- API KEY authorization
- Amazon Cognito User Pools authorization
- OPEN ID Connect Authorization
- AWS IAM
- Fine grained access control
© 2019, Amazon Web Services, Inc. or its Affiliates.
AppSync Datasources
- Amazon DynamoDB
- AWS Lambda
- Amazon Elastic Search
- Amazon Aurora
- HTTP services
© 2019, Amazon Web Services, Inc. or its Affiliates.
AppSync Resolvers
- A resolver must be attached for every operation
- Velocity template language (VTL)
- Takes requests as inputs and outputs a JSON document containing
the instructions to the data source
- VTL allows quite complex operations over the data – loops,
conditions, filters.
© 2019, Amazon Web Services, Inc. or its Affiliates.
How Appsync works?
Creates a schema
© 2019, Amazon Web Services, Inc. or its Affiliates.
How Appsync works?
Connect to different
datasources
Creates a schema
© 2019, Amazon Web Services, Inc. or its Affiliates.
How Appsync works?
Connect to different
datasources
Creates a schema
Updates data in real time
in different devices
© 2019, Amazon Web Services, Inc. or its Affiliates.
Customer story using Appsync??
© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
Infrastructure as code
• AWS Cloudformation
• Serverless Framework
• Serverless Framework plugin for AppSync
(https://github.com/sid88in/serverless-appsync-plugin)
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Cloud
Client
AWS
AppSync
AWS
Lambda
Amazon
DynamoDB
VLT mappers
for request
and response
VLT mappers
for request
and response
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
How the client uses this?
• AWS Amplify
• Client library for building cloud apps
• More info: https://aws-amplify.github.io/docs/js/api#aws-appsync-
sdk
© 2019, Amazon Web Services, Inc. or its Affiliates.
Configure the client
© 2019, Amazon Web Services, Inc. or its Affiliates.
Run a Query
© 2019, Amazon Web Services, Inc. or its Affiliates.
Best practices when working with AppSync
- Think about how to implement search
- Be careful when doing a lot of HTTP requests
- Use as much VLT resolvers as possible
- Use subscriptions appropriately
- Paginate your large responses
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Q&AMarcia Villalba
AWS Loft in Kyiv
14-18 October
https://aws-loft.provectus.com
Marcia Villalba
@mavi888uy
Practical examples on AppSync and more on
serverless
https://www.youtube.com/foobar_codes
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Thank you!
Marcia Villalba
@mavi888uy
AWS Loft in Kyiv
14-18 October
https://aws-loft.provectus.com
Practical examples on AppSync and more on
serverless
https://www.youtube.com/foobar_codes

Marcia Villalba "Developing Serverless Applications with GraphQL"

  • 1.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Marcia Villalba – AWS Technical Evangelist @mavi888uy Serverless 🧡 GraphQL A match made in heaven Highload fwdays’19 – 5th Oct 2019
  • 2.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. About me AWS since September 2019 Coding for more than 15 years Serverless since 2016 Content creator Before AWS I was working in gaming
  • 3.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Speed to market GraphQL? Serverless? 🤔
  • 4.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Serverless Brief introduction
  • 5.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Serverless promises No managing infrastructure High availability built in Pay for what you useScales automagically
  • 6.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Serverless Backend as a service (BAAS) Function as a service (FAAS)
  • 7.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AWS Buildings blocks for serverless applications Compute Storage Databases API management Messaging Analytics Orchestration Monitoring User Management API Gateway AWS Lambda AppSync Step functions Event Brigde Amazon S3 Amazon SNS Amazon SQS CloudWatch DynamoDB Amazon Kinesis Amazon Athena Amazon Cognito
  • 8.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. What is GraphQL? Let’s talk about the most important concepts
  • 9.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. GraphQL is a specification Not a framework Not a database Not a server
  • 10.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.
  • 11.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.
  • 12.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql schema Describe all the data the client has available and what the client can do using a type system
  • 13.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.
  • 14.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql characteristics Ask for what you need an get exactly that. No over fetching
  • 15.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql characteristics Get many resources in one request. No under fetching
  • 16.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql characteristics Evolve your API without versions
  • 17.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql - Characteristics Connect to multiple datasources Heroes database Planets HTTP service Species non relational database
  • 18.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. What are datasources? • A Database • Another service with an API • A HTTP request that return data • A call to a search service • Can be anything!
  • 19.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. GraphQL query language
  • 20.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql – Query Language Everything is a type Fields can be scalar or other types
  • 21.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql – Query Language There are special types
  • 22.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql – Query Language Entry point to the graphql query
  • 23.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql – Query Language The client can write a query like this And get exactly what it needs
  • 24.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Graphql – Query Language Very complete language Read more about it here: https://graphql.org/learn/
  • 25.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works?
  • 26.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works? Client GraphQL SQL datasource 1. Create the schema. Describe all the available types and operations
  • 27.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works? Client GraphQL SQL datasource 2. Define all your resolvers, to be able to serve all the operations defined in the schema
  • 28.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works? Client GraphQL SQL datasource 3. The client makes a request
  • 29.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works? Client GraphQL SQL datasource 4. GraphQL uses the request resolver to translate the client query and get data from the datasource Translate GraphQL query into SELECT video_id, video_name FROM videos
  • 30.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works? Client GraphQL SQL datasource 5. GraphQL uses the response resolver to return data from the datasource to the client In this case the resolver will translate SQL into JSON
  • 31.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How GraphQL works? Client GraphQL SQL datasource 6. GraphQL returns the JSON response to the client
  • 32.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. GraphQL or REST
  • 33.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. So when to use GraphQL? - Creating a single entry point for your clients Client GraphQL Orders service Customers service Product service
  • 34.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. So when to use GraphQL? - When you want to add more functionality to an old service Client GraphQL Old customers service
  • 35.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. So when to use GraphQL? - When you want to simplify a complex API Client GraphQL Very complex API
  • 36.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Implementing GraphQL Implement your own GraphQL server Use an existing GraphQL server library Use an existing GraphQL platform
  • 37.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Existing GraphQL platforms Apollo Platform (https://www.apollographql.com/platform/) GraphCMS (https://graphcms.com/) GraphCool (https://www.graph.cool/) AppSync (https://aws.amazon.com/appsync/)
  • 38.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AWS AppSync Serverless GraphQL platform
  • 39.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Appsync AWS AppSync is a managed service for application data using GraphQL with real-time capabilities and offline programming model Real time Offline support Support for many different Databases Fine grained access control
  • 40.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AppSync Security - API KEY authorization - Amazon Cognito User Pools authorization - OPEN ID Connect Authorization - AWS IAM - Fine grained access control
  • 41.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AppSync Datasources - Amazon DynamoDB - AWS Lambda - Amazon Elastic Search - Amazon Aurora - HTTP services
  • 42.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AppSync Resolvers - A resolver must be attached for every operation - Velocity template language (VTL) - Takes requests as inputs and outputs a JSON document containing the instructions to the data source - VTL allows quite complex operations over the data – loops, conditions, filters.
  • 43.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How Appsync works? Creates a schema
  • 44.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How Appsync works? Connect to different datasources Creates a schema
  • 45.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How Appsync works? Connect to different datasources Creates a schema Updates data in real time in different devices
  • 46.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Customer story using Appsync??
  • 47.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.
  • 48.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Infrastructure as code • AWS Cloudformation • Serverless Framework • Serverless Framework plugin for AppSync (https://github.com/sid88in/serverless-appsync-plugin)
  • 49.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AWS Cloud Client AWS AppSync AWS Lambda Amazon DynamoDB VLT mappers for request and response VLT mappers for request and response
  • 50.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
  • 51.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.
  • 52.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How the client uses this? • AWS Amplify • Client library for building cloud apps • More info: https://aws-amplify.github.io/docs/js/api#aws-appsync- sdk
  • 53.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Configure the client
  • 54.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Run a Query
  • 55.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Best practices when working with AppSync - Think about how to implement search - Be careful when doing a lot of HTTP requests - Use as much VLT resolvers as possible - Use subscriptions appropriately - Paginate your large responses
  • 56.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Q&AMarcia Villalba AWS Loft in Kyiv 14-18 October https://aws-loft.provectus.com Marcia Villalba @mavi888uy Practical examples on AppSync and more on serverless https://www.youtube.com/foobar_codes
  • 57.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Thank you! Marcia Villalba @mavi888uy AWS Loft in Kyiv 14-18 October https://aws-loft.provectus.com Practical examples on AppSync and more on serverless https://www.youtube.com/foobar_codes