graphql-rails_logger 1.0.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 718affecc756a81b55c2a9184d6c548d280494d4
4
- data.tar.gz: 890ecf5d194cba6d4a032f4bf62838c2d061b9df
2
+ SHA256:
3
+ metadata.gz: ec122c5449dca8d9c4ad3cbfcf566b3fb326f3dda9e4ab873780a4789e716ae4
4
+ data.tar.gz: 37797d6232ce4e3befc9138d71a9fea3596d8b888f13917eb5221ef9c8709187
5
5
  SHA512:
6
- metadata.gz: bcc3afed83c469732b55749ff531892aa6d8cca7d311ef67e9a6183a8e480598b98c84b6695865986304cb9b342e0124d22224ca81aefcbcb7170e3935c1253b
7
- data.tar.gz: e6b26301123958355ee9a82da0d04a9f30a8697b2693fee5b76ae925cf9a94ce62179b9ec7122274022a2c89422303324503be428ff160d82a3db752418c230d
6
+ metadata.gz: 52b519e43fd717f8235ec0ab27014cacec433561560b87c17288e657d0109f71aae30ccd0966c7cd0cabca534c586d349030616a3f411a3fa188e490e161b1a7
7
+ data.tar.gz: 44f1c66f08bdfbdfd5f6089ebbe1e9e0a25dc5e26528e4c93dfe69e0beb75e1f413a5a249084bb584841fe977f1a8d9398b7d0478571fbe2ff38113e9f28faf9
data/README.md CHANGED
@@ -28,6 +28,7 @@ And then execute:
28
28
  By default this gem formats params only for `GraphqlController#execute`.
29
29
 
30
30
  If you want to change this behaviour, add `config/initializers/graphql_rails_logger.rb` file and set proper controller and actions like this:
31
+
31
32
  ```ruby
32
33
  GraphQL::RailsLogger.configure do |config|
33
34
  config.white_list = {
@@ -44,6 +45,14 @@ GraphQL::RailsLogger.configure do |config|
44
45
  end
45
46
  ```
46
47
 
48
+ The theme can be configured as well. The theme is applied using the [rouge](https://github.com/jneen/rouge) gem, where all available options can be found. The default value is `Rouge::Themes::ThankfulEyes.new`.
49
+
50
+ ```ruby
51
+ GraphQL::RailsLogger.configure do |config|
52
+ config.theme = Rouge::Themes::Pastie.new
53
+ end
54
+ ```
55
+
47
56
  ## Contributing
48
57
 
49
58
  Bug reports and pull requests are welcome on GitHub at https://github.com/jetruby/graphql-rails_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -16,12 +16,14 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
- spec.bindir = 'bin'
20
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
19
  spec.require_paths = ['lib']
22
20
 
23
21
  spec.add_dependency 'rouge', '~> 3.0'
24
- spec.add_dependency 'rails', '~> 5.0' # 5 because not tested with 4
22
+
23
+ # 5 because not tested with 4
24
+ spec.add_dependency 'actionpack', '> 5.0'
25
+ spec.add_dependency 'activesupport', '> 5.0'
26
+ spec.add_dependency 'railties', '> 5.0'
25
27
 
26
28
  spec.add_development_dependency 'bundler', '~> 1.15'
27
29
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,7 +1,9 @@
1
+ require 'rouge'
2
+
1
3
  module GraphQL
2
4
  module RailsLogger
3
5
  class Configuration
4
- attr_accessor :skip_introspection_query, :white_list
6
+ attr_accessor :skip_introspection_query, :white_list, :theme
5
7
 
6
8
  def initialize
7
9
  @skip_introspection_query = nil
@@ -10,6 +12,8 @@ module GraphQL
10
12
  @white_list = {
11
13
  'GraphqlController' => %w[execute]
12
14
  }
15
+
16
+ @theme = Rouge::Themes::ThankfulEyes.new
13
17
  end
14
18
  end
15
19
  end
@@ -1,6 +1,7 @@
1
1
  require 'graphql/rails_logger/configuration'
2
2
  require 'action_controller/log_subscriber'
3
3
  require 'rouge'
4
+ require 'pp'
4
5
 
5
6
  module GraphQL
6
7
  module RailsLogger
@@ -30,23 +31,40 @@ module GraphQL
30
31
  info "Processing by #{payload[:controller]}##{payload[:action]} as #{format}"
31
32
 
32
33
  if config.white_list.fetch(payload[:controller], []).include?(payload[:action])
33
- formatter = Rouge::Formatters::Terminal256.new
34
+ formatter = Rouge::Formatters::Terminal256.new(config.theme)
34
35
  query_lexer = Rouge::Lexers::GraphQL.new
35
36
  variables_lexer = Rouge::Lexers::Ruby.new
36
37
 
37
- (params['_json'] || [params.slice('query', 'variables')]).each do |data|
38
+ (params['_json'] || [params.slice('query', 'variables', 'extensions')]).each do |data|
38
39
 
39
40
  next if config.skip_introspection_query && data['query'].index(/query IntrospectionQuery/)
40
41
 
41
- query = data['query'].lines.map { |line| " #{line}" }.join.chomp # add indentation
42
- variables = PP.pp(data['variables'] || {}, '')
43
- info " Variables: #{formatter.format(variables_lexer.lex(variables))}"
44
- info formatter.format(query_lexer.lex(query))
42
+ # Cleanup and indent params for logging
43
+ query = indent(data.fetch('query', ''))
44
+ variables = indent(pretty(data.fetch('variables', '')))
45
+ extensions = indent(pretty(data.fetch('extensions', '')))
46
+
47
+ info "\nVariables:\n#{formatter.format(variables_lexer.lex(variables))}" if variables.present?
48
+ info "\nQuery:\n#{formatter.format(query_lexer.lex(query))}" if query.present?
49
+ info "\nExtensions:\n#{formatter.format(variables_lexer.lex(extensions))}" if extensions.present?
45
50
  end
46
51
  else
47
- info " Parameters: #{params.inspect}" unless params.empty?
52
+ info "\nParameters:\n#{params.inspect}" unless params.empty?
48
53
  end
49
54
  end
55
+
56
+ private
57
+
58
+ def indent(data)
59
+ data.lines.map { |line| " #{line}" }.join.chomp
60
+ end
61
+
62
+ def pretty(data)
63
+ return '' if data.blank?
64
+
65
+ data = JSON.parse(data) if data.is_a?(String)
66
+ PP.pp(data, '')
67
+ end
50
68
  end
51
69
  end
52
70
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module RailsLogger
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.2.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-rails_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JetRuby
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-13 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rouge
@@ -25,17 +25,45 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '5.0'
41
69
  - !ruby/object:Gem::Dependency
@@ -69,9 +97,7 @@ dependencies:
69
97
  description: Display GraphQL queries in a more readable format.
70
98
  email:
71
99
  - engineering@jetruby.com
72
- executables:
73
- - console
74
- - setup
100
+ executables: []
75
101
  extensions: []
76
102
  extra_rdoc_files: []
77
103
  files:
@@ -95,7 +121,7 @@ homepage: https://github.com/jetruby/graphql-rails_logger
95
121
  licenses:
96
122
  - MIT
97
123
  metadata: {}
98
- post_install_message:
124
+ post_install_message:
99
125
  rdoc_options: []
100
126
  require_paths:
101
127
  - lib
@@ -110,9 +136,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
136
  - !ruby/object:Gem::Version
111
137
  version: '0'
112
138
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.6.11
115
- signing_key:
139
+ rubyforge_project:
140
+ rubygems_version: 2.7.3
141
+ signing_key:
116
142
  specification_version: 4
117
143
  summary: Pretty logger for Rails + GraphQL applications.
118
144
  test_files: []