graphql-filters 1.1.2 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 384e2aca53aa1fce190281c21041e66682616963ead8887c4a05c3586f1c9c98
|
4
|
+
data.tar.gz: c4b48cd47c65fbe371e7e555c7bce2d2fd47c823da49e532af579c9d40df23ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebef1f3f13bc566f81ee84a522c74046eb601fd6e6d9d1b31804a7649857af719b78566acf0946173c6ae25ebfb53c114f4036883ea799719a86829a16e8e50a
|
7
|
+
data.tar.gz: '038e7a8eeb8b8819567101aeb4bc573eb00322ac4ebf50722a27e1448b638f072d25874db78a1f42d8277d3837a6f7975ae0f1a2c22924344f63a77a9aa5b517'
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,16 @@
|
|
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
|
+
|
11
21
|
## 1.1.2 2025-05-16
|
12
22
|
|
13
23
|
### 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
|
|
@@ -10,24 +10,31 @@ module GraphQL
|
|
10
10
|
klass.new BaseComparisonInputType do
|
11
11
|
graphql_name "#{object_type.graphql_name}ComparisonInput"
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
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.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-
|
12
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|