diff --git a/Gemfile b/Gemfile index 009240b..5b908a9 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec rails_version = ENV["RAILS_VERSION"] == "edge" ? { github: "rails/rails" } : ENV["RAILS_VERSION"] gem "actionpack", rails_version gem "activesupport", rails_version +gem "concurrent-ruby", "1.3.4" graphql_version = ENV["GRAPHQL_VERSION"] == "edge" ? { github: "rmosolgo/graphql-ruby", ref: "interpreter-without-legacy" } : ENV["GRAPHQL_VERSION"] gem "graphql", graphql_version diff --git a/lib/graphql/client/erb.rb b/lib/graphql/client/erb.rb index d4b42fd..d549f29 100644 --- a/lib/graphql/client/erb.rb +++ b/lib/graphql/client/erb.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true require "action_view" +require "logger" module GraphQL class Client diff --git a/lib/rubocop/cop/graphql/overfetch.rb b/lib/rubocop/cop/graphql/overfetch.rb index 182fe83..f30f1bd 100644 --- a/lib/rubocop/cop/graphql/overfetch.rb +++ b/lib/rubocop/cop/graphql/overfetch.rb @@ -42,7 +42,7 @@ def investigate(processed_source) visitor.fields.each do |field, count| next if count > 0 - add_offense(nil, message: "GraphQL field '#{field}' query but was not used in template.") + add_offense(visitor.ranges[field], message: "GraphQL field '#{field}' query but was not used in template.") end end diff --git a/test/test_client_fetch.rb b/test/test_client_fetch.rb index e438f70..dbf99a4 100644 --- a/test/test_client_fetch.rb +++ b/test/test_client_fetch.rb @@ -79,10 +79,10 @@ def self.resolve_type(_type, _obj, _ctx) refute response.data refute_empty response.errors - assert_equal "Field 'err' doesn't exist on type 'Query'", response.errors[:data][0] + assert_includes response.errors[:data][0], "Field 'err' doesn't exist on type 'Query'" refute_empty response.errors.all - assert_equal "Field 'err' doesn't exist on type 'Query'", response.errors[:data][0] + assert_includes response.errors[:data][0], "Field 'err' doesn't exist on type 'Query'" end def test_failed_response diff --git a/test/test_rubocop_heredoc.rb b/test/test_rubocop_heredoc.rb index e1a5586..57fd011 100644 --- a/test/test_rubocop_heredoc.rb +++ b/test/test_rubocop_heredoc.rb @@ -9,85 +9,85 @@ def setup end def test_good_graphql_heredoc - investigate(@cop, <<-RUBY) + result = investigate(@cop, <<-RUBY) Query = Client.parse <<'GRAPHQL' { version } GRAPHQL RUBY - assert_empty @cop.offenses.map(&:message) + assert_empty result.offenses.map(&:message) end def test_good_graphql_dash_heredoc - investigate(@cop, <<-RUBY) + result = investigate(@cop, <<-RUBY) Query = Client.parse <<-'GRAPHQL' { version } GRAPHQL RUBY - assert_empty @cop.offenses.map(&:message) + assert_empty result.offenses.map(&:message) end def test_good_graphql_squiggly_heredoc - investigate(@cop, <<-RUBY) + result = investigate(@cop, <<-RUBY) Query = Client.parse <<~'GRAPHQL' { version } GRAPHQL RUBY - assert_empty @cop.offenses.map(&:message) + assert_empty result.offenses.map(&:message) end def test_bad_graphql_heredoc - investigate(@cop, <<-RUBY) + result = investigate(@cop, <<-RUBY) Query = Client.parse <