yuki24 / artemis

Ruby GraphQL client on Rails that actually makes you more productive
MIT License
207 stars 14 forks source link

Rails 7.1 complains about improper logging call from graphql-client gem #88

Closed erikdstock closed 6 months ago

erikdstock commented 8 months ago

As of Rails 7.1 a certain logging call triggered by Artemis through the graphql-client gem is supposed to use kwargs, but it doesn't. As a result, a wall of deprecation warnings appear in logs.

To make matters worse, the graphql-client source repo disappeared recently which is strange since it was repo under the github org. Here is one of the last wayback machine snapshots. As the remaining hosted documentation notes, this library is just a thin wrapper around the graphql gem, so it might be worth moving off this completely.

In our application we fixed this temporarily by adding a monkey patch to config/initializers/graphql_client.rb

require 'active_support/log_subscriber'

module GraphQL
  class Client
    class LogSubscriber < ActiveSupport::LogSubscriber
      def query(event)
        logger.info do
          name = event.payload[:operation_name].gsub('__', '::')
          type = event.payload[:operation_type].upcase
          # use keyword arg instead of positional for bolding
          color("#{name} #{type} (#{event.duration.round(1)}ms)", nil, bold: true)
        end

        logger.debug do
          event.payload[:document].to_query_string
        end
      end

      def error(event)
        logger.error do
          name = event.payload[:operation_name].gsub('__', '::')
          message = event.payload[:message]
          # use keyword arg instead of positional for bolding
          color("#{name} ERROR: #{message}", nil, bold: true)
        end
      end
    end
  end
end

Here is a link from our investigations with another approach to the fix.

h/t @jonallured for help with the investigation and fix.

yuki24 commented 8 months ago

@erikdstock Thanks for reporting! There seems to be some stuff that I have to catch up on in terms of the Ruby GraphQL client. I'll look into this and see if I can solve the issue quickly.

yuki24 commented 8 months ago

It seems like the repo has been moved to github-community-projects/graphql-client. I have sent a PR https://github.com/github-community-projects/graphql-client/pull/10 as a pernanent fix for this.

I have also cut a new release of artemis v1.0.0 that does not have any version constrants on the graphcl gem, so you should be able to work around this issue by using the latest gems and the PR above:

gem "artemis", ">= 1.0.0"
gem "graphql-client", git: "https://github.com/github-community-projects/graphql-client.git", commit: "b177b19"

Edit 02/06/2024: The PR linked above has been merged and I have updated the gem declaration above.

erikdstock commented 8 months ago

It seems like the repo has been moved to github-community-projects/graphql-client.

Wow, how did you track this down?

yuki24 commented 8 months ago

There is a private Slack community for the people who purchased The Complete Guide to Rails Performance and a dozen of folks had a conversation about it.

yuki24 commented 8 months ago

@erikdstock I just wanted to check in and see if this is still an issue. Please let me know if you any other help. Thanks!

yuki24 commented 6 months ago

I'm closing this issue as I believe the deprecation warnings have been addressed in the new graphql-client repo.