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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 474fc735080a91dfb20de27a6f30d865130318e8689f2cd3e2fc4c4ba36c5510
4
- data.tar.gz: aac6eb21e108ae715f69f4256d21491cc23a5b5cc01e64528fbc9e48864c8bac
3
+ metadata.gz: af871adf4f20074267e23317255e81bff397756f724200e340d7d1dc878adb23
4
+ data.tar.gz: eaa5d6246257da87995933a8fd56ef0666a6b4e29babc24e34079fcc786f45c0
5
5
  SHA512:
6
- metadata.gz: ea105b60ad6f8a8da6c13fd2dc78e0230f0d2ad091645e59acb56c1f38b6b04804eba2acd1487b350234225d3624c8d36dd88a8292b73f0aff003bf30ecacbb7
7
- data.tar.gz: 746922a0932f6446e1428265d9a8b97ab82dc543af4907cf811b42d24b60430a419e9055cbabfa58b4d25eea3fd42f14b6d00d42d36cf774d8f37da4575ad9a6
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.
@@ -0,0 +1,5 @@
1
+ module GraphQL
2
+ module Filters
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -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{v(?<version>\d)+/(?<full_pattern>.*)} do |match_data|
23
- raise 'The only supported version of pattern is v1' if match_data[:version].to_i != 1
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
- resolve_v1 column_node, match_data[:full_pattern]
26
- end
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>.*)} do |match_data|
31
- options = match_data[:options].chars.map(&:to_sym)
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
- if options.present? && options != [:i]
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
- case_sensitive = !options.include?(:i)
38
+ if options.present? && options != [:i]
39
+ raise InvalidMatchError, 'The only supported option is \'i\' for case insensitive matching'
40
+ end
38
41
 
39
- characters = match_data[:pattern].chars
40
- pattern = ''
42
+ case_sensitive = !options.include?(:i)
41
43
 
42
- while characters.present?
43
- char = characters.shift
44
+ characters = match_data[:pattern].chars
45
+ pattern = ''
44
46
 
45
- pattern << case char
46
- when '\\'
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
- column_node.matches pattern, nil, case_sensitive
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
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Filters
3
- VERSION = '1.1.6'.freeze
3
+ VERSION = '1.1.7'.freeze
4
4
  end
5
5
  end
@@ -21,6 +21,7 @@ end
21
21
 
22
22
  # These need to be here, after the definition of GraphQL::Filters
23
23
 
24
+ require_relative 'filters/error'
24
25
  require_relative 'filters/activerecord_patch'
25
26
  require_relative 'filters/dsl'
26
27
  require_relative 'filters/filterable'
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.6
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