question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:12

github_iconTop GitHub Comments

6reactions
flisboaccommented, Mar 22, 2019

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.

4reactions
michaelcuneocommented, Apr 1, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SqlAlchemy - Filtering by Relationship Attribute - Stack Overflow
I use 'any()' function for add filter query on relationship column. class ArticleModel(db.Model, BaseModel): __tablename__ = "articles" id ...
Read more >
Filter by relationship picker - Budibase Docs
When using an external SQL datasource, such as MySQL, PostgreSQL and SQL Server, it is possible to use the Relationship Picker to filter...
Read more >
Master SQLAlchemy Relationships in a Performance Friendly ...
Filter your queries by relationship attributes. Let's use the example from above. Imagine you want to get all the Person instances that live...
Read more >
Filtering Query Results - Developer Guides - Neo4j
Just as you can filter queries based on node labels or properties, you can also filter results based on relationships or patterns.
Read more >
laravel filter query with relationship in with relationship
categories TABLE id name prodacts TABLE id title category_id orders TABLE id prodact_id I want to filter the order results by category I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found