graphql-filters 1.1.1 → 1.1.3

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: 1d399441a0d115f6f12a81f8c02b58d812565fcbb2f6643950fb47011961fc30
4
- data.tar.gz: 0c6254f218d5ee41a0b69677148fccffc43952e35ce970457954f94f9f1689e3
3
+ metadata.gz: 384e2aca53aa1fce190281c21041e66682616963ead8887c4a05c3586f1c9c98
4
+ data.tar.gz: c4b48cd47c65fbe371e7e555c7bce2d2fd47c823da49e532af579c9d40df23ae
5
5
  SHA512:
6
- metadata.gz: 7f3d352f14eaddf2d43d1cbf0c78a213adeb2bde8b2f8322905521d530864f4980f41490d1482fdbaadddd86865d0539ce69604c83427a3737e1a997171d9098
7
- data.tar.gz: 5fd54c27598465b72b77b7cf31678d167180ddc2833bfb93d8aac43a8ee8dadbf01a3ad8639ab7888921a3f96d1dd6b48e35fd221a2278b591e080164aa0cf2b
6
+ metadata.gz: ebef1f3f13bc566f81ee84a522c74046eb601fd6e6d9d1b31804a7649857af719b78566acf0946173c6ae25ebfb53c114f4036883ea799719a86829a16e8e50a
7
+ data.tar.gz: '038e7a8eeb8b8819567101aeb4bc573eb00322ac4ebf50722a27e1448b638f072d25874db78a1f42d8277d3837a6f7975ae0f1a2c22924344f63a77a9aa5b517'
data/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@
8
8
  ### Bug fixes
9
9
  )-->
10
10
 
11
+ ## 1.1.3 2025-05-21
12
+
13
+ ### New features
14
+
15
+ - Added the `filtered_type` field option.
16
+
17
+ ### Bug fixes
18
+
19
+ - Ensured the arguments of a `ComparisonInput` are defined after all the fields of the respective object type have been defined. Before, some cases of circular references made certain arguments not get defined.
20
+
21
+ ## 1.1.2 2025-05-16
22
+
23
+ ### Bug fixes
24
+
25
+ - Using `definition_methods` broke something in newer versions of the `graphql` gem. We now use `ActiveSupport::Concern`.
26
+
11
27
  ## 1.1.1 2025-05-16
12
28
 
13
29
  ### Bug fixes
data/README.md CHANGED
@@ -47,8 +47,6 @@ class RoutesResolver < BaseResolver
47
47
  end
48
48
  ```
49
49
 
50
- By default the filters are based on the `type`. If you need them to be based on a different type (for example if the result will be wrapped in another object), you can declare it with `filtered_type`, which has the same API as `type`.
51
-
52
50
  Using either of these resolvers for a `routes` field will generate all the necessary input types to make a query like this:
53
51
 
54
52
  ```graphql
@@ -234,6 +232,10 @@ field :name, String, null: false, filter: {enabled: false}
234
232
 
235
233
  The name of the Active Record association that the field is tied to in the model. Equivalent to `attribute_name`, has the same default.
236
234
 
235
+ - `filtered_type`
236
+
237
+ The type the filters for this field need to be based on, if it's different from the field's own type (for example, a field thet returns a connection will need to be filtered based on the connection's node type). Can also be set calling the `filtered_type` on a resolver/mutation if the field is associated with one.
238
+
237
239
  ## Plans for future development
238
240
 
239
241
  - A finer grain support for non-nullable fields.
@@ -13,7 +13,8 @@ monkey_patch = Module.new do
13
13
  default: {
14
14
  enabled: true,
15
15
  attribute_name: :method_sym.to_proc,
16
- association_name: :method_sym.to_proc
16
+ association_name: :method_sym.to_proc,
17
+ filtered_type: ->(field){field.resolver ? field.resolver.filtered_type : field.type}
17
18
  }
18
19
  end
19
20
 
@@ -1,13 +1,21 @@
1
- GraphQL::Schema::Interface.definition_methods do
2
- def comparison_input_type new_comparison_input_type=nil
3
- if new_comparison_input_type.present?
4
- @comparison_input_type = new_comparison_input_type
5
- else
6
- @comparison_input_type ||= get_comparison_input_type
1
+ require 'active_support/concern'
2
+
3
+ monkey_patch = Module.new do
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ def comparison_input_type new_comparison_input_type=nil
8
+ if new_comparison_input_type.present?
9
+ @comparison_input_type = new_comparison_input_type
10
+ else
11
+ @comparison_input_type ||= get_comparison_input_type
12
+ end
7
13
  end
8
- end
9
14
 
10
- def get_comparison_input_type(*)
11
- GraphQL::Filters::InputTypes::ObjectComparisonInputType[self]
15
+ def get_comparison_input_type(*)
16
+ GraphQL::Filters::InputTypes::ObjectComparisonInputType[self]
17
+ end
12
18
  end
13
19
  end
20
+
21
+ GraphQL::Schema::Interface.include monkey_patch
@@ -10,24 +10,31 @@ module GraphQL
10
10
  klass.new BaseComparisonInputType do
11
11
  graphql_name "#{object_type.graphql_name}ComparisonInput"
12
12
 
13
- object_type.fields.each_value do |field_object|
14
- next unless field_object.filter_options[:enabled]
15
-
16
- type = field_object.type
17
- filter_options = field_object.filter_options
18
-
19
- argument field_object.name,
20
- type.comparison_input_type,
21
- required: false,
22
- prepare: lambda { |field_comparator, _context|
23
- lambda { |scope|
24
- if scope.klass.attribute_names.include? filter_options[:attribute_name].to_s
25
- field_comparator.call scope, filter_options[:attribute_name]
26
- else
27
- field_comparator.call scope, filter_options[:association_name]
28
- end
29
- }
30
- }
13
+ define_singleton_method :own_arguments do |*args, **kwargs, &block|
14
+ unless @loaded_fields_arguments
15
+ object_type.fields.each_value do |field_object|
16
+ next unless field_object.filter_options[:enabled]
17
+
18
+ type = field_object.filter_options[:filtered_type]
19
+ filter_options = field_object.filter_options
20
+
21
+ argument field_object.name,
22
+ type.comparison_input_type,
23
+ required: false,
24
+ prepare: lambda { |field_comparator, _context|
25
+ lambda { |scope|
26
+ if scope.klass.attribute_names.include? filter_options[:attribute_name].to_s
27
+ field_comparator.call scope, filter_options[:attribute_name]
28
+ else
29
+ field_comparator.call scope, filter_options[:association_name]
30
+ end
31
+ }
32
+ }
33
+ end
34
+ @loaded_fields_arguments = true
35
+ end
36
+
37
+ super(*args, **kwargs, &block)
31
38
  end
32
39
 
33
40
  define_method :prepare do
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Filters
3
- VERSION = '1.1.1'.freeze
3
+ VERSION = '1.1.3'.freeze
4
4
  end
5
5
  end
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.1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moku S.r.l.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-05-16 00:00:00.000000000 Z
12
+ date: 2025-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord