Using an AWS-managed service

This chapter is really about introducing you to AWS AppSync, the fully managed serverless GraphQL service. By all means, you can implement your own graphql runtime using Lambda compute, but why would you when there is one built and maintained for you? Using AppSync allows you to focus more on building the application, rather than the infrastructure.

AppSync provides one controlled API endpoint that you POST your operations to. It's a little different from the resource-based URLs that you might be used to in REST. The endpoint is reliable and scalable and supports WebSockets for real-time event-driven APIs. 

The following diagram shows how the new implementation looks when using AppSync. You can see that our API Gateway endpoint and backing Lambda have been replaced by AWS AppSync:

Implementation of a GraphQL API using AppSync

AppSync comes with managed resolvers that can natively communicate with several AWS services and other REST endpoints. As a GraphQL developer, you provide templates written in VTL (short for Velocity Templating Language) that map the requests and responses to the appropriate fields. These mapping templates are actually powerful enough that you can implement custom business logic to transform the fields during the mapping.

AppSync, of course, gives you a place to create your own schema, or import an existing one. Also, don't forget your security. AppSync integrates with Cognito User Pools (or any OpenID Connect provider) so you can use jwt tokens with your requests. You can even go one step further and define in your schema which groups of users in Cognito are allowed to run each query or mutation. So, that brings native authentication and authorization into your GraphQL schema—that's cool.

Once set up, the basic flow of data looks like this:

  • The frontend makes an HTTP POST request to our AppSync API endpoint.
  • AppSync uses our GraphQL schema to validate the request.
  • AppSync uses our request mapping template to map the request to our data source.
  • Data is fetched from the data source.
  • AppSync uses our response mapping template to map the response from our data source to fields in the API.
  • The frontend receives an HTTP response from our AppSync API.

The AppSync service was designed to simplify the setup required for a frontend developer needing backend infrastructure. Where the service shines is the amount of time it takes to spin up a streamlined CRUD API for backend data sources such as DynamoDB.

That was a brief introduction to AppSync; hopefully, it is clear that it is much simpler to use a managed service to implement your GraphQL runtime.

Check out the Further reading section for getting started tutorials.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.75