rack-graphql 2.5.1 → 2.7.1

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: bd612f51ed5029ea31f162ccb63419bbda93203c1c4dc32fd8fe8dc8cb3df296
4
- data.tar.gz: b58c4efcf02014ea60969fdd8d4375c19fa1f0bd143f7b6c1496b2e6f977ac05
3
+ metadata.gz: e93e42e089512fb66fd31d4ee5927904e795b98729b7e61819c85062d1bbe05d
4
+ data.tar.gz: 01156f4ddac5d400a610aedb10eba7cf7b15f35ae54b2379e5a3cee812128c68
5
5
  SHA512:
6
- metadata.gz: f8e5816abcb0fc2b487331784dd29b23322a83c788a3f43ac11f02f435d67ed2bc61c9bedc544eb6dabc55376eeaba7d1a2a906f8e4077ad0d488fcce9e24adf
7
- data.tar.gz: a7ab2a91badf6bdf080f023beb4e989a2883308896691fa52512fb2034c33ea93e5ed9deb6216cec43918a3e1d0af5e3d51917adbc0c429a924751271129826f
6
+ metadata.gz: 19716823cf60ebd465c7c9d7927f2b03bc54c0c07e0ffe14105548af9effd090f5ae98df3a50efbf6bd59a54d1823181c6e5669accf5ef291e1a28850d7b4e42
7
+ data.tar.gz: 60b7edf7e00f84c5f83a7d10f03706660a5dd9b9e95dd3954b2e405c72814c10950c375bbfad2ac2e71043aa7cb79b6f5cfa34fea17949d1638d8e6c5185ab91
data/.bundler-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.29
@@ -3,9 +3,14 @@ version: 1
3
3
  update_configs:
4
4
  - package_manager: "ruby:bundler"
5
5
  directory: "/"
6
- update_schedule: "monthly"
6
+ update_schedule: "daily"
7
7
  commit_message:
8
8
  prefix: "[dependabot]"
9
9
  allowed_updates:
10
10
  - match:
11
- update_type: "all"
11
+ dependency_type: "all"
12
+ update_type: "security"
13
+ automerged_updates:
14
+ - match:
15
+ dependency_type: "all"
16
+ update_type: "security:patch"
@@ -1,18 +1,6 @@
1
- ## Description
1
+ ## Description, motivation and context
2
2
  <!--- Describe your changes in detail -->
3
-
4
- ## Related issue(s)
5
- <!--- GH issue number -->
6
-
7
- ## Motivation and Context
8
3
  <!--- Why is this change required? What problem does it solve? -->
9
- <!--- If it fixes an open issue, please link to the issue here. -->
10
4
 
11
- ## How Has This Been Tested?
12
- <!--- Please describe in detail how you tested your changes. -->
13
-
14
- ## Screenshots (if appropriate):
15
- <!--- Please add any screenshots of the feature. -->
16
-
17
- ## Related PRs
18
- <!--- Please add links to any related PRs (backend, component packages, etc). -->
5
+ ## Related issue(s) or PR(s)
6
+ <!--- GH issue number -->
@@ -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
@@ -0,0 +1,28 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.7', '3.0']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby
19
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
20
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
21
+ # uses: ruby/setup-ruby@v1
22
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
26
+
27
+ - name: Run tests
28
+ run: bundle exec rake ci
data/CHANGELOG.md CHANGED
@@ -1,8 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 2.5.1 - 2020-11-18
3
+ ## 2.7.0 - 2021-03-24
4
4
 
5
- - respond with http status 400 when UTF null byte passed as part of input
5
+ - Add ability to skip setting up health endpoint on root path with `health_on_root_path` option.
6
+
7
+ ## 2.6.1 - 2021-01-14
8
+
9
+ - Fix uninitialized `Timeout` error. The issue was fixed in https://github.com/rmosolgo/graphql-ruby/commit/56abba472dbb48a1f8445d41f928bea72b5148e9, but new version has not yet been relased.
10
+
11
+ ## 2.6.0 - 2021-01-14
12
+
13
+ - Add ability to re-raise exception (`re_raise_exceptions` option)
14
+
15
+ ## 2.5.1 - 2020-11-19
16
+
17
+ - respond with http status `400` when UTF null byte is passed as a part of the input
6
18
 
7
19
  ## 2.5.0 - 2020-11-18
8
20
 
data/Gemfile.lock CHANGED
@@ -1,69 +1,71 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.5.1)
5
- graphql (~> 1.11)
4
+ rack-graphql (2.7.1)
5
+ graphql (~> 1.12)
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)
13
- awesome_print (1.8.0)
12
+ ast (2.4.2)
13
+ awesome_print (1.9.2)
14
14
  coderay (1.1.3)
15
15
  diff-lcs (1.4.4)
16
- graphql (1.11.6)
16
+ graphql (1.12.17)
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.13.9)
19
+ parallel (1.21.0)
20
+ parser (3.0.2.0)
21
21
  ast (~> 2.4.1)
22
- pry (0.13.1)
22
+ pry (0.14.1)
23
23
  coderay (~> 1.1)
24
24
  method_source (~> 1.0)
25
25
  rack (2.2.3)
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)
31
- rexml (3.2.4)
29
+ rake (13.0.6)
30
+ regexp_parser (2.1.1)
31
+ rexml (3.2.5)
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.2)
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.2)
45
+ rubocop (1.22.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.8)
49
+ regexp_parser (>= 1.8, < 3.0)
50
50
  rexml
51
- rubocop-ast (>= 1.1.1)
51
+ rubocop-ast (>= 1.12.0, < 2.0)
52
52
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (1.1.1)
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)
53
+ unicode-display_width (>= 1.4.0, < 3.0)
54
+ rubocop-ast (1.12.0)
55
+ parser (>= 3.0.1.1)
56
+ rubocop-rake (0.6.0)
60
57
  rubocop (~> 1.0)
61
- rubocop-ast (>= 1.1.0)
62
- ruby-progressbar (1.10.1)
63
- unicode-display_width (1.7.0)
58
+ rubocop-rspec (2.5.0)
59
+ rubocop (~> 1.19)
60
+ ruby-progressbar (1.11.0)
61
+ unicode-display_width (2.1.0)
64
62
 
65
63
  PLATFORMS
66
- ruby
64
+ aarch64-linux-musl
65
+ x86_64-darwin-18
66
+ x86_64-darwin-19
67
+ x86_64-darwin-20
68
+ x86_64-linux
67
69
 
68
70
  DEPENDENCIES
69
71
  awesome_print
@@ -74,8 +76,8 @@ DEPENDENCIES
74
76
  rake
75
77
  rspec
76
78
  rubocop
77
- rubocop-performance
79
+ rubocop-rake
78
80
  rubocop-rspec
79
81
 
80
82
  BUNDLED WITH
81
- 2.1.4
83
+ 2.2.29
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/rack-graphql.svg)](https://rubygems.org/gems/rack-graphql)
2
- [![Build Status](https://travis-ci.org/RenoFi/rack-graphql.svg?branch=master)](https://travis-ci.org/RenoFi/rack-graphql)
2
+ [![Build Status](https://github.com/RenoFi/rack-graphql/actions/workflows/ci.yml/badge.svg)](https://github.com/RenoFi/rack-graphql/actions/workflows/ci.yml?query=branch%3Amain)
3
3
 
4
4
  # rack-graphql
5
5
 
@@ -23,14 +23,16 @@ 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
+ health_on_root_path: health_route, # optional, health_route value by default (mind map '/' is covering '/any/path-123')
33
+ logger: A9n.logger, # optional, not set by default
33
34
  error_status_code_map: { IamTeapotError => 418 }, # optional
35
+ re_raise_exceptions: true, # optional, false by default
34
36
  )
35
37
  ```
36
38
 
@@ -81,6 +83,38 @@ RackGraphql catches all errors and respond with 500 code. By default it adds exc
81
83
  RackGraphql.log_exception_backtrace = false
82
84
  ```
83
85
 
86
+ ### Error tracking/reporting
87
+
88
+ 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.
89
+ Because of this, using error tracking middleware (`use Sentry::Rack::CaptureExceptions`, `use Raven::Rack`) does not take any effect for graphql requests.
90
+
91
+ To use Sentry or other reporting tool for graphql queries, you should handle it on graphql schema level:
92
+
93
+ ```ruby
94
+ class MySchema < GraphQL::Schema
95
+ rescue_from StandardError do |e, obj, args, ctx, field|
96
+ extra = {
97
+ args: args,
98
+ field: field.inspect,
99
+ context: ctx
100
+ }
101
+ Sentry.capture_exception(e, extra: extra)
102
+ # re-raise to be handled by rack middleware
103
+ raise
104
+ # or return execution error
105
+ ::GraphQL::ExecutionError.new(
106
+ exception.class.to_s,
107
+ options: { "http_status" => 500 },
108
+ extensions: {
109
+ "code" => exception.class.to_s,
110
+ "http_status" => 500,
111
+ "details" => exception.inspect
112
+ }
113
+ )
114
+ end
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.
data/Rakefile CHANGED
@@ -5,4 +5,5 @@ require 'rubocop/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  RuboCop::RakeTask.new
7
7
 
8
+ task ci: %i[spec rubocop]
8
9
  task default: %i[spec rubocop:auto_correct]
@@ -5,9 +5,11 @@ 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,
12
+ health_on_root_path: health_route,
11
13
  error_status_code_map: {}
12
14
  )
13
15
 
@@ -17,6 +19,7 @@ module RackGraphql
17
19
  app_name: app_name,
18
20
  schema: schema,
19
21
  context_handler: context_handler,
22
+ re_raise_exceptions: re_raise_exceptions,
20
23
  logger: logger,
21
24
  log_exception_backtrace: log_exception_backtrace,
22
25
  error_status_code_map: error_status_code_map,
@@ -31,7 +34,9 @@ module RackGraphql
31
34
  map '/healthz' do
32
35
  run ->(env) { health_response_builder.new(app_name: app_name, env: env).build }
33
36
  end
37
+ end
34
38
 
39
+ if health_on_root_path
35
40
  map '/' do
36
41
  run ->(env) { health_response_builder.new(app_name: app_name, env: env).build }
37
42
  end
@@ -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.7.1'.freeze
3
3
  end
data/lib/rack_graphql.rb CHANGED
@@ -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'
data/rack-graphql.gemspec CHANGED
@@ -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', '~> 1.12'
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.5.1
4
+ version: 2.7.1
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-10-17 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.11'
20
+ version: '1.12'
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: '1.12'
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
  - - ">="
@@ -187,6 +187,7 @@ executables: []
187
187
  extensions: []
188
188
  extra_rdoc_files: []
189
189
  files:
190
+ - ".bundler-version"
190
191
  - ".dependabot/config.yml"
191
192
  - ".github/ISSUE_TEMPLATE/bug_report.md"
192
193
  - ".github/ISSUE_TEMPLATE/config.yml"
@@ -194,9 +195,9 @@ files:
194
195
  - ".github/PULL_REQUEST_TEMPLATE.md"
195
196
  - ".github/workflows/auto-approve.yml"
196
197
  - ".github/workflows/auto-merge.yml"
198
+ - ".github/workflows/ci.yml"
197
199
  - ".gitignore"
198
200
  - ".rspec"
199
- - ".travis.yml"
200
201
  - CHANGELOG.md
201
202
  - Gemfile
202
203
  - Gemfile.lock
@@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
234
  - !ruby/object:Gem::Version
234
235
  version: '0'
235
236
  requirements: []
236
- rubygems_version: 3.1.4
237
+ rubygems_version: 3.2.23
237
238
  signing_key:
238
239
  specification_version: 4
239
240
  summary: Rack middleware implementing graphql endpoint.
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6
7
- - 2.7
8
- before_install: gem install bundler
9
- script:
10
- - bundle exec rake rubocop
11
- - bundle exec rake spec