rack-graphql 1.2.4 → 2.1.0

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
2
  SHA256:
3
- metadata.gz: ad72995a97636738e4bffab0a6b6e238ff977c235305c7bcae168117de59115d
4
- data.tar.gz: a6f19b6371d91d7de8db37f7f40909ef639ffd7b225cfc2f45e6ea16241afd94
3
+ metadata.gz: 89001cf0e27af277a4e74c423e6ebaed600057a5528d9c0b850a76f704690454
4
+ data.tar.gz: d5250dddf85e2203701d5357f6479001294e64f7d3f28457bc10b55698e0f0c7
5
5
  SHA512:
6
- metadata.gz: 8da35ce898800200e1c8b1dfea8c597c551c713c49a7699d42d0a4222b56e36f8aac189029b4b912a719367292ca5bb4a19b2ccffe661c367162ba66126093e7
7
- data.tar.gz: 01f8fa1c60af82ecd4e5de10dfb56748c97f10aebcb736402a15bcbeec9e6c92e21fb1013ca2d33312b4191b559ed5c92769d83f0de707a361a922521af8e9cb
6
+ metadata.gz: e0975735f7f595af62aeece22cb537e454eef1608b0f012af59e0cc65e14b3015c1db2dd9b7e15402b19bbf1cf564e9982bcd8c79c22681e486d23ae2a96be25
7
+ data.tar.gz: 508d6a5276bfbc8914c9870e4cfa390455ef687634f7de4fc314f28f2c19feedcf7f78de7a39add4543947a44e08e1b0e2de978a1598ac3e8369e5c921c12140
@@ -9,10 +9,3 @@ update_configs:
9
9
  allowed_updates:
10
10
  - match:
11
11
  update_type: "all"
12
- automerged_updates:
13
- - match:
14
- dependency_type: "development"
15
- update_type: "all"
16
- - match:
17
- dependency_type: "production"
18
- update_type: "all"
@@ -1,7 +1,7 @@
1
- # automatically approve PRs submitted by Dependabot
1
+ # automatically approve PRs submitted by Dependabot or Renofidev
2
2
  # this will allow Dependabot to automatically merge dependency update PRs where CI passes
3
3
  # from: https://github.com/hmarr/auto-approve-action
4
- name: Auto approve Dependabot PRs
4
+ name: Auto approve dependency upgrades PRs
5
5
 
6
6
  on:
7
7
  pull_request
@@ -11,6 +11,6 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
13
  - uses: hmarr/auto-approve-action@v2.0.0
14
- if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
14
+ if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' || github.actor == 'renofidev'
15
15
  with:
16
16
  github-token: "${{ secrets.GITHUB_TOKEN }}"
@@ -0,0 +1,10 @@
1
+ # CHANGELOG
2
+
3
+ ## 2.1.0 - 2020-09-14
4
+
5
+ - Add `log_exception_backtrace` option to `RackGraphql::Application`
6
+
7
+ ## 2.0.0 - 2020-09-14
8
+
9
+ - Catch all exceptions raised by the app respond with 500 status codea and json content type
10
+ - Add ability to not log exception backtrace with `RackGraphql.log_exception_backtrace = false`
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (1.2.4)
5
- graphql (~> 1.9)
4
+ rack-graphql (2.1.0)
5
+ graphql (~> 1.11)
6
6
  oj
7
- rack (~> 2.0)
7
+ rack (~> 2.2)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.1)
13
13
  coderay (1.1.3)
14
- diff-lcs (1.3)
15
- graphql (1.11.1)
14
+ diff-lcs (1.4.4)
15
+ graphql (1.11.4)
16
16
  method_source (1.0.0)
17
- oj (3.10.6)
17
+ oj (3.10.14)
18
18
  parallel (1.19.2)
19
- parser (2.7.1.3)
20
- ast (~> 2.4.0)
19
+ parser (2.7.1.4)
20
+ ast (~> 2.4.1)
21
21
  pry (0.13.1)
22
22
  coderay (~> 1.1)
23
23
  method_source (~> 1.0)
@@ -41,21 +41,21 @@ GEM
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
42
  rspec-support (~> 3.9.0)
43
43
  rspec-support (3.9.3)
44
- rubocop (0.85.1)
44
+ rubocop (0.90.0)
45
45
  parallel (~> 1.10)
46
- parser (>= 2.7.0.1)
46
+ parser (>= 2.7.1.1)
47
47
  rainbow (>= 2.2.2, < 4.0)
48
48
  regexp_parser (>= 1.7)
49
49
  rexml
50
- rubocop-ast (>= 0.0.3)
50
+ rubocop-ast (>= 0.3.0, < 1.0)
51
51
  ruby-progressbar (~> 1.7)
52
52
  unicode-display_width (>= 1.4.0, < 2.0)
53
- rubocop-ast (0.0.3)
54
- parser (>= 2.7.0.1)
55
- rubocop-performance (1.6.1)
56
- rubocop (>= 0.71.0)
57
- rubocop-rspec (1.40.0)
58
- rubocop (>= 0.68.1)
53
+ rubocop-ast (0.3.0)
54
+ parser (>= 2.7.1.4)
55
+ rubocop-performance (1.8.0)
56
+ rubocop (>= 0.87.0)
57
+ rubocop-rspec (1.43.2)
58
+ rubocop (~> 0.87)
59
59
  ruby-progressbar (1.10.1)
60
60
  unicode-display_width (1.7.0)
61
61
 
data/README.md CHANGED
@@ -23,10 +23,12 @@ Add following to your `config.ru` file:
23
23
 
24
24
  ```ruby
25
25
  run RackGraphql::Application.call(
26
- schema: YourGraqphqlSchema, # required
27
- app_name: 'your-service-name', # optional, used for health endpoint content
28
- context_handler: YourGraphqlContextHandler, # optional, empty `proc` by default
29
- health_route: true, # optional, true by default
26
+ schema: YourGraqphqlSchema, # required
27
+ app_name: 'your-service-name', # optional, used for health endpoint content
28
+ context_handler: YourGraphqlContextHandler, # optional, empty `proc` by default
29
+ log_exception_backtrace: !A9n.env.production?, # optional, `true` default
30
+ health_route: true, # optional, true by default
31
+ logger: A9n.logger, # optional, not set by default
30
32
  )
31
33
  ```
32
34
 
@@ -69,6 +71,14 @@ class GraphqlContextHandler
69
71
  end
70
72
  ```
71
73
 
74
+ ### Logging exception backtrace
75
+
76
+ RackGraphql catches all errors and respond with 500 code. By default it adds exception backtrace to the response body. If you don't want to have the backtrace in the response set:
77
+
78
+ ```
79
+ RackGraphql.log_exception_backtrace = false
80
+ ```
81
+
72
82
  ## Contributing
73
83
 
74
84
  Bug reports and pull requests are welcome on GitHub at https://github.com/RenoFi/rack-graphql. 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.
@@ -7,3 +7,11 @@ require 'rack_graphql/exceptions'
7
7
  require 'rack_graphql/health_response_builder'
8
8
  require 'rack_graphql/middleware'
9
9
  require 'rack_graphql/application'
10
+
11
+ module RackGraphql
12
+ class << self
13
+ attr_accessor :log_exception_backtrace
14
+ end
15
+
16
+ self.log_exception_backtrace = true
17
+ end
@@ -1,11 +1,18 @@
1
1
  module RackGraphql
2
2
  class Application
3
- def self.call(schema:, app_name: 'rack-graphql-service', logger: nil, context_handler: nil,
4
- health_route: true, health_response_builder: RackGraphql::HealthResponseBuilder)
3
+ def self.call(
4
+ schema:,
5
+ app_name: 'rack-graphql-service',
6
+ logger: nil,
7
+ context_handler: nil,
8
+ log_exception_backtrace: RackGraphql.log_exception_backtrace,
9
+ health_route: true,
10
+ health_response_builder: RackGraphql::HealthResponseBuilder
11
+ )
5
12
 
6
13
  ::Rack::Builder.new do
7
14
  map '/graphql' do
8
- run RackGraphql::Middleware.new(schema: schema, context_handler: context_handler, logger: logger)
15
+ run RackGraphql::Middleware.new(schema: schema, context_handler: context_handler, log_exception_backtrace: log_exception_backtrace, logger: logger)
9
16
  end
10
17
 
11
18
  if health_route
@@ -1,9 +1,10 @@
1
1
  module RackGraphql
2
2
  class Middleware
3
- def initialize(schema:, logger: nil, context_handler: nil)
3
+ def initialize(schema:, logger: nil, context_handler: nil, log_exception_backtrace: RackGraphql.log_exception_backtrace)
4
4
  @schema = schema
5
5
  @logger = logger
6
6
  @context_handler = context_handler || ->(_) {}
7
+ @log_exception_backtrace = log_exception_backtrace
7
8
  end
8
9
 
9
10
  def call(env)
@@ -20,17 +21,40 @@ module RackGraphql
20
21
  log("Executing with params: #{params.inspect}, operationName: #{operation_name}, variables: #{variables.inspect}")
21
22
  result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
22
23
 
23
- [200, response_headers(result), [response_body(result)]]
24
+ [
25
+ 200,
26
+ response_headers(result),
27
+ [response_body(result)]
28
+ ]
24
29
  rescue AmbiguousParamError => e
25
- log("Responded with #{e.class} because of #{e.message}")
26
- [400, { 'Content-Type' => 'application/json' }, [Oj.dump({})]]
30
+ exception_string = dump_exception(e)
31
+ log(exception_string)
32
+ env[Rack::RACK_ERRORS].puts(exception_string)
33
+ env[Rack::RACK_ERRORS].flush
34
+ [
35
+ 400,
36
+ { 'Content-Type' => 'application/json' },
37
+ [Oj.dump({})]
38
+ ]
39
+ rescue StandardError, LoadError, SyntaxError => e
40
+ # To respect the graphql spec, all errors need to be returned as json.
41
+ # It needs to take Rack::ShowExceptions role of catching all exceptions raised by the app.
42
+ exception_string = dump_exception(e)
43
+ log(exception_string)
44
+ env[Rack::RACK_ERRORS].puts(exception_string)
45
+ env[Rack::RACK_ERRORS].flush
46
+ [
47
+ 500,
48
+ { 'Content-Type' => 'application/json' },
49
+ [Oj.dump(errors: [exception_hash(e)])]
50
+ ]
27
51
  ensure
28
52
  ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
29
53
  end
30
54
 
31
55
  private
32
56
 
33
- attr_reader :schema, :logger, :context_handler
57
+ attr_reader :schema, :logger, :context_handler, :log_exception_backtrace
34
58
 
35
59
  def post_request?(env)
36
60
  env['REQUEST_METHOD'] == 'POST'
@@ -124,5 +148,19 @@ module RackGraphql
124
148
  return unless logger
125
149
  logger.debug("[rack-graphql] #{message}")
126
150
  end
151
+
152
+ # Based on https://github.com/rack/rack/blob/master/lib/rack/show_exceptions.rb
153
+ def dump_exception(exception)
154
+ string = "#{exception.class}: #{exception.message}\n"
155
+ string << exception.backtrace.map { |l| "\t#{l}" }.join("\n") if log_exception_backtrace
156
+ string
157
+ end
158
+
159
+ def exception_hash(exception)
160
+ {
161
+ message: "#{exception.class}: #{exception.message}",
162
+ backtrace: log_exception_backtrace ? exception.backtrace : "[FILTERED]"
163
+ }
164
+ end
127
165
  end
128
166
  end
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '1.2.4'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 2.6'
26
26
 
27
- spec.add_dependency 'graphql', '~> 1.9'
27
+ spec.add_dependency 'graphql', '~> 1.11'
28
28
  spec.add_dependency 'oj'
29
- spec.add_dependency 'rack', '~> 2.0'
29
+ spec.add_dependency 'rack', '~> 2.2'
30
30
 
31
31
  spec.add_development_dependency 'bundler'
32
32
  spec.add_development_dependency 'pry'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
8
8
  - RenoFi Engineering Team
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-06-18 00:00:00.000000000 Z
12
+ date: 2020-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.9'
20
+ version: '1.11'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.9'
27
+ version: '1.11'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: oj
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '2.0'
48
+ version: '2.2'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '2.0'
55
+ version: '2.2'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +165,7 @@ dependencies:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
- description:
168
+ description:
169
169
  email:
170
170
  - knapo@knapo.net
171
171
  - engineering@renofi.com
@@ -182,6 +182,7 @@ files:
182
182
  - ".gitignore"
183
183
  - ".rspec"
184
184
  - ".travis.yml"
185
+ - CHANGELOG.md
185
186
  - Gemfile
186
187
  - Gemfile.lock
187
188
  - LICENSE
@@ -201,7 +202,7 @@ licenses:
201
202
  metadata:
202
203
  homepage_uri: https://github.com/RenoFi/rack-graphql
203
204
  source_code_uri: https://github.com/RenoFi/rack-graphql
204
- post_install_message:
205
+ post_install_message:
205
206
  rdoc_options: []
206
207
  require_paths:
207
208
  - lib
@@ -217,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
218
  version: '0'
218
219
  requirements: []
219
220
  rubygems_version: 3.1.2
220
- signing_key:
221
+ signing_key:
221
222
  specification_version: 4
222
223
  summary: Rack middleware implementing graphql endpoint.
223
224
  test_files: []