AWS Amplify API/React: Filter a LIST query for Items related to a specific other item

Viewed 142

I am using AWS Amplify as the backend for my react app. My application uses Amplify Auth and API.

My project has a model called "Projects" that have a one-one relationship with another model called "Companies". Every Cognito User has a custom user attribute of 'CompanyID'.

When the user is logged in, I want to make an API.graphql request to list all projects related to the company that the Cognito User is assigned to. I am having a hard time figuring out how to filter the query so that it only returns the projects that are related to the specified company.

Is there a way to filter a ListProjects query by passing in the id of the related companies I am wanting to filter by?

1 Answers

I figured out what I needed to do. The problem was that I made the parent "Projects" when it should have been "Company". By making the parent "Company", I get a singular companyID field inside each project file. This allows me to quickly filter by projects matching the assigned ID.

Related