Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to filter dataloader query #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ccatterina
Copy link

Hi,
I've added a new decorator calledFilteredTypeormLoader which works exactly as TypeormLoader but it applies a custom function to the query builder.

I've implemented this functionality in order to apply some authorization filters on the query created by the TypeormLoader.

Example

@Entity()
@ObjectType()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  @Field()
  id: number;

  @ManyToMany(() => Customer, (customer) => customer.users)
  @JoinTable()
  @Field((_type) => [Customer])
  @FilteredTypeormLoader((qb, context) => {
    if (!context.currentUser.isAdmin) {
      qb.andWhere(...)
    }
  })
  customers: Promise<Customer[]>;

  ...
}

I can add some tests and an usage example if you want to include this functionality to the package, otherwise feel free to close the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant