AppSync
Learn about AWS AppSync and some of its use cases.
We'll cover the following
AWS AppSync is a fully managed AWS service that allows us to create serverless endpoints for our GraphQL APIs. It allows developers to securely connect their services or applications with data sources through GraphQL APIs. With AppSync, we can create purely serverless, highly available, resilient, scalable, and real-time APIs.
GraphQL offers more flexibility than RESTful APIs. This flexibility in usage has made developers more inclined toward its usage. AWS facilitates developers by providing AWS AppSync, which allows them to create serverless GraphQL APIs. GraphQL allows us to configure the schemas, resolvers, and data sources in simple steps and thus launch a GraphQL API in a few minutes.
AppSync allows us to create a new DynamoDB table when defining schemas and attach the existing data sources such as DynamoDB table, RDS, and custom data sources through the Lambda function. It also offers custom Lambda resolvers. This means that instead of connecting directly to the data source, we can connect through a Lambda function.
Example: E-commerce application
Let us understand it through a use case example. Suppose we want to design a serverless e-commerce application that allows us to view products, place an order, and make a user profile. We have data sources for product catalogs, user profiles, orders, carts, and reviews.
To store the product catalog, we’ll use the scalable DynamoDB. Similarly, we'll use a relational database, such as RDS Aurora serverless, to maintain standardized user data. Lastly, we will add payment gateways to our application through API gateway and store user reviews in an S3 bucket.
To control the shape of the data fetched, we’ll define the schema consisting of types for products, users, orders, and reviews. Also, we’ll add queries to fetch the data and mutations to add, update, and delete the products, users, and orders.
Finally, we’ll define resolvers for each GraphQL operation. The illustration given below depicts the complete infrastructure of the application.
Now consider a use case where we want to display the order summary before prompting the user for confirmation. On the summary page, we need selected product details from the product catalog and the contact details of the user from the RDS database. A RESTful CRUD application would typically send multiple requests; however, through GraphQL API, we can define a schema that fetches us the decider data and returns a customized JSON payload. Also, when we place the order, we can add a subscription to the POST order part to notify the admin about the new order.
Get hands-on with 1300+ tech skills courses.