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

TypeORM - Simple-array doesn't work #224

Closed
benjaminfrancois opened this issue Feb 12, 2024 · 6 comments
Closed

TypeORM - Simple-array doesn't work #224

benjaminfrancois opened this issue Feb 12, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@benjaminfrancois
Copy link

benjaminfrancois commented Feb 12, 2024

Hello,

I want to use FilterableField with a simple-array (typeorm), exemple :

  @FilterableField(() => [RolesEnum])
  @Column({
    type: 'simple-array',
    enum: RolesEnum,
    name: 'roles',
    default: [RolesEnum.CUSTOMER],
  })
  roles: RolesEnum[];

But i have this error :
Error: Unable to create filter comparison for [{"DEVELOPER":"DEVELOPER","ADMIN":"ADMIN","CUSTOMER":"CUSTOMER"}].

Same error when changing from [RolesEnum] to [String]

If you have a solution for me, I'm interested, thank you!

Thank's !

PS : Is it possible to create a typeorm querybuilder to customize the query as I see fit?
I want to use postgis SQL statements

@benjaminfrancois benjaminfrancois added the bug Something isn't working label Feb 12, 2024
@TriPSs
Copy link
Owner

TriPSs commented Feb 13, 2024

Interesting, I have the feeling it is because everything "array" is seen as a relation and @FilterableField does not handle that, could you add this case to an example (basic for example)? Than I can check it out.

@benjaminfrancois
Copy link
Author

benjaminfrancois commented Feb 14, 2024

Thank you for your responsiveness and for explaining it to me. It's a project with users who can have multiple roles in the app: artisan, client, admin, etc. So, I use the role to handle this, and I put it in an array to simplify the app and easily include it in the JWT.

When I want to retrieve a list of users, I use

  @Query(() => UserConnection, {
    nullable: true,
    description: `Liste des artisans`,
  })
  getArtisans(
    @Args() query: UserQuery
  ): Promise<ConnectionType<User>> {
    return this.usersService.indexArtisans(query);
  }
  async indexArtisans(data: UserQuery) {
    return UserConnection.createFromPromise(
      (q) => this.usersQueryService.query(q),
      { ...data, ...{ filter: data.filter } },
      (filter) => this.usersQueryService.count(filter)
    );
  }

But I encounter the aforementioned error.

I would have liked to use a query builder and be able to utilize your GraphQL return because it's very convenient, but I couldn't retrieve a query builder with your library, or at least I couldn't find one. 😬

@TriPSs
Copy link
Owner

TriPSs commented Feb 14, 2024

Just now see this part:

PS : Is it possible to create a typeorm querybuilder to customize the query as I see fit?
I want to use postgis SQL statements

Yes this is possible, when you create your own service you can pass FilterQueryBuilder inside the constructor opts, you could create your own that extends the default and overwrite the things you want.

@benjaminfrancois
Copy link
Author

Can you give me an example ?

@TriPSs
Copy link
Owner

TriPSs commented Feb 14, 2024

Here are some docs on how to create a custom service, in the constructor:

super(repo, {
      filterQueryBuilder: CustomFilterQueryBuilder
})

@TriPSs
Copy link
Owner

TriPSs commented May 4, 2024

Closing as it's (I think?) the same as #233

@TriPSs TriPSs closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants