GraphQL query string filters like "StartsWith" or "Contains"

I have generated GraphQL queries on realm app based on the schema. Generated GraphQL query has multiple filter options like _exists, _in, _gt, _lt, _nin, _gte etc.

I’m looking to fetch all the records where name starts with “xyz” or string contains any given word. Can anyone suggest how to apply such filters?

Hi Vivek – For this case we would recommend creating a custom resolver that leverages MongoDB’s Text Search.

1 Like

thanks for the response Drew,

I would imagine taking the custom resolver route for any specialized functionality where I have the freedom to implement the behaviour I want. However regex pattern matching on string fields should be part of auto-generated filters.

Do you think it could be implemented as generic feature at some point in future? or, are there any risks etc in adding it to default auto-generated filters like lack of indexes?

Hi Vivek – We’re definitely considering adding a Regex pattern to our defaults but don’t have a timeline for when this would be added. This is slightly complicated by the fact that $search is becoming the recommendation for use cases like this but requires additional set-up on the cluster.

1 Like

I am using the graphQL custom resolvers, and while they will do what you want, you are now operating outside the autogenerated types. For instance, you cannot combine things like in, greater than, less than with the custom resolvers because you have to rewrite all that.

A better solution would be to add custom Query Inputs. I get that $search is recommended from the database perspective, but I already have to look at the pros and cons of searching. I just want to extend the GraphQL schema a bit more than just a custom resolver.

3 Likes

+1. It’s frustrating to have to choose between all the generated options that map to find automatically (lt, gt, etc) and a custom resolver to implement missing features like pagination or search.

2 Likes