Skip to content

allow regex comparison operator. Included test cases. #162

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

Merged
merged 3 commits into from
Mar 2, 2021

Conversation

Yashesh123
Copy link
Contributor

Hi,

This is my first PR to this repository.

This PR will add support for regular expression based filtering. For that I have added a field operator using "matches" provided by neo4j-cypher-dsl. Which will convert to its equivalent cypher regexp operator (~=).

So for this schema:

enum Gender { female, male }
type Person {
id : ID!
name: String
age: Int
height: Float
fun: Boolean
gender: Gender
company: Company @relation(name:"WORKS_AT")
location: _Neo4jPoint
}
type Company {
_id: ID
name: String
employees: [Person] @relation(name:"WORKS_AT", direction: IN)
}
type Query {
person : [Person]
}

This graphql query example will work:

{
person(filter: { name_matches: "Ja.*" }) {
name
}
}

This can be example output:

{
"person" : [ {
"name" : "Jane"
} ]
}

This can also solves requirement for case-insensitiveness as cypher queries are already supporting it using a same (~=) regexp operator.

@@ -205,6 +205,8 @@ enum class FieldOperator(
C("_contains", "CONTAINS", { lhs, rhs -> lhs.contains(rhs) }),
SW("_starts_with", "STARTS WITH", { lhs, rhs -> lhs.startsWith(rhs) }),
EW("_ends_with", "ENDS WITH", { lhs, rhs -> lhs.endsWith(rhs) }),
MA("_matches", "=~", {lhs, rhs -> lhs.matches(rhs) }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to call it MATCHES, since its only usage is for the Cypher parameters. This would make the code more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks, @Andy2003

@Andy2003 Andy2003 self-requested a review February 24, 2021 09:42
@jexp jexp merged commit e459380 into neo4j-graphql:master Mar 2, 2021
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.

3 participants