graphql-filters 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc4c3d2727cdf9d6767658acca81bed6a8b9d56aa129050fbdd84d69a0ab4454
4
- data.tar.gz: 9d76544c44e8890950caf45a390f078b1af0c2f0f5a689f0535b07e230e6a63b
3
+ metadata.gz: 8a9d2f9785a7b0347f74b77fb46760c08d86ec336efd6d631f3db797cbec46c1
4
+ data.tar.gz: 126111cae0cca972100e917054cd62a7fa32bf449d316ce53ca1d3b91eb89d0b
5
5
  SHA512:
6
- metadata.gz: e44a35f54fa1dbc70bde801e3c13c22dde64324ab17dcd24335529f35236a0269df551f0f24a41fa75c64227bc6d2b690c4e899ed11586a0ec748b2324fe7540
7
- data.tar.gz: f036f44b1124d4b692bcd7e29f8b43b0ead9d5e6bdfe997e69a2a90dbf63ecd06ed68980a93167b82dd2b5dce48a904469501c78fd401fe791e83a23e171945d
6
+ metadata.gz: 54a8e2562c6f323e979ca03a5a380cb88e8d630765d6cdc2db8e08cd18f280c0d60865bbe591165a3774aaa37d5e3541de5dda717e727ea503387f354928afd7
7
+ data.tar.gz: 9c3f9ea059cdd7e819bbed5d417115f6a55969d4e89020fe37ecd400e65ccc679a8848b1e6d66ac2b7742f07f48a499fb8c098ad56ca3ab71763f4f881e3e8fe
data/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@
8
8
  ### Bug fixes
9
9
  )-->
10
10
 
11
+ ## 1.0.5 2024-11-29
12
+
13
+ ### Bug fixes
14
+
15
+ - Fixed an internal bug in resolution of the filtered type for a resolver.
16
+
17
+ ## 1.0.4 2024-10-14
18
+
19
+ ### New features
20
+
21
+ - Added `filtered_type` to declare a type for the filters which differs from the result type of the resolver.
22
+
23
+ ### Bug fixes
24
+
25
+ - Fixed a broken `require`.
26
+
11
27
  ## 1.0.3 2024-10-09
12
28
 
13
29
  ### Bug fixes
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 if without anything else the above query will fall victim to the N+1 problem.
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,34 @@
1
+ require_relative 'lib/graphql/filters/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'graphql-filters'
5
+ spec.version = GraphQL::Filters::VERSION
6
+ spec.authors = ['Moku S.r.l.', 'Riccardo Agatea']
7
+ spec.email = ['info@moku.io']
8
+ spec.license = 'MIT'
9
+
10
+ spec.summary = 'Provide a fully typed interface to filter lists in a GraphQL API.'
11
+ spec.description = 'Provide a fully typed interface to filter lists in a GraphQL API.'
12
+ spec.homepage = 'https://github.com/moku-io/graphql-filters'
13
+ spec.required_ruby_version = '>= 3.0.0' # Maybe we should check (?)
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/moku-io/graphql-filters'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/moku-io/graphql-filters/blob/master/CHANGELOG.md'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir File.expand_path(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'activerecord'
31
+ spec.add_dependency 'activesupport'
32
+ spec.add_dependency 'graphql', '~> 2.0.0'
33
+ spec.add_dependency 'graphql-models_connect'
34
+ end
@@ -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 type.list?
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 = type
19
- inner_type = type.of_type until inner_type.kind == GraphQL::TypeKinds::LIST
18
+ inner_type = filtered_type
19
+ inner_type = inner_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 type.list?
28
+ raise 'You can only apply a filter to a list field' unless filtered_type.list?
29
29
 
30
- inner_type = type
31
- inner_type = type.of_type while inner_type.kind == GraphQL::TypeKinds::LIST
30
+ inner_type = filtered_type
31
+ inner_type = inner_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
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Filters
3
- VERSION = '1.0.3'.freeze
3
+ VERSION = '1.0.5'.freeze
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  require 'active_support/configurable'
2
2
  require 'active_support/core_ext/module/delegation'
3
3
  require 'graphql'
4
- require 'models_connect'
4
+ require 'graphql/models_connect'
5
5
  require_relative 'filters/version'
6
6
  require_relative 'filters/utility/cached_class'
7
7
 
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.3
4
+ version: 1.0.5
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: 2024-10-09 00:00:00.000000000 Z
12
+ date: 2024-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -81,6 +81,7 @@ files:
81
81
  - LICENSE
82
82
  - README.md
83
83
  - Rakefile
84
+ - graphql-filters.gemspec
84
85
  - lib/graphql/filters.rb
85
86
  - lib/graphql/filters/activerecord_patch.rb
86
87
  - lib/graphql/filters/activerecord_patch/arel/nodes/contained.rb
@@ -92,6 +93,7 @@ files:
92
93
  - lib/graphql/filters/dsl/graphql/schema/member.rb
93
94
  - lib/graphql/filters/dsl/graphql/schema/non_null.rb
94
95
  - lib/graphql/filters/dsl/graphql/schema/object.rb
96
+ - lib/graphql/filters/dsl/graphql/schema/resolver.rb
95
97
  - lib/graphql/filters/dsl/graphql/schema/scalar.rb
96
98
  - lib/graphql/filters/dsl/graphql/types/numeric.rb
97
99
  - lib/graphql/filters/dsl/graphql/types/string.rb
@@ -129,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  - !ruby/object:Gem::Version
130
132
  version: '0'
131
133
  requirements: []
132
- rubygems_version: 3.5.20
134
+ rubygems_version: 3.5.22
133
135
  signing_key:
134
136
  specification_version: 4
135
137
  summary: Provide a fully typed interface to filter lists in a GraphQL API.