Class: GraphQL::Client::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/graphql/client/log_subscriber.rb

Overview

Public: Logger for “*.graphql” notification events.

Logs GraphQL queries to Rails logger.

QUERY (123ms) UsersController::ShowQuery
MUTATION (456ms) UsersController::UpdateMutation

Enable GraphQL Client query logging.

require "graphql/client/log_subscriber"
GraphQL::Client::LogSubscriber.attach_to :graphql

Instance Method Summary collapse

Instance Method Details

#query(event) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/client/log_subscriber.rb', line 18

def query(event)
  # TODO: Colorize output
  info do
    [
      event.payload[:operation_type].upcase,
      "(#{event.duration.round(1)}ms)",
      event.payload[:operation_name].gsub("__", "::")
    ].join(" ")
  end

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