Skip to content

Commit 901bf6d

Browse files
committed
Add support to ActiveRecord 3
1 parent eb12ce8 commit 901bf6d

12 files changed

+253
-13
lines changed

Appraisals

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
appraise "activerecord-3" do
2+
gem "activerecord", "3.2.14"
3+
gem "activesupport", "3.2.14"
4+
end
5+
6+
appraise "activerecord-4" do
7+
gem "activerecord", "4.2.0"
8+
end
9+
10+
appraise "activerecord-5" do
11+
gem "activerecord", "5.0.0"
12+
end

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
3434

3535
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/graphql-query-resolver. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
3636

37+
To run the specs across all supported versions of Rails, check out the repo and follow these steps:
38+
```bash
39+
$ bundle install
40+
$ bundle exec appraisal install
41+
$ bundle exec appraisal rake
42+
```
3743

3844
## License
3945

gemfiles/activerecord_3.gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "activerecord", "3.2.14"
6+
gem "activesupport", "3.2.14"
7+
8+
gemspec :path => "../"

gemfiles/activerecord_3.gemfile.lock

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
PATH
2+
remote: ../
3+
specs:
4+
graphql-query-resolver (0.1.0)
5+
graphql
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
activemodel (3.2.14)
11+
activesupport (= 3.2.14)
12+
builder (~> 3.0.0)
13+
activerecord (3.2.14)
14+
activemodel (= 3.2.14)
15+
activesupport (= 3.2.14)
16+
arel (~> 3.0.2)
17+
tzinfo (~> 0.3.29)
18+
activesupport (3.2.14)
19+
i18n (~> 0.6, >= 0.6.4)
20+
multi_json (~> 1.0)
21+
appraisal (2.1.0)
22+
bundler
23+
rake
24+
thor (>= 0.14.0)
25+
arel (3.0.3)
26+
builder (3.0.4)
27+
byebug (9.0.6)
28+
diff-lcs (1.3)
29+
graphql (1.5.1)
30+
i18n (0.8.1)
31+
multi_json (1.12.1)
32+
rake (10.5.0)
33+
rspec (3.5.0)
34+
rspec-core (~> 3.5.0)
35+
rspec-expectations (~> 3.5.0)
36+
rspec-mocks (~> 3.5.0)
37+
rspec-core (3.5.4)
38+
rspec-support (~> 3.5.0)
39+
rspec-expectations (3.5.0)
40+
diff-lcs (>= 1.2.0, < 2.0)
41+
rspec-support (~> 3.5.0)
42+
rspec-mocks (3.5.0)
43+
diff-lcs (>= 1.2.0, < 2.0)
44+
rspec-support (~> 3.5.0)
45+
rspec-support (3.5.0)
46+
sqlite3 (1.3.13)
47+
thor (0.19.4)
48+
tzinfo (0.3.52)
49+
50+
PLATFORMS
51+
ruby
52+
53+
DEPENDENCIES
54+
activerecord (= 3.2.14)
55+
activesupport (= 3.2.14)
56+
appraisal
57+
bundler (~> 1.11)
58+
byebug
59+
graphql-query-resolver!
60+
rake (~> 10.0)
61+
rspec (~> 3.0)
62+
sqlite3 (~> 1.3.12)
63+
64+
BUNDLED WITH
65+
1.13.7

gemfiles/activerecord_4.gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "activerecord", "4.2.0"
6+
7+
gemspec :path => "../"

gemfiles/activerecord_4.gemfile.lock

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
PATH
2+
remote: ../
3+
specs:
4+
graphql-query-resolver (0.1.0)
5+
graphql
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
activemodel (4.2.0)
11+
activesupport (= 4.2.0)
12+
builder (~> 3.1)
13+
activerecord (4.2.0)
14+
activemodel (= 4.2.0)
15+
activesupport (= 4.2.0)
16+
arel (~> 6.0)
17+
activesupport (4.2.0)
18+
i18n (~> 0.7)
19+
json (~> 1.7, >= 1.7.7)
20+
minitest (~> 5.1)
21+
thread_safe (~> 0.3, >= 0.3.4)
22+
tzinfo (~> 1.1)
23+
appraisal (2.1.0)
24+
bundler
25+
rake
26+
thor (>= 0.14.0)
27+
arel (6.0.4)
28+
builder (3.2.3)
29+
byebug (9.0.6)
30+
diff-lcs (1.3)
31+
graphql (1.5.1)
32+
i18n (0.8.1)
33+
json (1.8.6)
34+
minitest (5.10.1)
35+
rake (10.5.0)
36+
rspec (3.5.0)
37+
rspec-core (~> 3.5.0)
38+
rspec-expectations (~> 3.5.0)
39+
rspec-mocks (~> 3.5.0)
40+
rspec-core (3.5.4)
41+
rspec-support (~> 3.5.0)
42+
rspec-expectations (3.5.0)
43+
diff-lcs (>= 1.2.0, < 2.0)
44+
rspec-support (~> 3.5.0)
45+
rspec-mocks (3.5.0)
46+
diff-lcs (>= 1.2.0, < 2.0)
47+
rspec-support (~> 3.5.0)
48+
rspec-support (3.5.0)
49+
sqlite3 (1.3.13)
50+
thor (0.19.4)
51+
thread_safe (0.3.6)
52+
tzinfo (1.2.2)
53+
thread_safe (~> 0.1)
54+
55+
PLATFORMS
56+
ruby
57+
58+
DEPENDENCIES
59+
activerecord (= 4.2.0)
60+
appraisal
61+
bundler (~> 1.11)
62+
byebug
63+
graphql-query-resolver!
64+
rake (~> 10.0)
65+
rspec (~> 3.0)
66+
sqlite3 (~> 1.3.12)
67+
68+
BUNDLED WITH
69+
1.13.7

gemfiles/activerecord_5.gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "activerecord", "5.0.0"
6+
7+
gemspec :path => "../"

gemfiles/activerecord_5.gemfile.lock

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
PATH
2+
remote: ../
3+
specs:
4+
graphql-query-resolver (0.1.0)
5+
graphql
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
activemodel (5.0.0)
11+
activesupport (= 5.0.0)
12+
activerecord (5.0.0)
13+
activemodel (= 5.0.0)
14+
activesupport (= 5.0.0)
15+
arel (~> 7.0)
16+
activesupport (5.0.0)
17+
concurrent-ruby (~> 1.0, >= 1.0.2)
18+
i18n (~> 0.7)
19+
minitest (~> 5.1)
20+
tzinfo (~> 1.1)
21+
appraisal (2.1.0)
22+
bundler
23+
rake
24+
thor (>= 0.14.0)
25+
arel (7.1.4)
26+
byebug (9.0.6)
27+
concurrent-ruby (1.0.5)
28+
diff-lcs (1.3)
29+
graphql (1.5.1)
30+
i18n (0.8.1)
31+
minitest (5.10.1)
32+
rake (10.5.0)
33+
rspec (3.5.0)
34+
rspec-core (~> 3.5.0)
35+
rspec-expectations (~> 3.5.0)
36+
rspec-mocks (~> 3.5.0)
37+
rspec-core (3.5.4)
38+
rspec-support (~> 3.5.0)
39+
rspec-expectations (3.5.0)
40+
diff-lcs (>= 1.2.0, < 2.0)
41+
rspec-support (~> 3.5.0)
42+
rspec-mocks (3.5.0)
43+
diff-lcs (>= 1.2.0, < 2.0)
44+
rspec-support (~> 3.5.0)
45+
rspec-support (3.5.0)
46+
sqlite3 (1.3.13)
47+
thor (0.19.4)
48+
thread_safe (0.3.6)
49+
tzinfo (1.2.2)
50+
thread_safe (~> 0.1)
51+
52+
PLATFORMS
53+
ruby
54+
55+
DEPENDENCIES
56+
activerecord (= 5.0.0)
57+
appraisal
58+
bundler (~> 1.11)
59+
byebug
60+
graphql-query-resolver!
61+
rake (~> 10.0)
62+
rspec (~> 3.0)
63+
sqlite3 (~> 1.3.12)
64+
65+
BUNDLED WITH
66+
1.13.7

graphql-query-resolver.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
3030
spec.add_dependency "graphql"
3131

3232
spec.add_development_dependency "bundler", "~> 1.11"
33-
spec.add_development_dependency "activerecord", "~> 5.0.0"
33+
spec.add_development_dependency "activerecord", ">= 3.2"
3434
spec.add_development_dependency "sqlite3", "~> 1.3.12"
35-
35+
spec.add_development_dependency "appraisal"
3636
spec.add_development_dependency "byebug"
3737

3838
spec.add_development_dependency "rake", "~> 10.0"

lib/graphql/query_resolver.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ def self.run(model_class, context, return_type)
1212
dependencies = reflection_dependencies.merge(dependencies)
1313

1414
if dependencies.any? && to_load.present?
15-
# ActiveRecord::Associations::Preloader.new(to_load, dependencies).run
16-
ActiveRecord::Associations::Preloader.new.preload(to_load, dependencies)
15+
if ActiveRecord::VERSION::MAJOR < 4
16+
ActiveRecord::Associations::Preloader.new(to_load, dependencies).run
17+
else
18+
ActiveRecord::Associations::Preloader.new.preload(to_load, dependencies)
19+
end
1720
end
1821

1922
to_load

spec/graphql/query_resolver_spec.rb

+5-8
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,12 @@
7373
})
7474
end
7575

76-
expected_queries = [
77-
'SELECT "restaurants".* FROM "restaurants" WHERE "restaurants"."id" = ? LIMIT ?',
78-
'SELECT "chefs".* FROM "chefs" WHERE "chefs"."id" = 1',
79-
'SELECT "recipes".* FROM "recipes" WHERE "recipes"."chef_id" = 1',
80-
'SELECT "ingredients".* FROM "ingredients" WHERE "ingredients"."recipe_id" IN (1, 2, 3, 4)',
81-
'SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)'
82-
]
8376

84-
expect(queries).to eq(expected_queries)
77+
expect(queries[0]).to include('SELECT "restaurants".* FROM "restaurants" WHERE "restaurants"."id" = ?')
78+
expect(queries[1]).to include('SELECT "chefs".* FROM "chefs" WHERE "chefs"."id"') # AR 4 will use id IN (1), AR 5 will use id = 1
79+
expect(queries[2]).to include('SELECT "recipes".* FROM "recipes" WHERE "recipes"."chef_id"') # AR 4 will use id IN (1), AR 5 will use id = 1
80+
expect(queries[3]).to include('SELECT "ingredients".* FROM "ingredients" WHERE "ingredients"."recipe_id" IN (1, 2, 3, 4)')
81+
expect(queries[4]).to include('SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)')
8582
end
8683

8784
it 'works with alias reflections' do

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ def track_queries
3030
yield
3131
end
3232

33-
selects.map { |sel| sel[:sql] }
33+
selects.map { |sel| sel[:sql].strip.gsub(" ", " ") }
3434
end

0 commit comments

Comments
 (0)