Creating a blog post with Mutation for the ReactJS app
In this section, we will be creating a blog post with Mutation. Mutation is all about asking for specific fields in objects to create and manipulate data in GraphQL. Let's look at how to do this.
First, let's create a simple data model for a blog post. Edit the schema.graphql
file in the amplify/backend/api/api-name/
directory by using the following code:
type Post @model @key(fields: ["title"]) { Â Â id: ID! Â Â title: String! Â Â content: String! }
The id
parameter is a unique identifier that's assigned to each blog post to help us differentiate between them. If we put an exclamation mark (!
) next to the type of the parameter, this means it cannot be null; that is, it cannot be empty when it is stored in the database, which is DynamoDB in our case. DynamoDB instances, tables, and connections will be generated automatically in the next step. Both the title
and content
parameters...