Skip to content

Commit b3a5967

Browse files
committed
feat: support ActiveRecord v7
1 parent 5040f78 commit b3a5967

File tree

5 files changed

+44
-159
lines changed

5 files changed

+44
-159
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ gemspec
66
gem 'activerecord', ENV['RAILS_VERSION'] && "~> #{ENV['RAILS_VERSION']}.0"
77

88
# See https://github.com/nepalez/rspec-sqlimit/issues/13
9-
gem 'rspec-sqlimit', git: 'https://github.com/nepalez/rspec-sqlimit', branch: 'master', ref: '90c85f4143ae584872a6ce1d240d77fa4f3ceb49' # v0.0.3
9+
gem 'rspec-sqlimit'

Gemfile.lock

Lines changed: 34 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,66 @@
1-
GIT
2-
remote: https://github.com/nepalez/rspec-sqlimit
3-
revision: 90c85f4143ae584872a6ce1d240d77fa4f3ceb49
4-
ref: 90c85f4143ae584872a6ce1d240d77fa4f3ceb49
5-
branch: master
6-
specs:
7-
rspec-sqlimit (0.0.3)
8-
rails (> 4.2, < 7.0)
9-
rspec (~> 3.0)
10-
111
PATH
122
remote: .
133
specs:
144
graphql-preload (2.1.0)
15-
activerecord (>= 4.1, < 7)
5+
activerecord (>= 7)
166
graphql (>= 1.8, < 2)
177
graphql-batch (~> 0.3)
188
promise.rb (~> 0.7)
199

2010
GEM
2111
remote: https://rubygems.org/
2212
specs:
23-
actioncable (6.0.2.2)
24-
actionpack (= 6.0.2.2)
25-
nio4r (~> 2.0)
26-
websocket-driver (>= 0.6.1)
27-
actionmailbox (6.0.2.2)
28-
actionpack (= 6.0.2.2)
29-
activejob (= 6.0.2.2)
30-
activerecord (= 6.0.2.2)
31-
activestorage (= 6.0.2.2)
32-
activesupport (= 6.0.2.2)
33-
mail (>= 2.7.1)
34-
actionmailer (6.0.2.2)
35-
actionpack (= 6.0.2.2)
36-
actionview (= 6.0.2.2)
37-
activejob (= 6.0.2.2)
38-
mail (~> 2.5, >= 2.5.4)
39-
rails-dom-testing (~> 2.0)
40-
actionpack (6.0.2.2)
41-
actionview (= 6.0.2.2)
42-
activesupport (= 6.0.2.2)
43-
rack (~> 2.0, >= 2.0.8)
44-
rack-test (>= 0.6.3)
45-
rails-dom-testing (~> 2.0)
46-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
47-
actiontext (6.0.2.2)
48-
actionpack (= 6.0.2.2)
49-
activerecord (= 6.0.2.2)
50-
activestorage (= 6.0.2.2)
51-
activesupport (= 6.0.2.2)
52-
nokogiri (>= 1.8.5)
53-
actionview (6.0.2.2)
54-
activesupport (= 6.0.2.2)
55-
builder (~> 3.1)
56-
erubi (~> 1.4)
57-
rails-dom-testing (~> 2.0)
58-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
59-
activejob (6.0.2.2)
60-
activesupport (= 6.0.2.2)
61-
globalid (>= 0.3.6)
62-
activemodel (6.0.2.2)
63-
activesupport (= 6.0.2.2)
64-
activerecord (6.0.2.2)
65-
activemodel (= 6.0.2.2)
66-
activesupport (= 6.0.2.2)
67-
activestorage (6.0.2.2)
68-
actionpack (= 6.0.2.2)
69-
activejob (= 6.0.2.2)
70-
activerecord (= 6.0.2.2)
71-
marcel (~> 0.3.1)
72-
activesupport (6.0.2.2)
13+
activemodel (7.0.4.3)
14+
activesupport (= 7.0.4.3)
15+
activerecord (7.0.4.3)
16+
activemodel (= 7.0.4.3)
17+
activesupport (= 7.0.4.3)
18+
activesupport (7.0.4.3)
7319
concurrent-ruby (~> 1.0, >= 1.0.2)
74-
i18n (>= 0.7, < 2)
75-
minitest (~> 5.1)
76-
tzinfo (~> 1.1)
77-
zeitwerk (~> 2.2)
20+
i18n (>= 1.6, < 2)
21+
minitest (>= 5.1)
22+
tzinfo (~> 2.0)
7823
appraisal (2.2.0)
7924
bundler
8025
rake
8126
thor (>= 0.14.0)
82-
builder (3.2.4)
8327
coderay (1.1.2)
84-
concurrent-ruby (1.1.6)
85-
crass (1.0.6)
86-
diff-lcs (1.3)
87-
erubi (1.9.0)
88-
globalid (0.4.2)
89-
activesupport (>= 4.2.0)
28+
concurrent-ruby (1.2.2)
29+
diff-lcs (1.5.0)
9030
graphql (1.10.5)
9131
graphql-batch (0.4.2)
9232
graphql (>= 1.3, < 2)
9333
promise.rb (~> 0.7.2)
94-
i18n (1.8.2)
34+
i18n (1.13.0)
9535
concurrent-ruby (~> 1.0)
96-
loofah (2.4.0)
97-
crass (~> 1.0.2)
98-
nokogiri (>= 1.5.9)
99-
mail (2.7.1)
100-
mini_mime (>= 0.1.1)
101-
marcel (0.3.3)
102-
mimemagic (~> 0.3.2)
10336
method_source (1.0.0)
104-
mimemagic (0.3.4)
105-
mini_mime (1.0.2)
106-
mini_portile2 (2.4.0)
107-
minitest (5.14.0)
108-
nio4r (2.5.2)
109-
nokogiri (1.10.9)
110-
mini_portile2 (~> 2.4.0)
37+
minitest (5.18.0)
11138
promise.rb (0.7.4)
11239
pry (0.13.0)
11340
coderay (~> 1.1)
11441
method_source (~> 1.0)
115-
rack (2.2.2)
116-
rack-test (1.1.0)
117-
rack (>= 1.0, < 3)
118-
rails (6.0.2.2)
119-
actioncable (= 6.0.2.2)
120-
actionmailbox (= 6.0.2.2)
121-
actionmailer (= 6.0.2.2)
122-
actionpack (= 6.0.2.2)
123-
actiontext (= 6.0.2.2)
124-
actionview (= 6.0.2.2)
125-
activejob (= 6.0.2.2)
126-
activemodel (= 6.0.2.2)
127-
activerecord (= 6.0.2.2)
128-
activestorage (= 6.0.2.2)
129-
activesupport (= 6.0.2.2)
130-
bundler (>= 1.3.0)
131-
railties (= 6.0.2.2)
132-
sprockets-rails (>= 2.0.0)
133-
rails-dom-testing (2.0.3)
134-
activesupport (>= 4.2.0)
135-
nokogiri (>= 1.6)
136-
rails-html-sanitizer (1.3.0)
137-
loofah (~> 2.3)
138-
railties (6.0.2.2)
139-
actionpack (= 6.0.2.2)
140-
activesupport (= 6.0.2.2)
141-
method_source
142-
rake (>= 0.8.7)
143-
thor (>= 0.20.3, < 2.0)
144-
rake (13.0.1)
145-
rspec (3.9.0)
146-
rspec-core (~> 3.9.0)
147-
rspec-expectations (~> 3.9.0)
148-
rspec-mocks (~> 3.9.0)
149-
rspec-core (3.9.1)
150-
rspec-support (~> 3.9.1)
151-
rspec-expectations (3.9.1)
42+
rake (13.0.6)
43+
rspec (3.12.0)
44+
rspec-core (~> 3.12.0)
45+
rspec-expectations (~> 3.12.0)
46+
rspec-mocks (~> 3.12.0)
47+
rspec-core (3.12.2)
48+
rspec-support (~> 3.12.0)
49+
rspec-expectations (3.12.3)
15250
diff-lcs (>= 1.2.0, < 2.0)
153-
rspec-support (~> 3.9.0)
154-
rspec-mocks (3.9.1)
51+
rspec-support (~> 3.12.0)
52+
rspec-mocks (3.12.5)
15553
diff-lcs (>= 1.2.0, < 2.0)
156-
rspec-support (~> 3.9.0)
157-
rspec-support (3.9.2)
158-
sprockets (4.0.0)
159-
concurrent-ruby (~> 1.0)
160-
rack (> 1, < 3)
161-
sprockets-rails (3.2.1)
162-
actionpack (>= 4.0)
163-
activesupport (>= 4.0)
164-
sprockets (>= 3.0.0)
54+
rspec-support (~> 3.12.0)
55+
rspec-sqlimit (0.0.5)
56+
activerecord (> 4.2, < 7.1)
57+
rspec (~> 3.0)
58+
rspec-support (3.12.0)
16559
sqlite3 (1.4.2)
166-
thor (1.0.1)
167-
thread_safe (0.3.6)
168-
tzinfo (1.2.6)
169-
thread_safe (~> 0.1)
170-
websocket-driver (0.7.1)
171-
websocket-extensions (>= 0.1.0)
172-
websocket-extensions (0.1.4)
60+
thor (1.2.2)
61+
tzinfo (2.0.6)
62+
concurrent-ruby (~> 1.0)
17363
yard (0.9.24)
174-
zeitwerk (2.3.0)
17564

17665
PLATFORMS
17766
ruby
@@ -184,9 +73,9 @@ DEPENDENCIES
18473
pry (~> 0.10)
18574
rake (~> 13.0)
18675
rspec (~> 3.8)
187-
rspec-sqlimit!
76+
rspec-sqlimit
18877
sqlite3
18978
yard (~> 0.9)
19079

19180
BUNDLED WITH
192-
2.1.4
81+
2.3.14

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# GraphQL::Preload
22

3-
[![Gem Version](https://badge.fury.io/rb/graphql-preload.svg)](https://rubygems.org/gems/graphql-preload)
4-
53
Provides a DSL for the [`graphql` gem](https://github.com/rmosolgo/graphql-ruby) that allows ActiveRecord associations to be preloaded in field definitions. Based on a [gist](https://gist.github.com/theorygeek/a1a59a2bf9c59e4b3706ac68d12c8434) by @theorygeek.
64

7-
This fork works with Ruby on Rails 6.0 and GraphQL-Ruby 1.10 (but not in interpreter mode yet).
5+
This fork works with Ruby on Rails 7.0 and GraphQL-Ruby 1.12 (but not in interpreter mode yet).
86

97
## Installation
108

@@ -57,6 +55,7 @@ end
5755
```
5856

5957
### `preload_scope`
58+
6059
Starting with Rails 4.1, you can scope your preloaded records by passing a valid scope to [`ActiveRecord::Associations::Preloader`](https://apidock.com/rails/v4.1.8/ActiveRecord/Associations/Preloader/preload). Scoping can improve performance by reducing the number of models to be instantiated and can help with certain business goals (e.g., only returning records that have not been soft deleted).
6160

6261
This functionality is surfaced through the `preload_scope` option:
@@ -71,7 +70,7 @@ end
7170

7271
## Development
7372

74-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
7574

7675
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
7776

graphql-preload.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
2121
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2222
spec.require_paths = ['lib']
2323

24-
spec.add_runtime_dependency 'activerecord', '>= 4.1', '< 7'
24+
spec.add_runtime_dependency 'activerecord', '>= 7'
2525
spec.add_runtime_dependency 'graphql', '>= 1.8', '< 2'
2626
spec.add_runtime_dependency 'graphql-batch', '~> 0.3'
2727
spec.add_runtime_dependency 'promise.rb', '~> 0.7'

lib/graphql/preload/loader.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@ def perform(records)
3535
end
3636

3737
private def preload_association(records)
38-
preloader = ActiveRecord::Associations::Preloader.new.preload(records, association, preload_scope).first
38+
preloader = ActiveRecord::Associations::Preloader.new(
39+
records: records,
40+
associations: association,
41+
scope: preload_scope
42+
).call.first
3943
return unless preload_scope
40-
return if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.0.0")
41-
42-
if preloader.is_a?(::ActiveRecord::Associations::Preloader::AlreadyLoaded)
43-
raise ArgumentError,
44-
"Preloading association twice with scopes is not possible. " \
45-
"To resolve this problem add a scoped association (e.g., `has_many :records, -> { scope_name }, ...`) to the model"
46-
end
4744

4845
# this commit changes the way preloader works with scopes
4946
# https://github.com/rails/rails/commit/2847653869ffc1ff5139c46e520c72e26618c199#diff-3bba5f66eb1ed62bd5700872fcd6c632

0 commit comments

Comments
 (0)