graphql-filters 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +3 -0
- data/lib/graphql/filters/error.rb +5 -0
- data/lib/graphql/filters/input_types/string_comparison_input_type.rb +30 -26
- data/lib/graphql/filters/version.rb +1 -1
- data/lib/graphql/filters.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af871adf4f20074267e23317255e81bff397756f724200e340d7d1dc878adb23
|
|
4
|
+
data.tar.gz: eaa5d6246257da87995933a8fd56ef0666a6b4e29babc24e34079fcc786f45c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b2aa98387e913285068058dde306b188f90a4c921a9939e41d1542e90e725572d9bd6b9b2cc2425dc88d4f3beec84b10a44171041eb79b69472bf816e799875
|
|
7
|
+
data.tar.gz: b4934e3e62c1b4c79fc37da84ad14d879b136934e0615d8030c508b8daf5c338789c941995ee515c42274d9e279e206fb5d6159bc560b39469dc324fedd79193
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
### Bug fixes
|
|
9
9
|
)-->
|
|
10
10
|
|
|
11
|
+
## 1.1.7 2026-07-22
|
|
12
|
+
|
|
13
|
+
### New features
|
|
14
|
+
|
|
15
|
+
- Added `GraphQL::Filters::Error` as the common base for gem domain errors.
|
|
16
|
+
|
|
17
|
+
### Bug fixes
|
|
18
|
+
|
|
19
|
+
- Invalid string match syntax now raises an explicit error `GraphQL::Filters::InputTypes::StringComparisonInputType::InvalidMatchError` for invalid string match filters. instead of returning `nil`; unsupported versions and options no longer raise a generic `RuntimeError`.
|
|
20
|
+
|
|
11
21
|
## 1.1.6 2026-06-03
|
|
12
22
|
|
|
13
23
|
### Bug fixes
|
data/README.md
CHANGED
|
@@ -165,6 +165,9 @@ The best way to know what comparators you can use with each field is to open the
|
|
|
165
165
|
> [!NOTE]
|
|
166
166
|
> This is *not* a regex engine, just a simple wildcard matcher.
|
|
167
167
|
|
|
168
|
+
Malformed match syntax, unsupported pattern versions, and unsupported options raise
|
|
169
|
+
`GraphQL::Filters::InputTypes::StringComparisonInputType::InvalidMatchError`.
|
|
170
|
+
|
|
168
171
|
#### List comparisons
|
|
169
172
|
|
|
170
173
|
`any`, `all`, and `none` are available for any list, take a comparator for the type of the elements of the list, and match, respectively, if at least one, all, or none, of the elements of the list match the nested comparator.
|
|
@@ -4,6 +4,8 @@ module GraphQL
|
|
|
4
4
|
module Filters
|
|
5
5
|
module InputTypes
|
|
6
6
|
class StringComparisonInputType < BaseScalarComparisonInputType[GraphQL::Types::String]
|
|
7
|
+
class InvalidMatchError < GraphQL::Filters::Error; end
|
|
8
|
+
|
|
7
9
|
argument :match,
|
|
8
10
|
String,
|
|
9
11
|
prepare: lambda { |value, _context|
|
|
@@ -19,43 +21,45 @@ module GraphQL
|
|
|
19
21
|
private
|
|
20
22
|
|
|
21
23
|
def resolve_pattern column_node, expression
|
|
22
|
-
expression.match %r{
|
|
23
|
-
|
|
24
|
+
match_data = expression.match %r{\Av(?<version>\d+)/(?<full_pattern>.*)\z}
|
|
25
|
+
raise InvalidMatchError, 'Invalid match filter syntax. Expected v1/<v1_pattern>.' unless match_data
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
raise InvalidMatchError, 'The only supported version of pattern is v1' if match_data[:version].to_i != 1
|
|
28
|
+
|
|
29
|
+
resolve_v1 column_node, match_data[:full_pattern]
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
def resolve_v1 column_node, full_pattern
|
|
30
|
-
full_pattern.match %r{(?<pattern>.*?)/(?<options>.*)}
|
|
31
|
-
|
|
33
|
+
match_data = full_pattern.match %r{\A(?<pattern>.*?)/(?<options>.*)\z}
|
|
34
|
+
raise InvalidMatchError, 'Invalid match filter syntax for version v1. Expected v1/<pattern>/<options>.' unless match_data
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
raise 'The only supported option is \'i\' for case insensitive matching'
|
|
35
|
-
end
|
|
36
|
+
options = match_data[:options].chars.map(&:to_sym)
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
if options.present? && options != [:i]
|
|
39
|
+
raise InvalidMatchError, 'The only supported option is \'i\' for case insensitive matching'
|
|
40
|
+
end
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
pattern = ''
|
|
42
|
+
case_sensitive = !options.include?(:i)
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
characters = match_data[:pattern].chars
|
|
45
|
+
pattern = ''
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ActiveRecord::Base.sanitize_sql_like characters.shift
|
|
48
|
-
when '*'
|
|
49
|
-
'%'
|
|
50
|
-
when '.'
|
|
51
|
-
'_'
|
|
52
|
-
else
|
|
53
|
-
ActiveRecord::Base.sanitize_sql_like char
|
|
54
|
-
end
|
|
55
|
-
end
|
|
47
|
+
while characters.present?
|
|
48
|
+
char = characters.shift
|
|
56
49
|
|
|
57
|
-
|
|
50
|
+
pattern << case char
|
|
51
|
+
when '\\'
|
|
52
|
+
ActiveRecord::Base.sanitize_sql_like characters.shift
|
|
53
|
+
when '*'
|
|
54
|
+
'%'
|
|
55
|
+
when '.'
|
|
56
|
+
'_'
|
|
57
|
+
else
|
|
58
|
+
ActiveRecord::Base.sanitize_sql_like char
|
|
59
|
+
end
|
|
58
60
|
end
|
|
61
|
+
|
|
62
|
+
column_node.matches pattern, nil, case_sensitive
|
|
59
63
|
end
|
|
60
64
|
end
|
|
61
65
|
end
|
data/lib/graphql/filters.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: graphql-filters
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Moku S.r.l.
|
|
@@ -111,6 +111,7 @@ files:
|
|
|
111
111
|
- lib/graphql/filters/dsl/graphql/schema/scalar.rb
|
|
112
112
|
- lib/graphql/filters/dsl/graphql/types/numeric.rb
|
|
113
113
|
- lib/graphql/filters/dsl/graphql/types/string.rb
|
|
114
|
+
- lib/graphql/filters/error.rb
|
|
114
115
|
- lib/graphql/filters/filterable.rb
|
|
115
116
|
- lib/graphql/filters/input_types/base_comparison_input_type.rb
|
|
116
117
|
- lib/graphql/filters/input_types/base_list_comparison_input_type.rb
|