Amazon Web Services – Creating an AppSync GraphQL API
AppSync is an AWS service that helps you by simplifying the process of developing /building applications by letting developers create flexible, secure, extensible, and real-time APIs. It helps developers to manage and integrate mobile application data in real-time across devices and users, and at the same time allows the data to be accessed and modified when the mobile device is in an offline state.
AppSync exists in between the client apps and the AWS web services which include DynamoDB, Amazon Aurora, Lambda, Amazon Elasticsearch service, etc.
GraphQL is a language for APIs in AppSync that enables us to query and manipulate data easily through built-in and flexible syntax.
Unlike root API the GraphQL user decides what to receive rather than the server it is also fast, flexible as well as easy.
Benefits of AppSync :
1. Fast set upscale up as needed :
There are no servers to manage, AppSync provides a fully managed GraphQL setup, which has built-in high availability serverless infrastructure. You can create a GraphQL API in seconds through AWS CLI, Console, Amplify CLI, or cloud formation.
2. Simple and secure data access :
In AppSync you can perform complex queries and aggregation across multiple data sources with a single network call by using GraphQL. AppSync helps us to secure app data by using multiple simultaneous authentication modes as well as allowing us to define security and fine-grained access control at the data structure level directly from GraphQL schema.
3. Real-time subscriptions :
AppSync provides real-time subscription as well as offline access to app data. When your offline device tries to reconnect AWS appsync automatically syncs only the updates that occurred when the device was not connected instead of fetching the entire data set. AppSync manages data conflicts by offering user-customizable server-side conflict detection and resolution.
Creating an AWS AppSync GraphQL API :
- AWS account (You can apply for free tier)
- Install Node.js (version 10.x)
- Install NPM (version 6.x)
Follow the below steps to create an AWS AppSync GraphQL API:
Step 1: Go to your AWS management console and search for AppSync. Now go to Create API on the AppSync dashboard.
Step 2: Choose Build from scratch in order to build your API from scratch and define your own schema.
Step 3: Give a name to your API
Step 4: You can check your API configuration or details like API URL, API ID, Primary Auth mode, Auth Key in Settings.
Step 3: Go to Schema -> Create Resources and define your Schema according to your data. Schema is a text file written in GraphQL schema language also called Schema Definition Language(SDL).
Step 4: Define your Schema first give a custom type name and then declare fields in it.
Step 5: Your Schema with given fields and Resolvers are created. Resolvers help AWS AppSync to translate GraphQL requests and fetch information from your AWS resources.
Step 6: Your TODO Table created, will hold data in the fields that you have defined in your schema.
Step 7: Select your TODO table given above to see your TODO table, you can delete your data manually here.
Your AWS AppSync GraphQL API is successfully created and ready to be integrated with your applications