Skip to content

Filtering with IN, ANY operators #334

Closed
@santhidhanuskodi23

Description

@santhidhanuskodi23

Hi,

I want to filter the data with multiple values with some operators or methods.
How Can I filter?
I tried the below one...but it throws error. Need a better documentation on filter, sorting etc with some sample queries.
query {
products(filter: "mediaCode.any[1,2,3]") {
items {
clientCode
mediaCode
}
}
}

Activity

lukemurray

lukemurray commented on Dec 11, 2023

@lukemurray
Collaborator

The syntax is for calling a method is with braces () - so it should be mediaCode.any([1,2,3]).

Having said that, the array style may not be supported currently. I will update https://entitygraphql.github.io/docs/field-extensions/filtering with examples of each call and fix any issues found along the way.

santhidhanuskodi23

santhidhanuskodi23 commented on Dec 11, 2023

@santhidhanuskodi23
Author

Could you please give exact query?

I tried
query {
products(mediaCode.any([1,2,3])) {
items {
clientCode
mediaCode
}
}
}

lukemurray

lukemurray commented on Dec 11, 2023

@lukemurray
Collaborator

As I thought above, this is currently not possible. Currently the any method works like the Enumerable.Any LINQ method. E.g.

{
  people(filter: "actorIn.any(name == \"Star Wars\")") { ... }
}

Basically translates into C#

people.Where(p => p.ActorIn.Any(a => a.Name == "Star Wars"))

I will look at adding support for above and update the docs too.

lukemurray

lukemurray commented on Dec 17, 2023

@lukemurray
Collaborator

I know it is longer but you can (assuming mediaCode is just an int) write this

products(filter: "mediaCode == 1 || mediaCode= 2 || mediaCode == 3")

added this to the 5.3 milestone on Apr 7, 2024
removed this from the 5.3 milestone on May 7, 2024
added a commit that references this issue on May 13, 2024

#334 - add `isAny([])` method to the filter expression language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Filtering with IN, ANY operators · Issue #334 · EntityGraphQL/EntityGraphQL