top of page
Writer's picturefalhelpfrusholiba

What is AWS AppSync: A Tool that Allows You to Query Multiple Data Sources with a Single GraphQL End



A GraphQL schema is a definition of what data capabilities are available for the client application to operate on. For example, a schema might say what queries are available or how an app can subscribe to data without needing to know about the underlying data source. Schemas are defined by a type system, which an application's data model can leverage.


Another advantage is that this can work with data that is offline for periods of time. In a gaming app, for example, the developer can sync real-time data but also coordinate what happens when the end-user continues to use the game and rack up a high score when he or she is no longer connected to the Internet. AppSync can them sync the offline data once the user makes a connection again without having to sync the entire data set. This reduces bandwidth requirements and speeds up data syncing for the web or mobile application.




What is AWS AppSync




In the past, syncing all of this data for an app, and also deciding which data is mission-critical and must be real-time in nature and which data can be stored long-term and not synced, was quite an undertaking. It often requires a combination of multiple cloud services (opens in new tab) and a way to sync all of the data sources manually. Yet, AWS AppSync provides one console so that developers can understand their API and what is happening with their data.


Sensors might be installed to detect water leaks, look for intruders, and monitor whether a window has opened suddenly in the middle of the night. The Internet of Things (or IoT) (opens in new tab) is a concept that has allowed developers to create rich applications that unify and unite these disparate sensors to present a clear picture of what is happening in the home.


You only pay for what you use with AWS AppSync, with no minimum fees or required service usage. You are charged separately for query and data modification operations, as well as real-time data updates. Because you only pay for the AWS AppSync features you use, you get transparency and a low price regardless of your workload type.


The GraphQL schema defines what is possible with the API. It defines the object model, the queries, and the mutations (and in the case of AppSync, the subscriptions). This is a text document that you can copy-paste on the Schema page for the API:


The AWS Management Console provides a convenient query editor/runner on the Queries page. On the left you can define what you want to include in the query, and the generated request is shown in the middle. The right panel shows the response.


I am old in IT but new in development, and I've been spending time researching what tools and platforms to use for a social-good app I am making. I have some idea now around which Javascript framework to use, and am diving in to deployment, integration, and hosting environments. So it was a natural step to check out what AWS are doing in the mobile integration cloud space.


Searching the web and online training, it didn't take long for Amplify and AppSync to pop out. But what do they do? I will try and answer, starting with a diagram then getting into more of a breakdown.


It's a good time to mention that Amplify has a CLI option to scrub nicely whatever it built in the cloud, by rewinding the cloudformations - it's in the tutorials. At least you can run up tutorial resources knowing you can easily scrub them afterwards, on a project basis.


Before we dive into AppSync, we must first understand what GraphQL exactly is. What is this language whose beauty and power I have been incessantly ranting about for so long now? Well, GraphQL is basically a syntax that allows you to define what data you exactly need. It has three major components which include:


GraphQL is implemented between the client and the data sources, making GraphQL a single entry point to the backend. The data sources can be anything from NoSQL databases, relational databases, and HTTP servers to whatever returns data. To connect a GraphQL implementation to the data sources, you need to write resolvers.


Resolvers are a very important part of your GraphQL application, as they are the ones that translate GraphQL requests or responses to whatever the data sources understand. For example, if the data source is a relational database, the resolver will need to know how to transform a GraphQL query into a SELECT operation and then translate whatever the relational database returns into a GraphQl response.


When I was testing subscriptions, I asked myself, "what happens if I create a lambda resolver for the subscription?" So I tried and I discovered that the subscription resolver is called every time before a new subscription connection is established.


It seems like the subscription resolver is meant for authorization, because it doesn't really matter what you return as an output for the resolver. Only thing that matters is if the resolver function succeeds or fails. If it succeeds, a connection is established; if it fails, an error is sent to the frontend.


AppSync automatically create a log group with the name /aws/appsync/apis/ upon deployment withlog data set to never expire. If you want to set a different expiration period, use the logConfig.retention property.


AppSync can provide your Lambda with a set of fields selected by the client as an input argument. In the Lambda code, you can see what fields the client requested and fetch data from another source if you wish to.


The repository widdix/aws-cutting-edge-appsync contains a sample application based on AppSync, DynamoDB, and Lambda. The sample application Favorite AWS Architecture lets you vote for the services you would include in your favorite AWS architecture. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments


bottom of page