Skip to content

Commit

Permalink
Fix remaining tests and github CI actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Samsinite committed Nov 18, 2023
1 parent 27ef61f commit 0b8f72e
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 127 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ jobs:
fail-fast: false
matrix:
ruby_version:
- 2.5.x
- 2.6.x
- '2.7'
- '3.0'
- '3.1'
- '3.2'
graphql_version:
- 1.10.14
- 1.11.1
- "~> 2.1.0"
rails_version:
- "~> 5.2.0"
- "~> 6.0.0"
- "~> 6.1.0"
- "~> 7.0.0"
- "~> 7.1.0"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby_version }}
uses: actions/setup-ruby@v1
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
- name: Build and test
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake test
env:
Expand All @@ -37,13 +40,12 @@ jobs:
name: Rubocop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Ruby
uses: actions/setup-ruby@v1
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.x
ruby-version: 3.2
- name: Build and test
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rake rubocop
bundle exec rake rubocop
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Gemfile.lock
pkg
.ruby-version
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ graphql_version = ENV["GRAPHQL_VERSION"] == "edge" ? { github: "rmosolgo/graphql
gem "graphql", graphql_version

group :development, :test do
gem "rubocop", "~> 0.82.0"
gem "debug", ">= 1.0.0"
end
6 changes: 3 additions & 3 deletions graphql-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Gem::Specification.new do |s|
s.add_development_dependency "erubi", "~> 1.6"
s.add_development_dependency "erubis", "~> 2.7"
s.add_development_dependency "minitest", "~> 5.9"
s.add_development_dependency "rake", "~> 11.2"
s.add_development_dependency "rubocop-github", "~> 0.10", "<= 0.16.0"
s.add_development_dependency "rubocop", "~> 0.55"
s.add_development_dependency "rake", "~> 13.1.0"
s.add_development_dependency "rubocop-github"
s.add_development_dependency "rubocop", "~> 1.57.0"

s.required_ruby_version = ">= 2.1.0"

Expand Down
16 changes: 8 additions & 8 deletions lib/graphql/client/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ def flatten_spreads(node)

private

def cast_object(obj)
if obj.class.is_a?(GraphQL::Client::Schema::ObjectType)
unless obj._spreads.include?(definition_node.name)
raise TypeError, "#{definition_node.name} is not included in #{obj.source_definition.name}"
end
schema_class.cast(obj.to_h, obj.errors)
else
raise TypeError, "unexpected #{obj.class}"
def cast_object(obj)
if obj.class.is_a?(GraphQL::Client::Schema::ObjectType)
unless obj._spreads.include?(definition_node.name)
raise TypeError, "#{definition_node.name} is not included in #{obj.source_definition.name}"
end
schema_class.cast(obj.to_h, obj.errors)
else
raise TypeError, "unexpected #{obj.class}"
end
end
end
end
end
14 changes: 7 additions & 7 deletions lib/graphql/client/schema/object_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def gather_selections(fields, definition, selected_ast_node)
case selected_ast_node
when GraphQL::Language::Nodes::InlineFragment
continue_selection = if selected_ast_node.type.nil?
true
else
type_condition = definition.client.get_type(selected_ast_node.type.name)
applicable_types = definition.client.possible_types(type_condition)
# continue if this object type is one of the types matching the fragment condition
applicable_types.include?(type)
end
true
else
type_condition = definition.client.get_type(selected_ast_node.type.name)
applicable_types = definition.client.possible_types(type_condition)
# continue if this object type is one of the types matching the fragment condition
applicable_types.include?(type)
end

if continue_selection
selected_ast_node.selections.each do |next_selected_ast_node|
Expand Down
16 changes: 8 additions & 8 deletions lib/graphql/client/type_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def on_operation_definition(node, parent)

def on_inline_fragment(node, parent)
object_type = if node.type
@schema.get_type(node.type.name)
else
@object_types.last
end
@schema.get_type(node.type.name)
else
@object_types.last
end
if !object_type.nil?
object_type = object_type.unwrap
end
Expand All @@ -118,10 +118,10 @@ def on_inline_fragment(node, parent)

def on_fragment_definition(node, parent)
object_type = if node.type
@schema.get_type(node.type.name)
else
@object_types.last
end
@schema.get_type(node.type.name)
else
@object_types.last
end
if !object_type.nil?
object_type = object_type.unwrap
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_client_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class TestClientSchema < Minitest::Test
attr_reader :context

def headers(_)
{}
{}
end

def execute(document:, operation_name: nil, variables: {}, context: {})
@context = context
@context = context
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_erubis_graphql_section
output_buffer = @output_buffer = ActionView::OutputBuffer.new
# rubocop:disable Security/Eval
eval(erb.src, binding, "(erb)")
assert_equal "42", output_buffer.strip
assert_equal "42", output_buffer.to_s.strip

expected_query = <<-ERB
query {
Expand Down
6 changes: 2 additions & 4 deletions test/test_query_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def current_actor
)
end

field :users, PersonConnection, null: true do
argument :first, Integer, required: false
end
field :users, PersonConnection, null: true

def users
[
Expand Down Expand Up @@ -349,7 +347,7 @@ def test_no_method_error
person.nickname
flunk
rescue GraphQL::Client::UnimplementedFieldError => e
assert_equal "undefined field `nickname' on Person type. https://git.io/v1y3m", e.to_s
assert_match "undefined field `nickname' on Person type. https://git.io/v1y3m", e.to_s
end
end

Expand Down
20 changes: 10 additions & 10 deletions test/test_rubocop_heredoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_bad_graphql_heredoc
RUBY

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses.first.message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses.first.message
end

def test_bad_graphql_dash_heredoc
Expand All @@ -57,7 +57,7 @@ def test_bad_graphql_dash_heredoc
RUBY

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses.first.message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses.first.message
end

def test_bad_graphql_squiggly_heredoc
Expand All @@ -70,7 +70,7 @@ def test_bad_graphql_squiggly_heredoc
RUBY

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses.first.message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses.first.message
end

def test_bad_graphql_heredoc_with_interpolation
Expand All @@ -82,8 +82,8 @@ def test_bad_graphql_heredoc_with_interpolation
RUBY

assert_equal 2, @cop.offenses.count
assert_equal "Do not interpolate variables into GraphQL queries, used variables instead.", @cop.offenses[0].message
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[1].message
assert_equal "GraphQL/Heredoc: Do not interpolate variables into GraphQL queries, used variables instead.", @cop.offenses[0].message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[1].message
end

def test_bad_graphql_multiline_heredoc
Expand All @@ -96,7 +96,7 @@ def test_bad_graphql_multiline_heredoc
RUBY

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[0].message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[0].message
end

def test_bad_graphql_multiline_dash_heredoc
Expand All @@ -109,7 +109,7 @@ def test_bad_graphql_multiline_dash_heredoc
RUBY

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[0].message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[0].message
end

def test_bad_graphql_multiline_squiggly_heredoc
Expand All @@ -124,7 +124,7 @@ def test_bad_graphql_multiline_squiggly_heredoc
RUBY

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[0].message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[0].message
end

def test_bad_graphql_multiline_heredoc_with_interpolation
Expand All @@ -138,8 +138,8 @@ def test_bad_graphql_multiline_heredoc_with_interpolation
RUBY

assert_equal 2, @cop.offenses.count
assert_equal "Do not interpolate variables into GraphQL queries, used variables instead.", @cop.offenses[0].message
assert_equal "GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[1].message
assert_equal "GraphQL/Heredoc: Do not interpolate variables into GraphQL queries, used variables instead.", @cop.offenses[0].message
assert_equal "GraphQL/Heredoc: GraphQL heredocs should be quoted. <<-'GRAPHQL'", @cop.offenses[1].message
end

private
Expand Down
2 changes: 1 addition & 1 deletion test/test_rubocop_overfetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_field_unused
investigate(@cop, "#{Root}/views/users/overfetch.html.erb")

assert_equal 1, @cop.offenses.count
assert_equal "GraphQL field 'birthday' query but was not used in template.", @cop.offenses.first.message
assert_equal "GraphQL/Overfetch: GraphQL field 'birthday' query but was not used in template.", @cop.offenses.first.message
end

private
Expand Down
Loading

0 comments on commit 0b8f72e

Please sign in to comment.