Finding a blog post with Query with ReactJS
In this section, we will be finding blog posts that the user created with Query. Query helps us look up specific records in the database with GraphQL. Let's get started:
- Let's open the
schema.graphql
file again and add the following code to it. We will add the@key
directive field, calledtitle
, as the primary key and index of the DynamoDB table, calledPost
. This means that the user can find the post that they want by using a case-sensitive keyword from the title:type Post @model @key(fields: ["title"]) { Â Â id: ID! Â Â title: String! Â Â content: String! }
Call the
amplify push
command in your Terminal to update the GraphQL backend on the cloud. Once it's updated, open theApp.jsx
file. - Add the following
findPosts
method below thedeletePost
method and above thereturn
section of the code block. This method will list all the posts with a title that contains the keyword that was...