[Awesome Ruby Gem GraphQL] Use graphql-rails_logger gem to inspect GraphQL queries in a more readable format

GraphQL::RailsLogger

This gem allows you to inspect graphql queries in a more readable format.

This…

screenshot_before

becomes this …

screenshot_after

Installation

You can install it as a gem:

1
$ gem install graphql-rails_logger

or add it into a Gemfile (Bundler):

1
2
3
4
5
6
7
8
# Gemfile

# Put gems used only for development or testing in the appropriate group in the Gemfile
group :development do
# evanphx/benchmark-ips: Provides iteration per second benchmarking for Ruby
# https://github.com/evanphx/benchmark-ips
gem 'graphql-rails_logger', '1.2.3'
end

Then, run bundle install.

1
$ bundle install

Configuration

By default this gem formats params only for GraphqlController#execute.

If you want to change this behaviour, add config/initializers/graphql_rails_logger.rb file and set proper controller and actions like this:

1
2
3
4
5
6
7
# config/initializers/graphql_rails_logger.rb

GraphQL::RailsLogger.configure do |config|
config.white_list = {
'QueriesController' => %w(create)
}
end

There is an option to suppress (hide) the GraphQL Introspection Query from the console output. This may be helpful to declutter the console during client testing as these can be rather lengthy.

1
2
3
4
5
# config/initializers/graphql_rails_logger.rb

GraphQL::RailsLogger.configure do |config|
config.skip_introspection_query = true
end

The theme can be configured as well. The theme is applied using the rouge gem, where all available options can be found. The default value is Rouge::Themes::ThankfulEyes.new.

1
2
3
4
5
# config/initializers/graphql_rails_logger.rb

GraphQL::RailsLogger.configure do |config|
config.theme = Rouge::Themes::Pastie.new
end

References

[1] jetruby/graphql-rails_logger: Display GraphQL queries in a more readable format - https://github.com/jetruby/graphql-rails_logger

[2] graphql-rails_logger | RubyGems.org | your community gem host - https://rubygems.org/gems/graphql-rails_logger

[3] GraphQL - Related Projects - https://graphql-ruby.org/related_projects.html