From 759360a938ca9bdd2157516ee6fe06eb35458abf Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Tue, 25 Apr 2023 15:33:06 -0500 Subject: [PATCH] remove nregex and niregex --- docs/api.md | 34 +++++------ docs/assets/demo_schema.graphql | 2 + docs/changelog.md | 3 + src/graphql.rs | 12 +--- src/transpile.rs | 2 - test/expected/resolve_graphiql_schema.out | 20 ++++++ test/expected/string_filters.out | 74 ----------------------- test/sql/string_filters.sql | 33 ---------- 8 files changed, 41 insertions(+), 139 deletions(-) diff --git a/docs/api.md b/docs/api.md index 33f88698..921d57e6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -488,8 +488,6 @@ Where the `Filter` type enumerates filterable fields and their associated ilike: String regex: String iregex: String - nregex: String - niregex: String } ``` @@ -505,23 +503,21 @@ Where the `
Filter` type enumerates filterable fields and their associated The following list shows the operators that may be available on `Filter` types. -| Operator | Description | -| ----------- | ------------------------- | -| eq | Equal To | -| neq | Not Equal To | -| gt | Greater Than | -| gte | Greater Than Or Equal To | -| in | Contained by Value List | -| lt | Less Than | -| lte | Less Than Or Equal To | -| is | Null or Not Null | -| startsWith | `String` starts with prefix | -| like | Case Sensitive `String` Pattern Match. '%' as wildcard | -| ilike | Case Insensitive `String` Pattern Match. '%' as wildcard | -| regex | Case Sensitive `String` Regular Expression Match | -| iregex | Case Insensitive `String` Regular Expression Match | -| nregex | Case Sensitive `String` Regular Expression Negative Match | -| niregex | Case Insensitive `String` Regular Expression Negative Match | +| Operator | Description | +| ----------- | -------------------------------------------------| +| eq | Equal To | +| neq | Not Equal To | +| gt | Greater Than | +| gte | Greater Than Or Equal To | +| in | Contained by Value List | +| lt | Less Than | +| lte | Less Than Or Equal To | +| is | Null or Not Null | +| startsWith | Starts with prefix | +| like | Pattern Match. '%' as wildcard | +| ilike | Pattern Match. '%' as wildcard. Case Insensitive | +| regex | POSIX Regular Expression Match | +| iregex | POSIX Regular Expression Match. Case Insensitive | Not all operators are available on every `Filter` type. For example, `UUIDFilter` only supports `eq` and `neq` because `UUID`s are not ordered. diff --git a/docs/assets/demo_schema.graphql b/docs/assets/demo_schema.graphql index 35337a76..9c2aed08 100644 --- a/docs/assets/demo_schema.graphql +++ b/docs/assets/demo_schema.graphql @@ -609,6 +609,8 @@ input StringFilter { startsWith: String like: String ilike: String + regex: String + iregex: String } scalar Time diff --git a/docs/changelog.md b/docs/changelog.md index e2006acc..638eee89 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -21,3 +21,6 @@ - bugfix: Unknown types are represented in GraphQL schema as `Opaque` rather than `String` - bugfix: PostgreSQL type modifiers, e.g. char(n), no longer truncate excess text - bugfix: Creating a new enum variant between existing variants no longer errors + +## master +- feature: `String` type filters support `regex`, `iregex` diff --git a/src/graphql.rs b/src/graphql.rs index ea4acb8d..5b5ea189 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -3013,8 +3013,6 @@ pub enum FilterOp { ILike, RegEx, IRegEx, - NotRegEx, - NotIRegEx } impl ToString for FilterOp { @@ -3034,8 +3032,6 @@ impl ToString for FilterOp { Self::ILike => "ilike", Self::RegEx => "regex", Self::IRegEx => "iregex", - Self::NotRegEx => "nregex", - Self::NotIRegEx => "niregex", } .to_string() } @@ -3060,8 +3056,6 @@ impl FromStr for FilterOp { "ilike" => Ok(Self::ILike), "regex" => Ok(Self::RegEx), "iregex" => Ok(Self::IRegEx), - "nregex" => Ok(Self::NotRegEx), - "niregex" => Ok(Self::NotIRegEx), _ => Err("Invalid filter operation".to_string()), } } @@ -3147,8 +3141,6 @@ impl ___Type for FilterTypeType { FilterOp::ILike, FilterOp::RegEx, FilterOp::IRegEx, - FilterOp::NotRegEx, - FilterOp::NotIRegEx ], Scalar::BigInt => vec![ FilterOp::Equal, @@ -3223,9 +3215,7 @@ impl ___Type for FilterTypeType { | FilterOp::Like | FilterOp::ILike | FilterOp::RegEx - | FilterOp::IRegEx - | FilterOp::NotRegEx - | FilterOp::NotIRegEx => __InputValue { + | FilterOp::IRegEx => __InputValue { name_: op.to_string(), type_: __Type::Scalar(scalar.clone()), description: None, diff --git a/src/transpile.rs b/src/transpile.rs index 3da7aae5..865724cb 100644 --- a/src/transpile.rs +++ b/src/transpile.rs @@ -696,8 +696,6 @@ impl FilterBuilderElem { FilterOp::ILike => "ilike", FilterOp::RegEx => "~", FilterOp::IRegEx => "~*", - FilterOp::NotRegEx => "!~", - FilterOp::NotIRegEx => "!~*", FilterOp::Is => { return Err("Error transpiling Is filter".to_string()); } diff --git a/test/expected/resolve_graphiql_schema.out b/test/expected/resolve_graphiql_schema.out index 8d8ad122..6c419607 100644 --- a/test/expected/resolve_graphiql_schema.out +++ b/test/expected/resolve_graphiql_schema.out @@ -5413,6 +5413,16 @@ begin; "description": null, + "defaultValue": null + }, + + { + + "name": "iregex", + + "type": { + + "kind": "SCALAR", + + "name": "String", + + "ofType": null + + }, + + "description": null, + + "defaultValue": null + + }, + { + "name": "is", + "type": { + @@ -5481,6 +5491,16 @@ begin; "description": null, + "defaultValue": null + }, + + { + + "name": "regex", + + "type": { + + "kind": "SCALAR", + + "name": "String", + + "ofType": null + + }, + + "description": null, + + "defaultValue": null + + }, + { + "name": "startsWith", + "type": { + diff --git a/test/expected/string_filters.out b/test/expected/string_filters.out index a4ae9316..94e9f52c 100644 --- a/test/expected/string_filters.out +++ b/test/expected/string_filters.out @@ -200,43 +200,6 @@ begin; } (1 row) - rollback to savepoint a; - -- Filter by not regex - select jsonb_pretty( - graphql.resolve($$ - { - memoCollection(filter: {contents: {nregex: "^F\\w+$"}}) { - edges { - node { - contents - } - } - } - } - $$) - ); - jsonb_pretty -------------------------------------------- - { + - "data": { + - "memoCollection": { + - "edges": [ + - { + - "node": { + - "contents": "baR"+ - } + - }, + - { + - "node": { + - "contents": "baz"+ - } + - } + - ] + - } + - } + - } -(1 row) - rollback to savepoint a; -- iregex is not case sensitive select jsonb_pretty( @@ -269,42 +232,5 @@ begin; } (1 row) - rollback to savepoint a; - -- niregex is not case sensitive - select jsonb_pretty( - graphql.resolve($$ - { - memoCollection(filter: {contents: {niregex: "^f\\w+$"}}) { - edges { - node { - contents - } - } - } - } - $$) - ); - jsonb_pretty -------------------------------------------- - { + - "data": { + - "memoCollection": { + - "edges": [ + - { + - "node": { + - "contents": "baR"+ - } + - }, + - { + - "node": { + - "contents": "baz"+ - } + - } + - ] + - } + - } + - } -(1 row) - rollback to savepoint a; rollback; diff --git a/test/sql/string_filters.sql b/test/sql/string_filters.sql index bc880819..1c068cad 100644 --- a/test/sql/string_filters.sql +++ b/test/sql/string_filters.sql @@ -109,22 +109,6 @@ begin; ); rollback to savepoint a; - -- Filter by not regex - select jsonb_pretty( - graphql.resolve($$ - { - memoCollection(filter: {contents: {nregex: "^F\\w+$"}}) { - edges { - node { - contents - } - } - } - } - $$) - ); - rollback to savepoint a; - -- iregex is not case sensitive select jsonb_pretty( graphql.resolve($$ @@ -141,21 +125,4 @@ begin; ); rollback to savepoint a; - -- niregex is not case sensitive - select jsonb_pretty( - graphql.resolve($$ - { - memoCollection(filter: {contents: {niregex: "^f\\w+$"}}) { - edges { - node { - contents - } - } - } - } - $$) - ); - rollback to savepoint a; - - rollback;