Closed homosape closed 3 years ago
Hi @irakli-g, it's not possible to use contains
on an array list, but have you looked at using the @searchable
directive? This may solve the use case you are trying to address. (Docs: https://docs.amplify.aws/cli/graphql-transformer/searchable/#usage)
Hi @danielleadams, thanks for suggestion.
I've checked it. It's a fancy feature but I am not sure how useful it can be for my case. I assume creating many to many relationship in my schema would do the trick.
It's mentioned in this tutorial starting from 20:00. I will test this case. https://www.youtube.com/watch?v=eUQvsuO6EnU&list=WL&index=4&ab_channel=EnlearAcademy
I think creating a many-to-many relationship would help too. I talked more with team members, and it looks like using contains
actually does work when querying an array in a GraphQL endpoint too.
I confirm that using many to many relationship does help to solve this problem.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels for those types of questions.
Which Category is your question related to? GraphQL queries
Amplify CLI Version 5.3.0 You can use
amplify -v
to check the amplify cli version on your systemWhat AWS Services are you utilizing? S3, DynamoDB, Cognito, AppSync, Amplify
Provide additional details e.g. code snippets This is a post entity from my graphql schema
Post contains property "favorited" which will be an array of user ids (id when you get upon registration);
Upon creation of a post "favorited" is an empty array but if someone marks a post as his/her favorite, post's "favorited" array will be updated and user's ID will be added on top of the existing list of IDs (if any);
Let's say app has 100 posts from different users and I added to my favorites only 5 posts.
If I want to only see posts that I marked as my favorite, how will I be able to query them? Can I list posts where "favorited" array contains my ID?
Is something like this possible? let filter = { favorited: { contains: "my ID" } };
await API.graphql({ query: listPosts, variables: { filter: filter}}));