rack-graphql 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd612f51ed5029ea31f162ccb63419bbda93203c1c4dc32fd8fe8dc8cb3df296
4
- data.tar.gz: b58c4efcf02014ea60969fdd8d4375c19fa1f0bd143f7b6c1496b2e6f977ac05
3
+ metadata.gz: 845b505da7e26dbe5a9e5065514f0420de0c0394f09692afb6d49a134a35dcc2
4
+ data.tar.gz: 570b9ce45188d4371f18dd371468f77341535e54f574e06cc184e4e2aaf97adc
5
5
  SHA512:
6
- metadata.gz: f8e5816abcb0fc2b487331784dd29b23322a83c788a3f43ac11f02f435d67ed2bc61c9bedc544eb6dabc55376eeaba7d1a2a906f8e4077ad0d488fcce9e24adf
7
- data.tar.gz: a7ab2a91badf6bdf080f023beb4e989a2883308896691fa52512fb2034c33ea93e5ed9deb6216cec43918a3e1d0af5e3d51917adbc0c429a924751271129826f
6
+ metadata.gz: cbc0bbdad9edd52702b4bf7ad70dc46cf592a39e5a47fdb4031f87d1fcb29ca846555a8e05fa0e9620eb198f30212a17169444c6fe53be0a7083941bb8563a83
7
+ data.tar.gz: 11e95a8121612f0cd206cea8ac3109e02c5cc30a24524b1032b9d378926e0314a8c474b49e6c494a26d489e14f1e444b240c1f61ee330d5784d1d7c29639846e
@@ -12,7 +12,7 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  steps:
14
14
  - name: automerge
15
- uses: "pascalgn/automerge-action@v0.11.0"
15
+ uses: "pascalgn/automerge-action@v0.12.0"
16
16
  env:
17
17
  GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18
18
  MERGE_METHOD: squash
@@ -5,6 +5,7 @@ cache: bundler
5
5
  rvm:
6
6
  - 2.6
7
7
  - 2.7
8
+ - 3.0
8
9
  before_install: gem install bundler
9
10
  script:
10
11
  - bundle exec rake rubocop
@@ -1,8 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 2.5.1 - 2020-11-18
3
+ ## 2.6.0 - 2021-01-14
4
4
 
5
- - respond with http status 400 when UTF null byte passed as part of input
5
+ - Add ability to re-raise exception (`re_raise_exceptions` option)
6
+
7
+ ## 2.5.1 - 2020-11-19
8
+
9
+ - respond with http status `400` when UTF null byte is passed as a part of the input
6
10
 
7
11
  ## 2.5.0 - 2020-11-18
8
12
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.5.1)
4
+ rack-graphql (2.6.0)
5
5
  graphql (~> 1.11)
6
6
  oj
7
7
  rack (~> 2.2)
@@ -15,9 +15,9 @@ GEM
15
15
  diff-lcs (1.4.4)
16
16
  graphql (1.11.6)
17
17
  method_source (1.0.0)
18
- oj (3.10.16)
19
- parallel (1.20.0)
20
- parser (2.7.2.0)
18
+ oj (3.11.0)
19
+ parallel (1.20.1)
20
+ parser (3.0.0.0)
21
21
  ast (~> 2.4.1)
22
22
  pry (0.13.1)
23
23
  coderay (~> 1.1)
@@ -26,44 +26,44 @@ GEM
26
26
  rack-test (1.1.0)
27
27
  rack (>= 1.0, < 3)
28
28
  rainbow (3.0.0)
29
- rake (13.0.1)
30
- regexp_parser (1.8.2)
29
+ rake (13.0.3)
30
+ regexp_parser (2.0.3)
31
31
  rexml (3.2.4)
32
32
  rspec (3.10.0)
33
33
  rspec-core (~> 3.10.0)
34
34
  rspec-expectations (~> 3.10.0)
35
35
  rspec-mocks (~> 3.10.0)
36
- rspec-core (3.10.0)
36
+ rspec-core (3.10.1)
37
37
  rspec-support (~> 3.10.0)
38
- rspec-expectations (3.10.0)
38
+ rspec-expectations (3.10.1)
39
39
  diff-lcs (>= 1.2.0, < 2.0)
40
40
  rspec-support (~> 3.10.0)
41
- rspec-mocks (3.10.0)
41
+ rspec-mocks (3.10.1)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
43
  rspec-support (~> 3.10.0)
44
- rspec-support (3.10.0)
45
- rubocop (1.3.1)
44
+ rspec-support (3.10.1)
45
+ rubocop (1.8.0)
46
46
  parallel (~> 1.10)
47
- parser (>= 2.7.1.5)
47
+ parser (>= 3.0.0.0)
48
48
  rainbow (>= 2.2.2, < 4.0)
49
- regexp_parser (>= 1.8)
49
+ regexp_parser (>= 1.8, < 3.0)
50
50
  rexml
51
- rubocop-ast (>= 1.1.1)
51
+ rubocop-ast (>= 1.2.0, < 2.0)
52
52
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (1.1.1)
53
+ unicode-display_width (>= 1.4.0, < 3.0)
54
+ rubocop-ast (1.4.0)
55
55
  parser (>= 2.7.1.5)
56
- rubocop-performance (1.9.0)
57
- rubocop (>= 0.90.0, < 2.0)
58
- rubocop-ast (>= 0.4.0)
59
- rubocop-rspec (2.0.0)
56
+ rubocop-rake (0.5.1)
57
+ rubocop
58
+ rubocop-rspec (2.1.0)
60
59
  rubocop (~> 1.0)
61
60
  rubocop-ast (>= 1.1.0)
62
- ruby-progressbar (1.10.1)
63
- unicode-display_width (1.7.0)
61
+ ruby-progressbar (1.11.0)
62
+ unicode-display_width (2.0.0)
64
63
 
65
64
  PLATFORMS
66
65
  ruby
66
+ x86_64-linux
67
67
 
68
68
  DEPENDENCIES
69
69
  awesome_print
@@ -74,8 +74,8 @@ DEPENDENCIES
74
74
  rake
75
75
  rspec
76
76
  rubocop
77
- rubocop-performance
77
+ rubocop-rake
78
78
  rubocop-rspec
79
79
 
80
80
  BUNDLED WITH
81
- 2.1.4
81
+ 2.2.4
data/README.md CHANGED
@@ -23,14 +23,15 @@ 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
- log_exception_backtrace: !A9n.env.production?, # optional, `false` 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, `false` default
30
30
  # `true` when `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var is set to `'1'` or `'true'`
31
- health_route: true, # optional, true by default
32
- logger: A9n.logger, # optional, not set by default
31
+ health_route: true, # optional, true by default
32
+ logger: A9n.logger, # optional, not set by default
33
33
  error_status_code_map: { IamTeapotError => 418 }, # optional
34
+ re_raise_exceptions: true, # optional, false by default
34
35
  )
35
36
  ```
36
37
 
@@ -81,6 +82,39 @@ RackGraphql catches all errors and respond with 500 code. By default it adds exc
81
82
  RackGraphql.log_exception_backtrace = false
82
83
  ```
83
84
 
85
+ ### Error tracking/reporting
86
+
87
+ To respect the graphql spec, all errors need to be returned as json and `rack-graphql` catches all exceptions and does NOT re-raise them. You can change this behavior via `re_raise_exceptions` argument.
88
+ Because of this, using error tracking middleware (`use Sentry::Rack::CaptureExceptions`, `use Raven::Rack`) does not take any effect for graphql requests.
89
+
90
+ To use Sentry or other reporting tool for graphql queries, you can use `GraphQL::Schema` middleware:
91
+
92
+ ```ruby
93
+ class GraphqlErrorTrackerMiddleware
94
+ def self.call(parent_type, parent_object, field_definition, field_args, query_context)
95
+ yield
96
+ rescue StandardError => e
97
+ extra = {
98
+ parent_type: parent_type.inspect,
99
+ parent_object: parent_object.inspect,
100
+ field_definition: field_definition.to_s,
101
+ field_args: field_args&.to_h,
102
+ query_context: query_context&.to_h
103
+ }
104
+ Sentry.capture_exception(e, extra: extra)
105
+ raise
106
+ end
107
+ end
108
+
109
+ # MySchema.middleware GraphqlErrorTrackerMiddleware
110
+ # or
111
+ # GraphQL::Schema.middleware GraphqlErrorTrackerMiddleware
112
+ # or
113
+ # class MySchema < GraphQL::Schema
114
+ # middleware GraphqlErrorTrackerMiddleware
115
+ # end
116
+ ```
117
+
84
118
  ## Contributing
85
119
 
86
120
  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.
@@ -5,6 +5,7 @@ module RackGraphql
5
5
  app_name: 'rack-graphql-service',
6
6
  logger: nil,
7
7
  context_handler: nil,
8
+ re_raise_exceptions: false,
8
9
  log_exception_backtrace: RackGraphql.log_exception_backtrace,
9
10
  health_route: true,
10
11
  health_response_builder: RackGraphql::HealthResponseBuilder,
@@ -17,6 +18,7 @@ module RackGraphql
17
18
  app_name: app_name,
18
19
  schema: schema,
19
20
  context_handler: context_handler,
21
+ re_raise_exceptions: re_raise_exceptions,
20
22
  logger: logger,
21
23
  log_exception_backtrace: log_exception_backtrace,
22
24
  error_status_code_map: error_status_code_map,
@@ -2,6 +2,7 @@ module RackGraphql
2
2
  class Middleware
3
3
  DEFAULT_STATUS_CODE = 200
4
4
  DEFAULT_ERROR_STATUS_CODE = 500
5
+ NULL_BYTE = '\u0000'.freeze
5
6
 
6
7
  def initialize(
7
8
  schema:,
@@ -9,6 +10,7 @@ module RackGraphql
9
10
  context_handler: nil,
10
11
  logger: nil,
11
12
  log_exception_backtrace: RackGraphql.log_exception_backtrace,
13
+ re_raise_exceptions: false,
12
14
  error_status_code_map: {}
13
15
  )
14
16
 
@@ -17,6 +19,7 @@ module RackGraphql
17
19
  @context_handler = context_handler || ->(_) {}
18
20
  @logger = logger
19
21
  @log_exception_backtrace = log_exception_backtrace
22
+ @re_raise_exceptions = re_raise_exceptions
20
23
  @error_status_code_map = error_status_code_map
21
24
  end
22
25
 
@@ -51,9 +54,14 @@ module RackGraphql
51
54
  ]
52
55
  rescue StandardError, LoadError, SyntaxError => e
53
56
  # To respect the graphql spec, all errors need to be returned as json.
54
- # It needs to take Rack::ShowExceptions role of catching all exceptions raised by the app.
57
+ # By default exceptions are not re-raised,
58
+ # so they cannot be caught by error tracking rack middlewares.
59
+ # You can change this behavior via `re_raise_exceptions` argument.
55
60
  exception_string = dump_exception(e)
56
61
  log(exception_string)
62
+
63
+ raise e if re_raise_exceptions
64
+
57
65
  env[Rack::RACK_ERRORS].puts(exception_string)
58
66
  env[Rack::RACK_ERRORS].flush
59
67
  [
@@ -67,7 +75,8 @@ module RackGraphql
67
75
 
68
76
  private
69
77
 
70
- attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace, :error_status_code_map
78
+ attr_reader :schema, :app_name, :logger, :context_handler,
79
+ :log_exception_backtrace, :error_status_code_map, :re_raise_exceptions
71
80
 
72
81
  def post_request?(env)
73
82
  env['REQUEST_METHOD'] == 'POST'
@@ -75,7 +84,7 @@ module RackGraphql
75
84
 
76
85
  def post_data(env)
77
86
  payload = env['rack.input'].read.to_s
78
- return nil if payload.index('\u0000')
87
+ return nil if payload.index(NULL_BYTE)
79
88
 
80
89
  ::Oj.load(payload)
81
90
  rescue Oj::ParseError
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.5.1'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  end
@@ -36,6 +36,6 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'rake'
37
37
  spec.add_development_dependency 'rspec'
38
38
  spec.add_development_dependency 'rubocop'
39
- spec.add_development_dependency 'rubocop-performance'
39
+ spec.add_development_dependency 'rubocop-rake'
40
40
  spec.add_development_dependency 'rubocop-rspec'
41
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-11-19 00:00:00.000000000 Z
12
+ date: 2021-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -152,7 +152,7 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: rubocop-performance
155
+ name: rubocop-rake
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
- rubygems_version: 3.1.4
236
+ rubygems_version: 3.2.3
237
237
  signing_key:
238
238
  specification_version: 4
239
239
  summary: Rack middleware implementing graphql endpoint.