Building Serverless Applications with Amplify,VueJs/NuxtJs, and GraphQL(Part 1)

I love creating and writing about the creation of software.
Search for a command to run...

I love creating and writing about the creation of software.
No comments yet. Be the first to comment.
In this post series, we will be covering how to build a beautiful web applications on the amplify framework offered by AWS using GraphQL, Vue/Nuxt and Appsync
Introduction In Part 1 of this article, we looked at the use cases and data access patterns for our application. We also looked at the GraphQL schema and explained line by line, why it was written that way. In this second part, we will start build...
Watch the complete Video on Youtube https://www.youtube.com/watch?v=kKX-8L_R2XM Prerequisites Before proceeding make sure you have these dependencies Docker Python 3.11 and above AWS CLI Full access to a foundation model. For this workshop, we'll...

Introduction In a previous workshop, Building event-driven applications with AWS sam and python we built an e-commerce ordering service using AWS SAM, API Gateway, Lambda and Python. Here's the solutions architecture. In that workshop, whenever a ne...

Github Repository https://github.com/EducloudHQ/introduction_to_gen_ai Skill up with serverless on Educloud https://www.educloud.academy/content/da99ad07-7efa-41e7-ba50-b18e6b89e10d This post is an introductory lesson to building AI-enhanced serverle...

Introduction Serverless computing is a cloud-based approach to application development that eliminates the need for provisioning and managing servers. Instead, developers focus on writing code that is triggered by events such as HTTP requests or data...

https://github.com/trey-rosius/sam_stepfunctions Hey!!! How you doing? In this post, we’ll look at how to build a workflow, using SAM as IaC, Appsync, and python. Prerequisites Install AWS Cli (https://docs.aws.amazon.com/cli/latest/userguide/cli-c...

It's without a doubt that AWS Amplify is becoming the favorite framework for building full-stack serverless mobile and web applications.
With Amplify, you can configure app backends and connect your app in minutes, deploy static web apps in a few clicks, and easily manage app content outside the AWS console. And they are in heavy support of graphQL as the main query language for your APIs.
In this post series, we'll be building a beautiful graphQL driven serverless web app using vue, AWS Amplify, and AWS Appsync.

The GraphQL Transform provides a simple to use abstraction that helps you quickly create backends for your web and mobile applications on AWS. With the GraphQL Transform, you define your application’s data model using the GraphQL Schema Definition Language (SDL) and the library handles converting your SDL definition into a set of fully descriptive AWS CloudFormation templates that implement your data model.
So based on the access patterns above, here's how the backend for your application would be.
type User @model
@key(name:"byEmail",fields:["email"],queryField:"getUserByEmail")
@auth(rules:[
{ allow: owner },
{ allow: private, operations: [read] }
]) {
id: ID!
username: String!
email:String!
profilePicUrl:String!
posts: [Post] @connection
}
type Post @model
@auth(rules:[
{ allow: owner },
{ allow: private, operations: [read] }
])
{
id: ID!
userID:ID!
postText: String!
postImageUrl:String!
status:Status!
user: User @connection(fields:["userID"])
comments: [Comment] @connection
}
type Comment @model
@auth(rules:[
{ allow: owner },
{ allow: private, operations: [read] }
]) {
id: ID!
commentText: String!
postID:ID!
userID:ID!
post: Post @connection(fields:["postID"])
user:User @connection(fields:["userID"])
}
enum Status {
CREATED
UPDATED
DELETED
}
The GraphQL Transform simplifies the process of developing, deploying, and maintaining GraphQL APIs. With it, you define your API using the GraphQL Schema Definition Language (SDL) and can then use automation to transform it into a fully descriptive cloudformation template that implements the spec.
Let's move through the above schema line by line.
type User @model
@model is a directive, which defines top level object types in your API that are backed by Amazon DynamoDB. So, every type annotated with @model is a DynamoDB table
Therefore, our application would have 3 tables.
@key(name:"byEmail",fields:["email"],queryField:"getUserByEmail")
@key is a directive used for creating custom indexes in your application. It has 3 arguments.
@auth(rules:[
{ allow: owner },
{ allow: private, operations: [read] }
])
@auth is a directive for providing authorization to your API. Authorization is required for applications to interact with your GraphQL API. Object types that are annotated with @auth are protected by a set of authorization rules giving you additional controls.
The above snippet gives Create, Read, Update and Delete access to the owner of the data and then gives only Read access to an authenticated user.
id: ID!
username: String!
email:String!
profilePicUrl:String!
The above code defines the attribute and their respective types for our application. Bear in mind that these attributes act as fields in the DynamoDB table.
The ! at the end of the attribute types marks it as non-nullable. So the field can't be omitted when a mutation occurs.
posts: [Post] @connection
The @connection directive enables you to specify relationships between @model types. Currently, this supports one-to-one, one-to-many, and many-to-one relationships. You may implement many-to-many relationships using two one-to-many connections and a joining @model.
The user and post entity share a one-to-many relationship. So we have to add a post attribute in the user entity which takes a list of posts [Post].
post:[Post]
These last 2 lines in the Post model creates the relationship between a user and post entity.
user: User @connection(fields:["userID"])
comments: [Comment] @connection
@connection(fields:["userID"]) indicates that, the userId field should be queried to get the User Object for that post. @connection on the comments field only creates the relationship between the comment and the post entity
The rest of the schema simply repeats what we've already looked at.
We'll start building the application in Part 2 Thanks a lot for checking this out, any feedback would be greatly appreciated. I do a lot of writing about serverless and DynamoDB. Building Modern Serverless API's with AWS: DynamoDB, Lambda, and API Gateway
Stay safe✌🏿