Filtering queries by relationships
See original GitHub issue** Which Category is your question related to? ** API
** What AWS Services are you utilizing? ** Auth/API
** Provide additional details e.g. code snippets **
I’m building a project management app. I have a top level type known as a Company:
type Company @model @auth(rules: [ { allow: groups, groups: ["SUPERUSER", "ADMIN"], queries: [get, list], mutations: [create, update, delete] }, { allow: groups, groups: ["MANAGER, CONTRACTOR, CONSULTANT"], queries: [get], mutations: null } ] ) { id: ID! title: String! projects: [Project] @connection(name: "CompanyProjects") }
It contains a list of projects, another type:
type Project @model @auth(rules: [ { allow: owner }, { allow: groups, groups: ["SUPERUSER", "ADMIN", "MANAGER"], queries: [get, list], mutations: [create, update] }, { allow: groups, groups: ["CONTRACTOR", "CONSULTANT"], queries: [get, list], mutations: [update] }, ] ) { id: ID! company: Company! @connection(name: "CompanyProjects") createdOn: String! title: String! status: CompletionStatus! description: String documents: [Document] @connection(name: "ProjectDocuments") }
How do I properly use filtering during a query such as listProjects in order to make sure the current user only gets projects related to the company they are a part of?
PS sorry for the code formatting, not sure how to properly do it.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:12

Top Related StackOverflow Question
I’d also like to know how to filter a query by entity. It seems that Amplify completely ignores the entites and their relation IDs when generating the FilterInput.
In fact, Amplify seems to completely ignore the relation ID everywhere when generating the GraphQL schema; even if you define the entity’s type containing the relation field (e.g.
projectCompanyId: ID!), it simply doesn’t output that field, i.e. neither in the entity’s type (e.g.Project) nor in its filters.@MagneH This appears to completely defeat the purpose of having a linked @Connection in the first place. The company in Type Projects @model in my instance… will be null, no matter how many Projects I add, they won’t be placed into Company under projects, the @connection to Company, doesn’t actually exist, so adding a CompanyId: to make it filterable, is basically ignoring the fact that @connections are entirely 100% broken? None of this makes any sense.
[Project] denotes that it’s an array of multiple projects, so I assume that something will exist there when I add them as you would assume to add them… i.e. Add a Company, Add a Project, with a Company ID as ‘ProjectCompany’ … kinda works but doesn’t.