Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test GraphQL ruby gem 1.8 as well #28

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
@@ -10,6 +10,7 @@
{
posts {
user { id }
userId
}
}
QUERY
@@ -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
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "bundler/setup"

ENV['GRAPHQL_RUBY_VERSION'] ||= '1_8'

if ENV['CI']
require 'coveralls'
Coveralls.wear!