Skip to content

Commit b2625a3

Browse files
committed
Test against various versions of GraphQL-Ruby and ActiveRecord
1 parent 51ac726 commit b2625a3

File tree

13 files changed

+207
-35
lines changed

13 files changed

+207
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/spec/reports/
99
/tmp/
1010
.rspec_status
11+
/gemfiles/*.lock

.travis.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
---
2-
sudo: false
32
language: ruby
43
cache: bundler
5-
rvm:
6-
- 2.5.1
7-
- 2.4.4
8-
- 2.3.7
9-
before_install: gem install bundler -v 2.0.2
4+
before_install: gem install bundler -v '~> 2.0'
5+
6+
jobs:
7+
include:
8+
- rvm: 2.7.0
9+
gemfile: gemfiles/graphql_1.10.gemfile
10+
env:
11+
- GRAPHQL_RUBY_INTERPRETER=yes
12+
- RAILS_VERSION=6.0
13+
- rvm: 2.7.0
14+
gemfile: gemfiles/graphql_1.10.gemfile
15+
env:
16+
- GRAPHQL_RUBY_INTERPRETER=no
17+
- RAILS_VERSION=6.0
18+
- rvm: 2.6.5
19+
gemfile: gemfiles/graphql_1.9.gemfile
20+
env:
21+
- GRAPHQL_RUBY_INTERPRETER=yes
22+
- RAILS_VERSION=6.0
23+
- rvm: 2.6.5
24+
gemfile: gemfiles/graphql_1.9.gemfile
25+
env:
26+
- GRAPHQL_RUBY_INTERPRETER=no
27+
- RAILS_VERSION=6.0
28+
- rvm: 2.5.7
29+
gemfile: gemfiles/graphql_1.9.gemfile
30+
env:
31+
- GRAPHQL_RUBY_INTERPRETER=yes
32+
- RAILS_VERSION=5.2
33+
- rvm: 2.5.7
34+
gemfile: gemfiles/graphql_1.9.gemfile
35+
env:
36+
- GRAPHQL_RUBY_INTERPRETER=no
37+
- RAILS_VERSION=5.2
38+
- rvm: 2.4.9
39+
gemfile: gemfiles/graphql_1.8.gemfile
40+
env:
41+
- RAILS_VERSION=5.1

Appraisals

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
appraise "graphql-1.8" do
2+
gem "graphql", "~> 1.8.0"
3+
end
4+
5+
appraise "graphql-1.9" do
6+
gem "graphql", "~> 1.9.0"
7+
end
8+
9+
appraise "graphql-1.10" do
10+
gem "graphql", "~> 1.10.0"
11+
end

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in graphql-preload.gemspec
44
gemspec
5+
6+
gem 'activerecord', ENV['RAILS_VERSION'] && "~> #{ENV['RAILS_VERSION']}.0"

gemfiles/.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
BUNDLE_RETRY: "1"

gemfiles/graphql_1.10.gemfile

Lines changed: 8 additions & 0 deletions
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", nil
6+
gem "graphql", "~> 1.10.0"
7+
8+
gemspec path: "../"

gemfiles/graphql_1.8.gemfile

Lines changed: 8 additions & 0 deletions
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", nil
6+
gem "graphql", "~> 1.8.0"
7+
8+
gemspec path: "../"

gemfiles/graphql_1.9.gemfile

Lines changed: 8 additions & 0 deletions
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", nil
6+
gem "graphql", "~> 1.9.0"
7+
8+
gemspec path: "../"

graphql-preload.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ Gem::Specification.new do |spec|
2828

2929
spec.add_development_dependency 'bundler', '~> 2.0'
3030
spec.add_development_dependency 'pry', '~> 0.10'
31-
spec.add_development_dependency 'rake', '~> 10.0'
31+
spec.add_development_dependency 'rake', '~> 13.0'
3232
spec.add_development_dependency 'rspec', '~> 3.8'
3333
spec.add_development_dependency 'rspec-sqlimit'
3434
spec.add_development_dependency 'sqlite3'
3535
spec.add_development_dependency 'yard', '~> 0.9'
36+
spec.add_development_dependency "appraisal"
3637
end

spec/graphql/preload_spec.rb

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,61 @@
44
RSpec.describe GraphQL::Preload do
55
subject do
66
@result ||=
7-
PreloadSchema.execute(query: query_string, context: {}, variables: {})
7+
schema.execute(query: query_string, context: {}, variables: {})
88
end
99

10-
context "without associations" do
11-
let(:query_string) { "query { products { title } }" }
10+
shared_examples "test suite" do
11+
context "without associations" do
12+
let(:query_string) { "query { products { title } }" }
1213

13-
it "doesn't load associations at all" do
14-
expect { subject }.not_to exceed_query_limit 1
14+
it "doesn't load associations at all" do
15+
expect { subject }.not_to exceed_query_limit 1
16+
end
1517
end
16-
end
1718

18-
context "with associations" do
19-
let(:query_string) do
20-
<<~QRAPHQL
19+
context "with associations" do
20+
let(:query_string) do
21+
<<~QRAPHQL
2122
query { posts { title comments { text } } }
22-
QRAPHQL
23-
end
23+
QRAPHQL
24+
end
2425

25-
it "preloads associations by single query" do
26-
expect { subject }.to exceed_query_limit 1 # to ensure that GraphQL query at least works
27-
expect { subject }.not_to exceed_query_limit 2
28-
posts = subject.dig("data", "posts")
29-
expect(posts.size).to eq(4)
30-
expect(posts.flat_map { |p| p["comments"] }.size).to eq(8)
26+
it "preloads associations by single query" do
27+
expect { subject }.to exceed_query_limit 1 # to ensure that GraphQL query at least works
28+
expect { subject }.not_to exceed_query_limit 2
29+
posts = subject.dig("data", "posts")
30+
expect(posts.size).to eq(4)
31+
expect(posts.flat_map { |p| p["comments"] }.size).to eq(8)
32+
end
3133
end
32-
end
3334

34-
context "with associations with custom scopes" do
35-
let(:query_string) do
36-
<<~QRAPHQL
35+
context "with associations with custom scopes" do
36+
let(:query_string) do
37+
<<~QRAPHQL
3738
query { users { name posts { title } } }
38-
QRAPHQL
39-
end
39+
QRAPHQL
40+
end
4041

41-
it "preloads associations by single query and given order" do
42-
expect { subject }.not_to exceed_query_limit 2
43-
posts = subject.dig("data", "users").flat_map { |p| p["posts"] }
44-
# Posts for every user should be from greater rating to lower
45-
expect(posts.map { |p| p["title"] }).to eq(%w[Bar Foo Baz Huh])
42+
it "preloads associations by single query and given order" do
43+
expect { subject }.not_to exceed_query_limit 2
44+
posts = subject.dig("data", "users").flat_map { |p| p["posts"] }
45+
# Posts for every user should be from greater rating to lower
46+
expect(posts.map { |p| p["title"] }).to eq(%w[Bar Foo Baz Huh])
47+
end
4648
end
4749
end
50+
51+
context "modern class-based GraphQL schema" do
52+
let(:schema) { PreloadSchema }
53+
54+
include_examples "test suite"
55+
end
56+
57+
context "legacy define-based GraphQL schema" do
58+
next if TESTING_GRAPHQL_RUBY_INTERPRETER # No interpreter runtime these days
59+
60+
let(:schema) { Legacy::PreloadSchema }
61+
62+
include_examples "test suite"
63+
end
4864
end

0 commit comments

Comments
 (0)