rack-graphql 2.4.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundler-version +1 -0
- data/.dependabot/config.yml +7 -2
- data/.github/workflows/auto-merge.yml +19 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +39 -38
- data/README.md +41 -6
- data/lib/rack_graphql.rb +11 -3
- data/lib/rack_graphql/application.rb +5 -0
- data/lib/rack_graphql/middleware.rb +15 -3
- data/lib/rack_graphql/version.rb +1 -1
- data/rack-graphql.gemspec +2 -2
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0aed325620504c52731b38726309a1633831e5af42af1f2a42b9a85e1c7b662
|
4
|
+
data.tar.gz: df13c1c063bab50027908d4c44f0ecc242fca1bf6d7485e1fadb69a2e9dddbac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ca07400a4d7229462f720310d9da3a734c91ca78318bcba122734d8983cae935563488c1e146f19a991d3a1890be740ba6f752fb6ef0babeca791f188bed3b
|
7
|
+
data.tar.gz: 571b478112fd84ae108c78afd17a1e48a7163d8c2c2b582824ec9b2bdb1057aaa934a9a12f9a0dadfa6fe0008a80391e5d210970cc7736bfcfee173b09757ca6
|
data/.bundler-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.14
|
data/.dependabot/config.yml
CHANGED
@@ -3,9 +3,14 @@ version: 1
|
|
3
3
|
update_configs:
|
4
4
|
- package_manager: "ruby:bundler"
|
5
5
|
directory: "/"
|
6
|
-
update_schedule: "
|
6
|
+
update_schedule: "daily"
|
7
7
|
commit_message:
|
8
8
|
prefix: "[dependabot]"
|
9
9
|
allowed_updates:
|
10
10
|
- match:
|
11
|
-
|
11
|
+
dependency_type: "all"
|
12
|
+
update_type: "security"
|
13
|
+
automerged_updates:
|
14
|
+
- match:
|
15
|
+
dependency_type: "all"
|
16
|
+
update_type: "security:patch"
|
@@ -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
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.7.0 - 2021-03-24
|
4
|
+
|
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
|
18
|
+
|
19
|
+
## 2.5.0 - 2020-11-18
|
20
|
+
|
21
|
+
- make `log_exception_backtrace` false by default and allow to be controlled by `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var
|
22
|
+
|
3
23
|
## 2.4.0 - 2020-09-39
|
4
24
|
|
5
25
|
- Use `http_status` from `ExecutionError` for http response
|
data/Gemfile.lock
CHANGED
@@ -1,68 +1,69 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-graphql (2.
|
5
|
-
graphql
|
4
|
+
rack-graphql (2.7.0)
|
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.
|
13
|
-
awesome_print (1.
|
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.
|
16
|
+
graphql (1.12.6)
|
17
17
|
method_source (1.0.0)
|
18
|
-
oj (3.
|
19
|
-
parallel (1.
|
20
|
-
parser (
|
18
|
+
oj (3.11.3)
|
19
|
+
parallel (1.20.1)
|
20
|
+
parser (3.0.0.0)
|
21
21
|
ast (~> 2.4.1)
|
22
|
-
pry (0.
|
22
|
+
pry (0.14.0)
|
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.
|
30
|
-
regexp_parser (1.
|
29
|
+
rake (13.0.3)
|
30
|
+
regexp_parser (2.1.1)
|
31
31
|
rexml (3.2.4)
|
32
|
-
rspec (3.
|
33
|
-
rspec-core (~> 3.
|
34
|
-
rspec-expectations (~> 3.
|
35
|
-
rspec-mocks (~> 3.
|
36
|
-
rspec-core (3.
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-expectations (3.
|
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.
|
41
|
-
rspec-mocks (3.
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-mocks (3.10.2)
|
42
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-support (3.
|
45
|
-
rubocop (
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-support (3.10.2)
|
45
|
+
rubocop (1.11.0)
|
46
46
|
parallel (~> 1.10)
|
47
|
-
parser (>=
|
47
|
+
parser (>= 3.0.0.0)
|
48
48
|
rainbow (>= 2.2.2, < 4.0)
|
49
|
-
regexp_parser (>= 1.
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
50
|
rexml
|
51
|
-
rubocop-ast (>=
|
51
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
52
52
|
ruby-progressbar (~> 1.7)
|
53
|
-
unicode-display_width (>= 1.4.0, <
|
54
|
-
rubocop-ast (
|
53
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.4.1)
|
55
55
|
parser (>= 2.7.1.5)
|
56
|
-
rubocop-
|
57
|
-
rubocop
|
58
|
-
|
59
|
-
|
60
|
-
rubocop (
|
61
|
-
ruby-progressbar (1.
|
62
|
-
unicode-display_width (
|
56
|
+
rubocop-rake (0.5.1)
|
57
|
+
rubocop
|
58
|
+
rubocop-rspec (2.2.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
|
-
|
65
|
+
x86_64-darwin-20
|
66
|
+
x86_64-linux
|
66
67
|
|
67
68
|
DEPENDENCIES
|
68
69
|
awesome_print
|
@@ -73,8 +74,8 @@ DEPENDENCIES
|
|
73
74
|
rake
|
74
75
|
rspec
|
75
76
|
rubocop
|
76
|
-
rubocop-
|
77
|
+
rubocop-rake
|
77
78
|
rubocop-rspec
|
78
79
|
|
79
80
|
BUNDLED WITH
|
80
|
-
2.
|
81
|
+
2.2.15
|
data/README.md
CHANGED
@@ -23,13 +23,16 @@ Add following to your `config.ru` file:
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
run RackGraphql::Application.call(
|
26
|
-
schema: YourGraqphqlSchema,
|
27
|
-
app_name: 'your-service-name',
|
28
|
-
context_handler: YourGraphqlContextHandler,
|
29
|
-
log_exception_backtrace: !A9n.env.production?,
|
30
|
-
|
31
|
-
|
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
|
+
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
|
32
34
|
error_status_code_map: { IamTeapotError => 418 }, # optional
|
35
|
+
re_raise_exceptions: true, # optional, false by default
|
33
36
|
)
|
34
37
|
```
|
35
38
|
|
@@ -80,6 +83,38 @@ RackGraphql catches all errors and respond with 500 code. By default it adds exc
|
|
80
83
|
RackGraphql.log_exception_backtrace = false
|
81
84
|
```
|
82
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
|
+
|
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.
|
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'
|
@@ -10,8 +14,12 @@ require 'rack_graphql/application'
|
|
10
14
|
|
11
15
|
module RackGraphql
|
12
16
|
class << self
|
13
|
-
|
14
|
-
|
17
|
+
def log_exception_backtrace
|
18
|
+
return @log_exception_backtrace unless @log_exception_backtrace.nil?
|
15
19
|
|
16
|
-
|
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,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
|
-
#
|
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,14 +75,18 @@ module RackGraphql
|
|
67
75
|
|
68
76
|
private
|
69
77
|
|
70
|
-
attr_reader :schema, :app_name, :logger, :context_handler,
|
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'
|
74
83
|
end
|
75
84
|
|
76
85
|
def post_data(env)
|
77
|
-
|
86
|
+
payload = env['rack.input'].read.to_s
|
87
|
+
return nil if payload.index(NULL_BYTE)
|
88
|
+
|
89
|
+
::Oj.load(payload)
|
78
90
|
rescue Oj::ParseError
|
79
91
|
nil
|
80
92
|
end
|
data/lib/rack_graphql/version.rb
CHANGED
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'
|
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-
|
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.
|
4
|
+
version: 2.7.0
|
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:
|
12
|
+
date: 2021-03-24 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: '
|
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: '
|
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-
|
155
|
+
name: rubocop-rake
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
@@ -187,12 +187,14 @@ 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"
|
193
194
|
- ".github/ISSUE_TEMPLATE/story.md"
|
194
195
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
195
196
|
- ".github/workflows/auto-approve.yml"
|
197
|
+
- ".github/workflows/auto-merge.yml"
|
196
198
|
- ".gitignore"
|
197
199
|
- ".rspec"
|
198
200
|
- ".travis.yml"
|
@@ -232,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
232
234
|
- !ruby/object:Gem::Version
|
233
235
|
version: '0'
|
234
236
|
requirements: []
|
235
|
-
rubygems_version: 3.
|
237
|
+
rubygems_version: 3.2.15
|
236
238
|
signing_key:
|
237
239
|
specification_version: 4
|
238
240
|
summary: Rack middleware implementing graphql endpoint.
|