rack-graphql 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/auto-merge.yml +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -2
- data/Gemfile.lock +24 -24
- data/README.md +40 -6
- data/lib/rack_graphql/application.rb +2 -0
- data/lib/rack_graphql/middleware.rb +12 -3
- data/lib/rack_graphql/version.rb +1 -1
- data/rack-graphql.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 845b505da7e26dbe5a9e5065514f0420de0c0394f09692afb6d49a134a35dcc2
|
4
|
+
data.tar.gz: 570b9ce45188d4371f18dd371468f77341535e54f574e06cc184e4e2aaf97adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbc0bbdad9edd52702b4bf7ad70dc46cf592a39e5a47fdb4031f87d1fcb29ca846555a8e05fa0e9620eb198f30212a17169444c6fe53be0a7083941bb8563a83
|
7
|
+
data.tar.gz: 11e95a8121612f0cd206cea8ac3109e02c5cc30a24524b1032b9d378926e0314a8c474b49e6c494a26d489e14f1e444b240c1f61ee330d5784d1d7c29639846e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 2.
|
3
|
+
## 2.6.0 - 2021-01-14
|
4
4
|
|
5
|
-
-
|
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
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-graphql (2.
|
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.
|
19
|
-
parallel (1.20.
|
20
|
-
parser (
|
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.
|
30
|
-
regexp_parser (
|
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.
|
36
|
+
rspec-core (3.10.1)
|
37
37
|
rspec-support (~> 3.10.0)
|
38
|
-
rspec-expectations (3.10.
|
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.
|
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.
|
45
|
-
rubocop (1.
|
44
|
+
rspec-support (3.10.1)
|
45
|
+
rubocop (1.8.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.8)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
50
|
rexml
|
51
|
-
rubocop-ast (>= 1.
|
51
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
52
52
|
ruby-progressbar (~> 1.7)
|
53
|
-
unicode-display_width (>= 1.4.0, <
|
54
|
-
rubocop-ast (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-
|
57
|
-
rubocop
|
58
|
-
|
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.
|
63
|
-
unicode-display_width (
|
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-
|
77
|
+
rubocop-rake
|
78
78
|
rubocop-rspec
|
79
79
|
|
80
80
|
BUNDLED WITH
|
81
|
-
2.
|
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,
|
27
|
-
app_name: 'your-service-name',
|
28
|
-
context_handler: YourGraphqlContextHandler,
|
29
|
-
log_exception_backtrace: !A9n.env.production?,
|
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,
|
32
|
-
logger: A9n.logger,
|
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
|
-
#
|
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,
|
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(
|
87
|
+
return nil if payload.index(NULL_BYTE)
|
79
88
|
|
80
89
|
::Oj.load(payload)
|
81
90
|
rescue Oj::ParseError
|
data/lib/rack_graphql/version.rb
CHANGED
data/rack-graphql.gemspec
CHANGED
@@ -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.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:
|
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-
|
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.
|
236
|
+
rubygems_version: 3.2.3
|
237
237
|
signing_key:
|
238
238
|
specification_version: 4
|
239
239
|
summary: Rack middleware implementing graphql endpoint.
|