graphql-filters 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/LICENSE +1 -1
- data/README.md +3 -1
- data/lib/graphql/filters/dsl/graphql/schema/resolver.rb +26 -0
- data/lib/graphql/filters/filterable.rb +6 -6
- data/lib/graphql/filters/version.rb +1 -1
- data/lib/graphql/filters.rb +1 -1
- metadata +26 -14
- data/lib/graphql/models_connect/dsl/graphql/schema/object.rb +0 -27
- data/lib/graphql/models_connect/dsl.rb +0 -3
- data/lib/graphql/models_connect.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2de1ec0e63619e14566194c02827c05f3b593d1a032ab2a885ab2735fd2adf81
|
4
|
+
data.tar.gz: d26182e54ec5bdf0fa8eef48d31d76dd429827e7ac68e6cc2614fd25d1f3f99c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45e8caf0669fc4eba7a2731f19104177610692a526799b57d55c8c4b3d97aaf849e8c3162e6a7f7ea0af9be816102e61a3332d1a6f65394d6ef56e1fa287d448
|
7
|
+
data.tar.gz: c348559d4851966e5227f249f95d5bcfcf6a3bf9cc3f567d80f0ff41ca87dcab2c8f0f139ac96c76cf1da903cb0856ee5c8e035f99e40dc8864e0fdac60cc794
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,23 @@
|
|
8
8
|
### Bug fixes
|
9
9
|
)-->
|
10
10
|
|
11
|
+
## 1.0.4 2024-10-14
|
12
|
+
|
13
|
+
### New features
|
14
|
+
|
15
|
+
- Added `filtered_type` to declare a type for the filters which differs from the result type of the resolver.
|
16
|
+
|
17
|
+
### Bug fixes
|
18
|
+
|
19
|
+
- Fixed a broken `require`.
|
20
|
+
|
21
|
+
## 1.0.3 2024-10-09
|
22
|
+
|
23
|
+
### Bug fixes
|
24
|
+
|
25
|
+
- Made dependency to Rails more lax
|
26
|
+
- Extracted the pairing of models and GraphQL types into [a separate gem](https://github.com/moku-io/graphql-models_connect)
|
27
|
+
|
11
28
|
## 1.0.2 2023-07-24
|
12
29
|
|
13
30
|
### Bug fixes
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2023 Moku S.r.l., Riccardo Agatea
|
3
|
+
Copyright (c) 2023-2024 Moku S.r.l., Riccardo Agatea
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -47,6 +47,8 @@ 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
|
+
|
50
52
|
Using either of these resolvers for a `routes` field will generate all the necessary input types to make a query like this:
|
51
53
|
|
52
54
|
```graphql
|
@@ -95,7 +97,7 @@ query {
|
|
95
97
|
}
|
96
98
|
```
|
97
99
|
|
98
|
-
Notice that eager loading is outside the scope of this gem, so
|
100
|
+
Notice that eager loading is outside the scope of this gem, so without anything else the above query will fall victim to the N+1 problem.
|
99
101
|
|
100
102
|
Each input type is generated based on the respective type: scalar and enum types allow for basic comparisons like equality and inclusion, while object types let you build complex queries that mix and match comparisons on their fields. List types let you make `any`, `all`, and `none` queries based on a nested filter. Support for null-checked filters is planned for future development.
|
101
103
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
monkey_patch = Module.new do
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
attr_accessor :filtered_type_expr, :filtered_type_null
|
8
|
+
|
9
|
+
def filtered_type new_type=nil, null: nil
|
10
|
+
if new_type
|
11
|
+
raise ArgumentError, 'required argument `null:` is missing' if null.nil?
|
12
|
+
|
13
|
+
@filtered_type_expr = new_type
|
14
|
+
@filtered_type_null = null
|
15
|
+
elsif filtered_type_expr
|
16
|
+
GraphQL::Schema::Member::BuildType.parse_type filtered_type_expr, null: filtered_type_null
|
17
|
+
elsif type_expr
|
18
|
+
GraphQL::Schema::Member::BuildType.parse_type type_expr, null: self.null
|
19
|
+
elsif superclass.respond_to? :filtered_type
|
20
|
+
superclass.filtered_type
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
GraphQL::Schema::Resolver.prepend monkey_patch
|
@@ -9,14 +9,14 @@ module GraphQL
|
|
9
9
|
# nullability is relevant.
|
10
10
|
|
11
11
|
included do
|
12
|
-
raise 'You can only apply a filter to a list field' unless
|
12
|
+
raise 'You can only apply a filter to a list field' unless filtered_type.list?
|
13
13
|
|
14
14
|
unless defined?(SearchObject::Base) && include?(SearchObject::Base)
|
15
15
|
raise 'If you don\'t use SearchObject, you must *prepend* Filterable, not *include* it.'
|
16
16
|
end
|
17
17
|
|
18
|
-
inner_type =
|
19
|
-
inner_type =
|
18
|
+
inner_type = filtered_type
|
19
|
+
inner_type = filtered_type.of_type until inner_type.kind == GraphQL::TypeKinds::LIST
|
20
20
|
inner_type = inner_type.of_type
|
21
21
|
|
22
22
|
option :filter, type: inner_type.comparison_input_type do |scope, filter|
|
@@ -25,10 +25,10 @@ module GraphQL
|
|
25
25
|
end
|
26
26
|
|
27
27
|
prepended do
|
28
|
-
raise 'You can only apply a filter to a list field' unless
|
28
|
+
raise 'You can only apply a filter to a list field' unless filtered_type.list?
|
29
29
|
|
30
|
-
inner_type =
|
31
|
-
inner_type =
|
30
|
+
inner_type = filtered_type
|
31
|
+
inner_type = filtered_type.of_type while inner_type.kind == GraphQL::TypeKinds::LIST
|
32
32
|
inner_type = inner_type.of_type
|
33
33
|
|
34
34
|
argument :filter, inner_type.comparison_input_type, required: false
|
data/lib/graphql/filters.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_support/configurable'
|
2
2
|
require 'active_support/core_ext/module/delegation'
|
3
3
|
require 'graphql'
|
4
|
+
require 'graphql/models_connect'
|
4
5
|
require_relative 'filters/version'
|
5
6
|
require_relative 'filters/utility/cached_class'
|
6
7
|
|
@@ -20,7 +21,6 @@ end
|
|
20
21
|
|
21
22
|
# These need to be here, after the definition of GraphQL::Filters
|
22
23
|
|
23
|
-
require_relative 'models_connect'
|
24
24
|
require_relative 'filters/activerecord_patch'
|
25
25
|
require_relative 'filters/dsl'
|
26
26
|
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.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moku S.r.l.
|
@@ -9,36 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activesupport
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: graphql
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 2.0.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: graphql-models_connect
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
description: Provide a fully typed interface to filter lists in a GraphQL API.
|
57
71
|
email:
|
58
72
|
- info@moku.io
|
@@ -78,6 +92,7 @@ files:
|
|
78
92
|
- lib/graphql/filters/dsl/graphql/schema/member.rb
|
79
93
|
- lib/graphql/filters/dsl/graphql/schema/non_null.rb
|
80
94
|
- lib/graphql/filters/dsl/graphql/schema/object.rb
|
95
|
+
- lib/graphql/filters/dsl/graphql/schema/resolver.rb
|
81
96
|
- lib/graphql/filters/dsl/graphql/schema/scalar.rb
|
82
97
|
- lib/graphql/filters/dsl/graphql/types/numeric.rb
|
83
98
|
- lib/graphql/filters/dsl/graphql/types/string.rb
|
@@ -93,9 +108,6 @@ files:
|
|
93
108
|
- lib/graphql/filters/input_types/string_comparison_input_type.rb
|
94
109
|
- lib/graphql/filters/utility/cached_class.rb
|
95
110
|
- lib/graphql/filters/version.rb
|
96
|
-
- lib/graphql/models_connect.rb
|
97
|
-
- lib/graphql/models_connect/dsl.rb
|
98
|
-
- lib/graphql/models_connect/dsl/graphql/schema/object.rb
|
99
111
|
homepage: https://github.com/moku-io/graphql-filters
|
100
112
|
licenses:
|
101
113
|
- MIT
|
@@ -118,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
130
|
- !ruby/object:Gem::Version
|
119
131
|
version: '0'
|
120
132
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.5.11
|
122
134
|
signing_key:
|
123
135
|
specification_version: 4
|
124
136
|
summary: Provide a fully typed interface to filter lists in a GraphQL API.
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
monkey_patch = Module.new do
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
class_methods do
|
7
|
-
def model_class new_model_class=nil
|
8
|
-
if new_model_class.nil?
|
9
|
-
@model_class ||= default_model_class
|
10
|
-
else
|
11
|
-
@model_class = new_model_class
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def default_model_class
|
16
|
-
raise 'You must set an explicit model for anonymous graphql classes' if name.nil?
|
17
|
-
|
18
|
-
default_model_name = name.delete_suffix 'Type'
|
19
|
-
|
20
|
-
raise "No default model found for #{name}" unless const_defined? default_model_name
|
21
|
-
|
22
|
-
const_get default_model_name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
GraphQL::Schema::Object.prepend monkey_patch
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'active_support/configurable'
|
2
|
-
require 'active_support/core_ext/module/delegation'
|
3
|
-
require 'graphql'
|
4
|
-
|
5
|
-
module GraphQL
|
6
|
-
module ModelsConnect
|
7
|
-
include ActiveSupport::Configurable
|
8
|
-
|
9
|
-
singleton_class.delegate(*config.keys, to: :config)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# These need to be here, after the definition of GraphQL::ModelsConnect
|
14
|
-
|
15
|
-
require_relative 'models_connect/dsl'
|