Skip to content

Commit

Permalink
Test GraphQL ruby gem 1.8 as well
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Nov 30, 2018
1 parent 1f0048b commit 1b20018
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

# rspec failure tracking
.rspec_status
.ruby-version
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

26 changes: 21 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
sudo: false
language: ruby
rvm:
- 2.3.4
env:
- CI=true
before_install: gem install bundler -v 1.15.3
before_install: gem install bundler -v 1.17.1
matrix:
include:
- gemfile: graphql-1.7.gemfile
env: GRAPHQL_RUBY_VERSION=1_7 CI=true
rvm: 2.3.8
- gemfile: graphql-1.8.gemfile
env: GRAPHQL_RUBY_VERSION=1_8 CI=true
rvm: 2.3.8
- gemfile: graphql-1.7.gemfile
env: GRAPHQL_RUBY_VERSION=1_7 CI=true
rvm: 2.4.5
- gemfile: graphql-1.8.gemfile
env: GRAPHQL_RUBY_VERSION=1_8 CI=true
rvm: 2.4.5
- gemfile: graphql-1.7.gemfile
env: GRAPHQL_RUBY_VERSION=1_7 CI=true
rvm: 2.5.3
- gemfile: graphql-1.8.gemfile
env: GRAPHQL_RUBY_VERSION=1_8 CI=true
rvm: 2.5.3
7 changes: 7 additions & 0 deletions graphql-1.7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"

gem 'coveralls'

gem "graphql", "~> 1.7"

gemspec
7 changes: 7 additions & 0 deletions graphql-1.8.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"

gem 'coveralls'

gem "graphql", "~> 1.8"

gemspec
70 changes: 55 additions & 15 deletions spec/fixtures/graphql_schema.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
UserType = GraphQL::ObjectType.define do
name "User"
field :id, !types.ID
end
case ENV['GRAPHQL_RUBY_VERSION']
when '1_7'
UserType = GraphQL::ObjectType.define do
name "User"
field :id, !types.ID
end

PostType = GraphQL::ObjectType.define do
name "Post"
field :user, !UserType, resolve: ->(post, args, ctx) { post.user_lazy }
end
PostType = GraphQL::ObjectType.define do
name "Post"
field :user, !UserType, resolve: ->(object, args, ctx) { object.user_lazy }
field :userId, !types.Int, resolve: ->(object, args, ctx) do
BatchLoader.for(object).batch do |posts, loader|
posts.each { |p| loader.call(p, p.user_lazy.id) }
end
end
end

QueryType = GraphQL::ObjectType.define do
name "Query"
field :posts, !types[PostType], resolve: ->(obj, args, ctx) { Post.all }
end
QueryType = GraphQL::ObjectType.define do
name "Query"
field :posts, !types[PostType], resolve: ->(obj, args, ctx) { Post.all }
end

GraphqlSchema = GraphQL::Schema.define do
query QueryType
use BatchLoader::GraphQL
end
when '1_8'
class UserType < GraphQL::Schema::Object
field :id, ID, null: false
end

class PostType < GraphQL::Schema::Object
field :user, UserType, null: false
field :user_id, Int, null: false

def user
object.user_lazy
end

def user_id
BatchLoader.for(object).batch do |posts, loader|
posts.each { |p| loader.call(p, p.user_lazy.id) }
end
end
end

class QueryType < GraphQL::Schema::Object
field :posts, [PostType], null: false

def posts
Post.all
end
end

GraphqlSchema = GraphQL::Schema.define do
query QueryType
use BatchLoader::GraphQL
class GraphqlSchema < GraphQL::Schema
query QueryType
use BatchLoader::GraphQL
end
end
5 changes: 3 additions & 2 deletions spec/graphql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{
posts {
user { id }
userId
}
}
QUERY
Expand All @@ -20,8 +21,8 @@

expect(result['data']).to eq({
'posts' => [
{'user' => {'id' => "1"}},
{'user' => {'id' => "2"}}
{'user' => {'id' => "1"}, "userId" => 1},
{'user' => {'id' => "2"}, "userId" => 2}
]
})
end
Expand Down

0 comments on commit 1b20018

Please sign in to comment.