nestjs-query icon indicating copy to clipboard operation
nestjs-query copied to clipboard

Unable to create filter comparison for [null].

Open n3x7j2 opened this issue 3 years ago • 8 comments

Describe the bug I'm using @nestjs-query/query-typegoose and when I run my app it said: Unable to create filter comparison for [null].

To Reproduce This is my dto:

@ObjectType('ApiKey')
@KeySet(['id'])
export class ApiKeyDto {
  @FilterableField(() => ID)
  id!: string;

  @FilterableField()
  name: string;

  @FilterableField({ nullable: true })
  description?: string;

  @FilterableField(() => [String], { nullable: true })
  scopes?: string[];

  @FilterableField(() => [String], { nullable: true })
  ipRestrictions?: string[];

  @FilterableField(() => [String], { nullable: true })
  referrerRestrictions?: string[];

  @FilterableField(() => GraphQLISODateTime)
  createdAt: Date;

  @FilterableField(() => GraphQLISODateTime)
  updatedAt: Date;
}

Expected behavior It's working when I use it

@FilterableField(() => [String], { nullable: true })
scopes?: string[];

Screenshots If applicable, add screenshots to help explain your problem. image

Desktop (please complete the following information):

  • Node Version 12.18.3
  • Nestjs-query Version 0.24.4

n3x7j2 avatar Mar 28 '21 06:03 n3x7j2

@doug-martin - Can you say if arrays can be filterable in general? There doesn't seem to be an example in the e2e tests and before I go digging deeper, maybe you know off-hand. I ask because if it isn't possible to have arrays filterable, then I'd say this is "as designed" and thus should be a feature request?

Scott

smolinari avatar Mar 28 '21 07:03 smolinari

I have to declare explicitly like this for it to work:

 @FilterableField(() => [String], {
    allowedComparisons: ['eq', 'neq', 'in', 'notIn'],
  })
  scopes: string[];

n3x7j2 avatar Mar 28 '21 09:03 n3x7j2

And if you add the nullable property again?

Scott

smolinari avatar Mar 28 '21 10:03 smolinari

@viennv1709 and @smolinari Arrays are not currently supported, as they could be stored in a number of different ways (JSON, Postgres Array etc).

I started work on custom operators to allow this, but it was getting too complex to keep it type safe and extensible, so I put it down for a bit. I hope to get back to it sooner than later but I can't make any promises ATM.

doug-martin avatar Mar 29 '21 00:03 doug-martin

And if you add the nullable property again?

Scott

yes

n3x7j2 avatar Mar 29 '21 03:03 n3x7j2

I can imagine how complex this could get. Thanks for the info @doug-martin.

Scott

smolinari avatar Mar 29 '21 11:03 smolinari

How to support array of embed documents?

n3x7j2 avatar Apr 05 '21 14:04 n3x7j2

I would love to have support for filtering arrays in this great lib. Can confirm, I always get likeStr.replace is not a function Error when I try to filter an array. Is there some kind of workaround for this?

zampage avatar Jun 18 '21 18:06 zampage