rack-graphql 2.3.1 → 2.6.1

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: 96ec802b9de117754bdea93534b69eb47be05796d31ecc362d2c1ac32d4ab929
4
- data.tar.gz: f87c56ccc52c047e35ebde5777e7a0ff171e61263c6e58fe1b7312be47e41561
3
+ metadata.gz: 7b053aa44a60a954fb34b510282d975db883c54f3e301778f601cef8cee9f82b
4
+ data.tar.gz: 9ef8753993d89d6a0ac98864b01dd0a89ad8552765930e7ea933e63a9d60fd92
5
5
  SHA512:
6
- metadata.gz: 2637be8f7dc262397347f60d89133cbfb354c3943b7b2e16343bf2ec26cb2ffd127eedfb0a0d255cc29fadff3c02005373539e2325b300b655f000ad6f55dbac
7
- data.tar.gz: 4edf965d3d98f562618479721323adffc7093bdb34efeba9e495af8157e3690855f82d3f0dbcd77b49e4cad38247fe3c43dd6dd14efd8a1282d306e1dd6ddb70
6
+ metadata.gz: 1745f7f487e8a06447184464f9f2b2d97ac6f35dc4224d0122f4ed1f4c3ac37aec268c016db8d36c10f379e84e94e11d9b54a1d1512db07a20ac3684c355b31b
7
+ data.tar.gz: 2518a9c2c8842b34f23a4323b9579276a25a45065ffe97e7a155b3344cf00aadd5b7018c70af4ab9370979bda61dfdab4c5c046e933b2cd7f42ea51a90b77c15
@@ -0,0 +1,19 @@
1
+ name: automerge
2
+ on:
3
+ pull_request_review:
4
+ types:
5
+ - submitted
6
+ check_suite:
7
+ types:
8
+ - completed
9
+ status: {}
10
+ jobs:
11
+ automerge:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: automerge
15
+ uses: "pascalgn/automerge-action@v0.12.0"
16
+ env:
17
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18
+ MERGE_METHOD: squash
19
+ MERGE_DELETE_BRANCH: true
@@ -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,5 +1,21 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.6.0 - 2021-01-14
4
+
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
10
+
11
+ ## 2.5.0 - 2020-11-18
12
+
13
+ - make `log_exception_backtrace` false by default and allow to be controlled by `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var
14
+
15
+ ## 2.4.0 - 2020-09-39
16
+
17
+ - Use `http_status` from `ExecutionError` for http response
18
+
3
19
  ## 2.3.0 - 2020-09-39
4
20
 
5
21
  - Add `error_status_code_map` option to `RackGraphql::Application`.
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.3.1)
5
- graphql (~> 1.11)
4
+ rack-graphql (2.6.1)
5
+ graphql
6
6
  oj
7
7
  rack (~> 2.2)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- ast (2.4.1)
12
+ ast (2.4.2)
13
13
  awesome_print (1.8.0)
14
14
  coderay (1.1.3)
15
15
  diff-lcs (1.4.4)
16
- graphql (1.11.4)
16
+ graphql (1.12.0)
17
17
  method_source (1.0.0)
18
- oj (3.10.14)
19
- parallel (1.19.2)
20
- parser (2.7.1.5)
18
+ oj (3.11.1)
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,43 +26,43 @@ 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.1)
29
+ rake (13.0.3)
30
+ regexp_parser (2.0.3)
31
31
  rexml (3.2.4)
32
- rspec (3.9.0)
33
- rspec-core (~> 3.9.0)
34
- rspec-expectations (~> 3.9.0)
35
- rspec-mocks (~> 3.9.0)
36
- rspec-core (3.9.2)
37
- rspec-support (~> 3.9.3)
38
- rspec-expectations (3.9.2)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.1)
39
39
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.9.0)
41
- rspec-mocks (3.9.1)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.1)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.9.0)
44
- rspec-support (3.9.3)
45
- rubocop (0.92.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.1)
45
+ rubocop (1.8.1)
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.7)
49
+ regexp_parser (>= 1.8, < 3.0)
50
50
  rexml
51
- rubocop-ast (>= 0.5.0)
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 (0.7.1)
53
+ unicode-display_width (>= 1.4.0, < 3.0)
54
+ rubocop-ast (1.4.1)
55
55
  parser (>= 2.7.1.5)
56
- rubocop-performance (1.8.1)
57
- rubocop (>= 0.87.0)
58
- rubocop-ast (>= 0.4.0)
59
- rubocop-rspec (1.43.2)
60
- rubocop (~> 0.87)
61
- ruby-progressbar (1.10.1)
62
- unicode-display_width (1.7.0)
56
+ rubocop-rake (0.5.1)
57
+ rubocop
58
+ rubocop-rspec (2.1.0)
59
+ rubocop (~> 1.0)
60
+ rubocop-ast (>= 1.1.0)
61
+ ruby-progressbar (1.11.0)
62
+ unicode-display_width (2.0.0)
63
63
 
64
64
  PLATFORMS
65
- ruby
65
+ x86_64-darwin-20
66
66
 
67
67
  DEPENDENCIES
68
68
  awesome_print
@@ -73,8 +73,8 @@ DEPENDENCIES
73
73
  rake
74
74
  rspec
75
75
  rubocop
76
- rubocop-performance
76
+ rubocop-rake
77
77
  rubocop-rspec
78
78
 
79
79
  BUNDLED WITH
80
- 2.1.4
80
+ 2.2.4
data/README.md CHANGED
@@ -23,13 +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, `true` default
30
- health_route: true, # optional, true by default
31
- logger: A9n.logger, # optional, not set 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, `false` default
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
32
33
  error_status_code_map: { IamTeapotError => 418 }, # optional
34
+ re_raise_exceptions: true, # optional, false by default
33
35
  )
34
36
  ```
35
37
 
@@ -80,6 +82,39 @@ RackGraphql catches all errors and respond with 500 code. By default it adds exc
80
82
  RackGraphql.log_exception_backtrace = false
81
83
  ```
82
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
+
83
118
  ## Contributing
84
119
 
85
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.
@@ -2,6 +2,10 @@ require 'oj'
2
2
  require 'rack'
3
3
  require 'graphql'
4
4
 
5
+ # Timeout needs to be manually required before following fix is released:
6
+ # https://github.com/rmosolgo/graphql-ruby/commit/56abba472dbb48a1f8445d41f928bea72b5148e9
7
+ require 'timeout'
8
+
5
9
  require 'rack_graphql/version'
6
10
  require 'rack_graphql/exceptions'
7
11
  require 'rack_graphql/health_response_builder'
@@ -10,8 +14,12 @@ require 'rack_graphql/application'
10
14
 
11
15
  module RackGraphql
12
16
  class << self
13
- attr_accessor :log_exception_backtrace
14
- end
17
+ def log_exception_backtrace
18
+ return @log_exception_backtrace unless @log_exception_backtrace.nil?
15
19
 
16
- self.log_exception_backtrace = true
20
+ %w[1 true].include?(ENV['RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE'].to_s)
21
+ end
22
+
23
+ attr_writer :log_exception_backtrace
24
+ end
17
25
  end
@@ -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,
@@ -1,6 +1,8 @@
1
1
  module RackGraphql
2
2
  class Middleware
3
+ DEFAULT_STATUS_CODE = 200
3
4
  DEFAULT_ERROR_STATUS_CODE = 500
5
+ NULL_BYTE = '\u0000'.freeze
4
6
 
5
7
  def initialize(
6
8
  schema:,
@@ -8,6 +10,7 @@ module RackGraphql
8
10
  context_handler: nil,
9
11
  logger: nil,
10
12
  log_exception_backtrace: RackGraphql.log_exception_backtrace,
13
+ re_raise_exceptions: false,
11
14
  error_status_code_map: {}
12
15
  )
13
16
 
@@ -16,6 +19,7 @@ module RackGraphql
16
19
  @context_handler = context_handler || ->(_) {}
17
20
  @logger = logger
18
21
  @log_exception_backtrace = log_exception_backtrace
22
+ @re_raise_exceptions = re_raise_exceptions
19
23
  @error_status_code_map = error_status_code_map
20
24
  end
21
25
 
@@ -34,7 +38,7 @@ module RackGraphql
34
38
  result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
35
39
 
36
40
  [
37
- 200,
41
+ response_status(result),
38
42
  response_headers(result),
39
43
  [response_body(result)]
40
44
  ]
@@ -50,9 +54,14 @@ module RackGraphql
50
54
  ]
51
55
  rescue StandardError, LoadError, SyntaxError => e
52
56
  # To respect the graphql spec, all errors need to be returned as json.
53
- # 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.
54
60
  exception_string = dump_exception(e)
55
61
  log(exception_string)
62
+
63
+ raise e if re_raise_exceptions
64
+
56
65
  env[Rack::RACK_ERRORS].puts(exception_string)
57
66
  env[Rack::RACK_ERRORS].flush
58
67
  [
@@ -66,14 +75,18 @@ module RackGraphql
66
75
 
67
76
  private
68
77
 
69
- 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
70
80
 
71
81
  def post_request?(env)
72
82
  env['REQUEST_METHOD'] == 'POST'
73
83
  end
74
84
 
75
85
  def post_data(env)
76
- ::Oj.load(env['rack.input'].gets.to_s)
86
+ payload = env['rack.input'].read.to_s
87
+ return nil if payload.index(NULL_BYTE)
88
+
89
+ ::Oj.load(payload)
77
90
  rescue Oj::ParseError
78
91
  nil
79
92
  end
@@ -136,6 +149,13 @@ module RackGraphql
136
149
  end
137
150
  end
138
151
 
152
+ def response_status(result)
153
+ return DEFAULT_STATUS_CODE if result.is_a?(Array)
154
+
155
+ errors = result.to_h["errors"] || []
156
+ errors.map { |e| e["http_status"] }.compact.first || DEFAULT_STATUS_CODE
157
+ end
158
+
139
159
  def response_body(result = nil)
140
160
  if result_subscription?(result)
141
161
  body = result.to_h
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.3.1'.freeze
2
+ VERSION = '2.6.1'.freeze
3
3
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.required_ruby_version = '>= 2.6'
27
27
 
28
- spec.add_dependency 'graphql', '~> 1.11'
28
+ spec.add_dependency 'graphql'
29
29
  spec.add_dependency 'oj'
30
30
  spec.add_dependency 'rack', '~> 2.2'
31
31
 
@@ -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.3.1
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-09-30 00:00:00.000000000 Z
12
+ date: 2021-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.11'
20
+ version: '0'
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.11'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: oj
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -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
  - - ">="
@@ -193,6 +193,7 @@ files:
193
193
  - ".github/ISSUE_TEMPLATE/story.md"
194
194
  - ".github/PULL_REQUEST_TEMPLATE.md"
195
195
  - ".github/workflows/auto-approve.yml"
196
+ - ".github/workflows/auto-merge.yml"
196
197
  - ".gitignore"
197
198
  - ".rspec"
198
199
  - ".travis.yml"
@@ -232,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
233
  - !ruby/object:Gem::Version
233
234
  version: '0'
234
235
  requirements: []
235
- rubygems_version: 3.1.2
236
+ rubygems_version: 3.2.3
236
237
  signing_key:
237
238
  specification_version: 4
238
239
  summary: Rack middleware implementing graphql endpoint.