From 29693b762c9cdd20e3268ea8478e73e4f3bd8602 Mon Sep 17 00:00:00 2001 From: "Yashesh Chauhan(yashesh.chauhan)" Date: Thu, 24 Dec 2020 16:05:49 +0530 Subject: [PATCH 1/2] allow regex comparison operator. Included test cases. --- .../kotlin/org/neo4j/graphql/Predicates.kt | 4 +- .../kotlin/org/neo4j/graphql/ParserTests.kt | 12 ++-- .../test/resources/augmentation-tests.adoc | 12 ++++ core/src/test/resources/filter-tests.adoc | 67 +++++++++++++++++++ .../resources/schema-operations-tests.adoc | 4 ++ 5 files changed, 92 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt b/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt index c991baec..43bcd7bc 100644 --- a/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt +++ b/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt @@ -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) }), + DISTANCE(NEO4j_POINT_DISTANCE_FILTER_SUFFIX, "=", { lhs, rhs -> distanceOp(lhs, rhs, EQ) }, distance = true), DISTANCE_LT(NEO4j_POINT_DISTANCE_FILTER_SUFFIX + "_lt", "<", { lhs, rhs -> distanceOp(lhs, rhs, LT) }, distance = true), @@ -282,7 +284,7 @@ enum class FieldOperator( // todo list types !type.isScalar() -> listOf(EQ, NEQ, IN, NIN) else -> listOf(EQ, NEQ, IN, NIN, LT, LTE, GT, GTE) + - if (type.name() == "String" || type.name() == "ID") listOf(C, NC, SW, NSW, EW, NEW) else emptyList() + if (type.name() == "String" || type.name() == "ID") listOf(C, NC, SW, NSW, EW, NEW, MA) else emptyList() } } diff --git a/core/src/test/kotlin/org/neo4j/graphql/ParserTests.kt b/core/src/test/kotlin/org/neo4j/graphql/ParserTests.kt index 54766d32..7777d863 100644 --- a/core/src/test/kotlin/org/neo4j/graphql/ParserTests.kt +++ b/core/src/test/kotlin/org/neo4j/graphql/ParserTests.kt @@ -20,7 +20,7 @@ class ParserTests { fun parseFilter() { val schemaParser = SchemaParser() val schema = """ - input _MovieFilter { AND:[_MovieFilter!], OR:[_MovieFilter!], NOT:[_MovieFilter!], movieId:ID, movieId_not:ID, movieId_in:ID, movieId_not_in:ID, movieId_lt:ID, movieId_lte:ID, movieId_gt:ID, movieId_gte:ID, movieId_contains:ID, movieId_not_contains:ID, movieId_starts_with:ID, movieId_not_starts_with:ID, movieId_ends_with:ID, movieId_not_ends_with:ID, _id:String, _id_not:String, _id_in:String, _id_not_in:String, _id_lt:String, _id_lte:String, _id_gt:String, _id_gte:String, _id_contains:String, _id_not_contains:String, _id_starts_with:String, _id_not_starts_with:String, _id_ends_with:String, _id_not_ends_with:String, title:String, title_not:String, title_in:String, title_not_in:String, title_lt:String, title_lte:String, title_gt:String, title_gte:String, title_contains:String, title_not_contains:String, title_starts_with:String, title_not_starts_with:String, title_ends_with:String, title_not_ends_with:String, year:Int, year_not:Int, year_in:Int, year_not_in:Int, year_lt:Int, year_lte:Int, year_gt:Int, year_gte:Int, released:Int, released_not:Int, released_in:Int, released_not_in:Int, released_lt:Int, released_lte:Int, released_gt:Int, released_gte:Int, plot:String, plot_not:String, plot_in:String, plot_not_in:String, plot_lt:String, plot_lte:String, plot_gt:String, plot_gte:String, plot_contains:String, plot_not_contains:String, plot_starts_with:String, plot_not_starts_with:String, plot_ends_with:String, plot_not_ends_with:String, poster:String, poster_not:String, poster_in:String, poster_not_in:String, poster_lt:String, poster_lte:String, poster_gt:String, poster_gte:String, poster_contains:String, poster_not_contains:String, poster_starts_with:String, poster_not_starts_with:String, poster_ends_with:String, poster_not_ends_with:String, imdbRating:Float, imdbRating_not:Float, imdbRating_in:Float, imdbRating_not_in:Float, imdbRating_lt:Float, imdbRating_lte:Float, imdbRating_gt:Float, imdbRating_gte:Float, degree:Int, degree_not:Int, degree_in:Int, degree_not_in:Int, degree_lt:Int, degree_lte:Int, degree_gt:Int, degree_gte:Int, avgStars:Float, avgStars_not:Float, avgStars_in:Float, avgStars_not_in:Float, avgStars_lt:Float, avgStars_lte:Float, avgStars_gt:Float, avgStars_gte:Float, scaleRating:Float, scaleRating_not:Float, scaleRating_in:Float, scaleRating_not_in:Float, scaleRating_lt:Float, scaleRating_lte:Float, scaleRating_gt:Float, scaleRating_gte:Float, scaleRatingFloat:Float, scaleRatingFloat_not:Float, scaleRatingFloat_in:Float, scaleRatingFloat_not_in:Float, scaleRatingFloat_lt:Float, scaleRatingFloat_lte:Float, scaleRatingFloat_gt:Float, scaleRatingFloat_gte:Float } """.trimIndent() + input _MovieFilter { AND:[_MovieFilter!], OR:[_MovieFilter!], NOT:[_MovieFilter!], movieId:ID, movieId_not:ID, movieId_in:ID, movieId_not_in:ID, movieId_lt:ID, movieId_lte:ID, movieId_gt:ID, movieId_gte:ID, movieId_contains:ID, movieId_matches:ID, movieId_not_contains:ID, movieId_starts_with:ID, movieId_not_starts_with:ID, movieId_ends_with:ID, movieId_not_ends_with:ID, _id:String, _id_not:String, _id_in:String, _id_not_in:String, _id_lt:String, _id_lte:String, _id_gt:String, _id_gte:String, _id_contains:String, _id_matches:String, _id_not_contains:String, _id_starts_with:String, _id_not_starts_with:String, _id_ends_with:String, _id_not_ends_with:String, title:String, title_not:String, title_in:String, title_not_in:String, title_lt:String, title_lte:String, title_gt:String, title_gte:String, title_contains:String, title_matches:String, title_not_contains:String, title_starts_with:String, title_not_starts_with:String, title_ends_with:String, title_not_ends_with:String, year:Int, year_not:Int, year_in:Int, year_not_in:Int, year_lt:Int, year_lte:Int, year_gt:Int, year_gte:Int, released:Int, released_not:Int, released_in:Int, released_not_in:Int, released_lt:Int, released_lte:Int, released_gt:Int, released_gte:Int, plot:String, plot_not:String, plot_in:String, plot_not_in:String, plot_lt:String, plot_lte:String, plot_gt:String, plot_gte:String, plot_contains:String, plot_matches:String, plot_not_contains:String, plot_starts_with:String, plot_not_starts_with:String, plot_ends_with:String, plot_not_ends_with:String, poster:String, poster_not:String, poster_in:String, poster_not_in:String, poster_lt:String, poster_lte:String, poster_gt:String, poster_gte:String, poster_contains:String, poster_matches:String, poster_not_contains:String, poster_starts_with:String, poster_not_starts_with:String, poster_ends_with:String, poster_not_ends_with:String, imdbRating:Float, imdbRating_not:Float, imdbRating_in:Float, imdbRating_not_in:Float, imdbRating_lt:Float, imdbRating_lte:Float, imdbRating_gt:Float, imdbRating_gte:Float, degree:Int, degree_not:Int, degree_in:Int, degree_not_in:Int, degree_lt:Int, degree_lte:Int, degree_gt:Int, degree_gte:Int, avgStars:Float, avgStars_not:Float, avgStars_in:Float, avgStars_not_in:Float, avgStars_lt:Float, avgStars_lte:Float, avgStars_gt:Float, avgStars_gte:Float, scaleRating:Float, scaleRating_not:Float, scaleRating_in:Float, scaleRating_not_in:Float, scaleRating_lt:Float, scaleRating_lte:Float, scaleRating_gt:Float, scaleRating_gte:Float, scaleRatingFloat:Float, scaleRatingFloat_not:Float, scaleRatingFloat_in:Float, scaleRatingFloat_not_in:Float, scaleRatingFloat_lt:Float, scaleRatingFloat_lte:Float, scaleRatingFloat_gt:Float, scaleRatingFloat_gte:Float } """.trimIndent() val typeDefinitionRegistry = schemaParser.parse(schema) assertEquals(true, typeDefinitionRegistry.getType("_MovieFilter").isPresent) @@ -30,19 +30,19 @@ class ParserTests { fun parseFilter2() { val schemaParser = SchemaParser() val schema = """ -input _MovieFilter { AND:[_MovieFilter!], OR:[_MovieFilter!], NOT:[_MovieFilter!], movieId:ID, movieId_not:ID, movieId_in:ID, movieId_not_in:ID, movieId_lt:ID, movieId_lte:ID, movieId_gt:ID, movieId_gte:ID, movieId_contains:ID, movieId_not_contains:ID, movieId_starts_with:ID, movieId_not_starts_with:ID, movieId_ends_with:ID, movieId_not_ends_with:ID, _id:String, _id_not:String, _id_in:String, _id_not_in:String, _id_lt:String, _id_lte:String, _id_gt:String, _id_gte:String, _id_contains:String, _id_not_contains:String, _id_starts_with:String, _id_not_starts_with:String, _id_ends_with:String, _id_not_ends_with:String, title:String, title_not:String, title_in:String, title_not_in:String, title_lt:String, title_lte:String, title_gt:String, title_gte:String, title_contains:String, title_not_contains:String, title_starts_with:String, title_not_starts_with:String, title_ends_with:String, title_not_ends_with:String, year:Int, year_not:Int, year_in:Int, year_not_in:Int, year_lt:Int, year_lte:Int, year_gt:Int, year_gte:Int, released:Int, released_not:Int, released_in:Int, released_not_in:Int, released_lt:Int, released_lte:Int, released_gt:Int, released_gte:Int, plot:String, plot_not:String, plot_in:String, plot_not_in:String, plot_lt:String, plot_lte:String, plot_gt:String, plot_gte:String, plot_contains:String, plot_not_contains:String, plot_starts_with:String, plot_not_starts_with:String, plot_ends_with:String, plot_not_ends_with:String, poster:String, poster_not:String, poster_in:String, poster_not_in:String, poster_lt:String, poster_lte:String, poster_gt:String, poster_gte:String, poster_contains:String, poster_not_contains:String, poster_starts_with:String, poster_not_starts_with:String, poster_ends_with:String, poster_not_ends_with:String, imdbRating:Float, imdbRating_not:Float, imdbRating_in:Float, imdbRating_not_in:Float, imdbRating_lt:Float, imdbRating_lte:Float, imdbRating_gt:Float, imdbRating_gte:Float, degree:Int, degree_not:Int, degree_in:Int, degree_not_in:Int, degree_lt:Int, degree_lte:Int, degree_gt:Int, degree_gte:Int, avgStars:Float, avgStars_not:Float, avgStars_in:Float, avgStars_not_in:Float, avgStars_lt:Float, avgStars_lte:Float, avgStars_gt:Float, avgStars_gte:Float, scaleRating:Float, scaleRating_not:Float, scaleRating_in:Float, scaleRating_not_in:Float, scaleRating_lt:Float, scaleRating_lte:Float, scaleRating_gt:Float, scaleRating_gte:Float, scaleRatingFloat:Float, scaleRatingFloat_not:Float, scaleRatingFloat_in:Float, scaleRatingFloat_not_in:Float, scaleRatingFloat_lt:Float, scaleRatingFloat_lte:Float, scaleRatingFloat_gt:Float, scaleRatingFloat_gte:Float } +input _MovieFilter { AND:[_MovieFilter!], OR:[_MovieFilter!], NOT:[_MovieFilter!], movieId:ID, movieId_not:ID, movieId_in:ID, movieId_not_in:ID, movieId_lt:ID, movieId_lte:ID, movieId_gt:ID, movieId_gte:ID, movieId_contains:ID,movieId_matches:ID, movieId_not_contains:ID, movieId_starts_with:ID, movieId_not_starts_with:ID, movieId_ends_with:ID, movieId_not_ends_with:ID, _id:String, _id_not:String, _id_in:String, _id_not_in:String, _id_lt:String, _id_lte:String, _id_gt:String, _id_gte:String, _id_contains:String, _id_matches:String, _id_not_contains:String, _id_starts_with:String, _id_not_starts_with:String, _id_ends_with:String, _id_not_ends_with:String, title:String, title_not:String, title_in:String, title_not_in:String, title_lt:String, title_lte:String, title_gt:String, title_gte:String, title_contains:String, title_matches:String, title_not_contains:String, title_starts_with:String, title_not_starts_with:String, title_ends_with:String, title_not_ends_with:String, year:Int, year_not:Int, year_in:Int, year_not_in:Int, year_lt:Int, year_lte:Int, year_gt:Int, year_gte:Int, released:Int, released_not:Int, released_in:Int, released_not_in:Int, released_lt:Int, released_lte:Int, released_gt:Int, released_gte:Int, plot:String, plot_not:String, plot_in:String, plot_not_in:String, plot_lt:String, plot_lte:String, plot_gt:String, plot_gte:String, plot_contains:String, plot_matches:String, plot_not_contains:String, plot_starts_with:String, plot_not_starts_with:String, plot_ends_with:String, plot_not_ends_with:String, poster:String, poster_not:String, poster_in:String, poster_not_in:String, poster_lt:String, poster_lte:String, poster_gt:String, poster_gte:String, poster_contains:String, poster_matches:String, poster_not_contains:String, poster_starts_with:String, poster_not_starts_with:String, poster_ends_with:String, poster_not_ends_with:String, imdbRating:Float, imdbRating_not:Float, imdbRating_in:Float, imdbRating_not_in:Float, imdbRating_lt:Float, imdbRating_lte:Float, imdbRating_gt:Float, imdbRating_gte:Float, degree:Int, degree_not:Int, degree_in:Int, degree_not_in:Int, degree_lt:Int, degree_lte:Int, degree_gt:Int, degree_gte:Int, avgStars:Float, avgStars_not:Float, avgStars_in:Float, avgStars_not_in:Float, avgStars_lt:Float, avgStars_lte:Float, avgStars_gt:Float, avgStars_gte:Float, scaleRating:Float, scaleRating_not:Float, scaleRating_in:Float, scaleRating_not_in:Float, scaleRating_lt:Float, scaleRating_lte:Float, scaleRating_gt:Float, scaleRating_gte:Float, scaleRatingFloat:Float, scaleRatingFloat_not:Float, scaleRatingFloat_in:Float, scaleRatingFloat_not_in:Float, scaleRatingFloat_lt:Float, scaleRatingFloat_lte:Float, scaleRatingFloat_gt:Float, scaleRatingFloat_gte:Float } enum _MovieOrdering { movieId_asc ,movieId_desc,_id_asc ,_id_desc,title_asc ,title_desc,year_asc ,year_desc,released_asc ,released_desc,plot_asc ,plot_desc,poster_asc ,poster_desc,imdbRating_asc ,imdbRating_desc,degree_asc ,degree_desc,avgStars_asc ,avgStars_desc,scaleRating_asc ,scaleRating_desc,scaleRatingFloat_asc ,scaleRatingFloat_desc } input _MovieInput { movieId:ID, _id:String, title:String, year:Int, released:Int, plot:String, poster:String, imdbRating:Float, degree:Int, avgStars:Float, scaleRating:Float, scaleRatingFloat:Float } -input _GenreFilter { AND:[_GenreFilter!], OR:[_GenreFilter!], NOT:[_GenreFilter!], _id:String, _id_not:String, _id_in:String, _id_not_in:String, _id_lt:String, _id_lte:String, _id_gt:String, _id_gte:String, _id_contains:String, _id_not_contains:String, _id_starts_with:String, _id_not_starts_with:String, _id_ends_with:String, _id_not_ends_with:String, name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } +input _GenreFilter { AND:[_GenreFilter!], OR:[_GenreFilter!], NOT:[_GenreFilter!], _id:String, _id_not:String, _id_in:String, _id_not_in:String, _id_lt:String, _id_lte:String, _id_gt:String, _id_gte:String, _id_contains:String, _id_matches:String, _id_not_contains:String, _id_starts_with:String, _id_not_starts_with:String, _id_ends_with:String, _id_not_ends_with:String, name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_matches:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } enum _GenreOrdering { _id_asc ,_id_desc,name_asc ,name_desc } input _GenreInput { _id:String, name:String } -input _StateFilter { AND:[_StateFilter!], OR:[_StateFilter!], NOT:[_StateFilter!], name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } +input _StateFilter { AND:[_StateFilter!], OR:[_StateFilter!], NOT:[_StateFilter!], name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_matches:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } enum _StateOrdering { name_asc ,name_desc } input _StateInput { name:String } -input _ActorFilter { AND:[_ActorFilter!], OR:[_ActorFilter!], NOT:[_ActorFilter!], userId:ID, userId_not:ID, userId_in:ID, userId_not_in:ID, userId_lt:ID, userId_lte:ID, userId_gt:ID, userId_gte:ID, userId_contains:ID, userId_not_contains:ID, userId_starts_with:ID, userId_not_starts_with:ID, userId_ends_with:ID, userId_not_ends_with:ID, name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } +input _ActorFilter { AND:[_ActorFilter!], OR:[_ActorFilter!], NOT:[_ActorFilter!], userId:ID, userId_not:ID, userId_in:ID, userId_not_in:ID, userId_lt:ID, userId_lte:ID, userId_gt:ID, userId_gte:ID, userId_contains:ID, userId_matches:ID, userId_not_contains:ID, userId_starts_with:ID, userId_not_starts_with:ID, userId_ends_with:ID, userId_not_ends_with:ID, name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_matches:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } enum _ActorOrdering { userId_asc ,userId_desc,name_asc ,name_desc } input _ActorInput { userId:ID, name:String } -input _UserFilter { AND:[_UserFilter!], OR:[_UserFilter!], NOT:[_UserFilter!], userId:ID, userId_not:ID, userId_in:ID, userId_not_in:ID, userId_lt:ID, userId_lte:ID, userId_gt:ID, userId_gte:ID, userId_contains:ID, userId_not_contains:ID, userId_starts_with:ID, userId_not_starts_with:ID, userId_ends_with:ID, userId_not_ends_with:ID, name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } +input _UserFilter { AND:[_UserFilter!], OR:[_UserFilter!], NOT:[_UserFilter!], userId:ID, userId_not:ID, userId_in:ID, userId_not_in:ID, userId_lt:ID, userId_lte:ID, userId_gt:ID, userId_gte:ID, userId_contains:ID, userId_matches:ID, userId_not_contains:ID, userId_starts_with:ID, userId_not_starts_with:ID, userId_ends_with:ID, userId_not_ends_with:ID, name:String, name_not:String, name_in:String, name_not_in:String, name_lt:String, name_lte:String, name_gt:String, name_gte:String, name_contains:String, name_matches:String, name_not_contains:String, name_starts_with:String, name_not_starts_with:String, name_ends_with:String, name_not_ends_with:String } enum _UserOrdering { userId_asc ,userId_desc,name_asc ,name_desc } input _UserInput { userId:ID, name:String } input _FriendOfFilter { AND:[_FriendOfFilter!], OR:[_FriendOfFilter!], NOT:[_FriendOfFilter!], since:Int, since_not:Int, since_in:Int, since_not_in:Int, since_lt:Int, since_lte:Int, since_gt:Int, since_gte:Int } diff --git a/core/src/test/resources/augmentation-tests.adoc b/core/src/test/resources/augmentation-tests.adoc index 50614f3a..671a49f6 100644 --- a/core/src/test/resources/augmentation-tests.adoc +++ b/core/src/test/resources/augmentation-tests.adoc @@ -655,6 +655,7 @@ input _Knows0Filter { OR: [_Knows0Filter!] id: ID id_contains: ID + id_matches: ID id_ends_with: ID id_gt: ID id_gte: ID @@ -702,6 +703,7 @@ input _Knows1Filter { OR: [_Knows1Filter!] id: ID id_contains: ID + id_matches: ID id_ends_with: ID id_gt: ID id_gte: ID @@ -748,6 +750,7 @@ input _Knows4Filter { OR: [_Knows4Filter!] _id: ID _id_contains: ID + _id_matches: ID _id_ends_with: ID _id_gt: ID _id_gte: ID @@ -795,6 +798,7 @@ input _MovieFilter { OR: [_MovieFilter!] id: ID id_contains: ID + id_matches: ID id_ends_with: ID id_gt: ID id_gte: ID @@ -912,6 +916,7 @@ input _Person0Filter { location_not: _Neo4jPointInput name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -936,6 +941,7 @@ input _Person1Filter { born_not_in: [_Neo4jDateInput] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -973,6 +979,7 @@ input _Person2Filter { born_not_in: [_Neo4jDateTimeInput] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -1003,6 +1010,7 @@ input _Person3Filter { born_not_in: [_Neo4jLocalTimeInput] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -1032,6 +1040,7 @@ input _Person4Filter { born_not_in: [_Neo4jLocalDateTimeInput] id: ID id_contains: ID + id_matches: ID id_ends_with: ID id_gt: ID id_gte: ID @@ -1046,6 +1055,7 @@ input _Person4Filter { id_starts_with: ID name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -1072,6 +1082,7 @@ input _Person5Filter { OR: [_Person5Filter!] id: ID id_contains: ID + id_matches: ID id_ends_with: ID id_gt: ID id_gte: ID @@ -1108,6 +1119,7 @@ input _PublisherFilter { OR: [_PublisherFilter!] name: ID name_contains: ID + name_matches: ID name_ends_with: ID name_gt: ID name_gte: ID diff --git a/core/src/test/resources/filter-tests.adoc b/core/src/test/resources/filter-tests.adoc index d0e19813..75507af6 100644 --- a/core/src/test/resources/filter-tests.adoc +++ b/core/src/test/resources/filter-tests.adoc @@ -382,6 +382,40 @@ WHERE NOT person.id ENDS WITH $filterPersonId_NEW RETURN person { .name } AS person ---- +=== Filter id _matches_ + +.GraphQL-Query +[source,graphql] +---- +{ person(filter: { id_matches:"ja.*" }) { name }} +---- + +.GraphQL-Response +[source,json,response=true] +---- +{ + "person" : [ { + "name" : "Jane" + } ] +} +---- + +.Cypher Params +[source,json] +---- + { + "filterPersonId_MA": "ja.*" + } +---- + +.Cypher +[source,cypher] +---- +MATCH (person:Person) +WHERE person.id =~ $filterPersonId_MA +RETURN person { .name } AS person +---- + === Filter id _contains_ .GraphQL-Query @@ -1352,6 +1386,39 @@ WHERE NOT person.name ENDS WITH $filterPersonName_NEW RETURN person { .name } AS person ---- +=== Filter string _matches_ +.GraphQL-Query +[source,graphql] +---- +{ person(filter: { name_matches: "Ja.*" }) { name }} +---- + +.GraphQL-Response +[source,json,response=true] +---- +{ + "person" : [ { + "name" : "Jane" + } ] +} +---- + +.Cypher Params +[source,json] +---- +{ + "filterPersonName_MA": "Ja.*" +} +---- + +.Cypher +[source,cypher] +---- +MATCH (person:Person) +WHERE person.name =~ $filterPersonName_MA +RETURN person { .name } AS person +---- + === Filter string _contains_ .GraphQL-Query diff --git a/core/src/test/resources/schema-operations-tests.adoc b/core/src/test/resources/schema-operations-tests.adoc index c98b56d2..67f120d8 100644 --- a/core/src/test/resources/schema-operations-tests.adoc +++ b/core/src/test/resources/schema-operations-tests.adoc @@ -167,6 +167,7 @@ input _LocationFilter { OR: [_LocationFilter!] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -257,6 +258,7 @@ input _PersonFilter { OR: [_PersonFilter!] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -432,6 +434,7 @@ input _LocationFilter { OR: [_LocationFilter!] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String @@ -522,6 +525,7 @@ input _PersonFilter { OR: [_PersonFilter!] name: String name_contains: String + name_matches: String name_ends_with: String name_gt: String name_gte: String From 0e80cf466322e1779d967757541a69ba511ce07a Mon Sep 17 00:00:00 2001 From: Fataleagle Date: Wed, 24 Feb 2021 10:32:46 +0530 Subject: [PATCH 2/2] changed variable name from MA to MATCHES --- core/src/main/kotlin/org/neo4j/graphql/Predicates.kt | 4 ++-- core/src/test/resources/filter-tests.adoc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt b/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt index 43bcd7bc..734172f4 100644 --- a/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt +++ b/core/src/main/kotlin/org/neo4j/graphql/Predicates.kt @@ -205,7 +205,7 @@ 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) }), + MATCHES("_matches", "=~", {lhs, rhs -> lhs.matches(rhs) }), DISTANCE(NEO4j_POINT_DISTANCE_FILTER_SUFFIX, "=", { lhs, rhs -> distanceOp(lhs, rhs, EQ) }, distance = true), @@ -284,7 +284,7 @@ enum class FieldOperator( // todo list types !type.isScalar() -> listOf(EQ, NEQ, IN, NIN) else -> listOf(EQ, NEQ, IN, NIN, LT, LTE, GT, GTE) + - if (type.name() == "String" || type.name() == "ID") listOf(C, NC, SW, NSW, EW, NEW, MA) else emptyList() + if (type.name() == "String" || type.name() == "ID") listOf(C, NC, SW, NSW, EW, NEW, MATCHES) else emptyList() } } diff --git a/core/src/test/resources/filter-tests.adoc b/core/src/test/resources/filter-tests.adoc index 75507af6..2f90d877 100644 --- a/core/src/test/resources/filter-tests.adoc +++ b/core/src/test/resources/filter-tests.adoc @@ -404,7 +404,7 @@ RETURN person { .name } AS person [source,json] ---- { - "filterPersonId_MA": "ja.*" + "filterPersonId_MATCHES": "ja.*" } ---- @@ -412,7 +412,7 @@ RETURN person { .name } AS person [source,cypher] ---- MATCH (person:Person) -WHERE person.id =~ $filterPersonId_MA +WHERE person.id =~ $filterPersonId_MATCHES RETURN person { .name } AS person ---- @@ -1407,7 +1407,7 @@ RETURN person { .name } AS person [source,json] ---- { - "filterPersonName_MA": "Ja.*" + "filterPersonName_MATCHES": "Ja.*" } ---- @@ -1415,7 +1415,7 @@ RETURN person { .name } AS person [source,cypher] ---- MATCH (person:Person) -WHERE person.name =~ $filterPersonName_MA +WHERE person.name =~ $filterPersonName_MATCHES RETURN person { .name } AS person ----