rack-graphql 2.0.0 → 2.3.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 +4 -4
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +12 -9
- data/README.md +7 -5
- data/Rakefile +1 -1
- data/lib/rack_graphql/application.rb +18 -3
- data/lib/rack_graphql/middleware.rb +22 -8
- data/lib/rack_graphql/version.rb +1 -1
- data/rack-graphql.gemspec +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96ec802b9de117754bdea93534b69eb47be05796d31ecc362d2c1ac32d4ab929
|
|
4
|
+
data.tar.gz: f87c56ccc52c047e35ebde5777e7a0ff171e61263c6e58fe1b7312be47e41561
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2637be8f7dc262397347f60d89133cbfb354c3943b7b2e16343bf2ec26cb2ffd127eedfb0a0d255cc29fadff3c02005373539e2325b300b655f000ad6f55dbac
|
|
7
|
+
data.tar.gz: 4edf965d3d98f562618479721323adffc7093bdb34efeba9e495af8157e3690855f82d3f0dbcd77b49e4cad38247fe3c43dd6dd14efd8a1282d306e1dd6ddb70
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 2.3.0 - 2020-09-39
|
|
4
|
+
|
|
5
|
+
- Add `error_status_code_map` option to `RackGraphql::Application`.
|
|
6
|
+
|
|
7
|
+
`error_status_code_map` allows for return custom http code when specific errors are raised.
|
|
8
|
+
|
|
9
|
+
## 2.2.1 - 2020-09-14
|
|
10
|
+
|
|
11
|
+
- Rename `source_app` to `app_name` in error payload.
|
|
12
|
+
|
|
13
|
+
## 2.2.0 - 2020-09-14
|
|
14
|
+
|
|
15
|
+
- Add `source_app` to error payload.
|
|
16
|
+
|
|
17
|
+
## 2.1.0 - 2020-09-14
|
|
18
|
+
|
|
19
|
+
- Add `log_exception_backtrace` option to `RackGraphql::Application`
|
|
20
|
+
|
|
3
21
|
## 2.0.0 - 2020-09-14
|
|
4
22
|
|
|
5
23
|
- Catch all exceptions raised by the app respond with 500 status codea and json content type
|
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.3.1)
|
|
5
5
|
graphql (~> 1.11)
|
|
6
6
|
oj
|
|
7
7
|
rack (~> 2.2)
|
|
@@ -10,13 +10,14 @@ GEM
|
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
12
|
ast (2.4.1)
|
|
13
|
+
awesome_print (1.8.0)
|
|
13
14
|
coderay (1.1.3)
|
|
14
15
|
diff-lcs (1.4.4)
|
|
15
16
|
graphql (1.11.4)
|
|
16
17
|
method_source (1.0.0)
|
|
17
18
|
oj (3.10.14)
|
|
18
19
|
parallel (1.19.2)
|
|
19
|
-
parser (2.7.1.
|
|
20
|
+
parser (2.7.1.5)
|
|
20
21
|
ast (~> 2.4.1)
|
|
21
22
|
pry (0.13.1)
|
|
22
23
|
coderay (~> 1.1)
|
|
@@ -26,7 +27,7 @@ GEM
|
|
|
26
27
|
rack (>= 1.0, < 3)
|
|
27
28
|
rainbow (3.0.0)
|
|
28
29
|
rake (13.0.1)
|
|
29
|
-
regexp_parser (1.
|
|
30
|
+
regexp_parser (1.8.1)
|
|
30
31
|
rexml (3.2.4)
|
|
31
32
|
rspec (3.9.0)
|
|
32
33
|
rspec-core (~> 3.9.0)
|
|
@@ -41,19 +42,20 @@ GEM
|
|
|
41
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
42
43
|
rspec-support (~> 3.9.0)
|
|
43
44
|
rspec-support (3.9.3)
|
|
44
|
-
rubocop (0.
|
|
45
|
+
rubocop (0.92.0)
|
|
45
46
|
parallel (~> 1.10)
|
|
46
|
-
parser (>= 2.7.1.
|
|
47
|
+
parser (>= 2.7.1.5)
|
|
47
48
|
rainbow (>= 2.2.2, < 4.0)
|
|
48
49
|
regexp_parser (>= 1.7)
|
|
49
50
|
rexml
|
|
50
|
-
rubocop-ast (>= 0.
|
|
51
|
+
rubocop-ast (>= 0.5.0)
|
|
51
52
|
ruby-progressbar (~> 1.7)
|
|
52
53
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
53
|
-
rubocop-ast (0.
|
|
54
|
-
parser (>= 2.7.1.
|
|
55
|
-
rubocop-performance (1.8.
|
|
54
|
+
rubocop-ast (0.7.1)
|
|
55
|
+
parser (>= 2.7.1.5)
|
|
56
|
+
rubocop-performance (1.8.1)
|
|
56
57
|
rubocop (>= 0.87.0)
|
|
58
|
+
rubocop-ast (>= 0.4.0)
|
|
57
59
|
rubocop-rspec (1.43.2)
|
|
58
60
|
rubocop (~> 0.87)
|
|
59
61
|
ruby-progressbar (1.10.1)
|
|
@@ -63,6 +65,7 @@ PLATFORMS
|
|
|
63
65
|
ruby
|
|
64
66
|
|
|
65
67
|
DEPENDENCIES
|
|
68
|
+
awesome_print
|
|
66
69
|
bundler
|
|
67
70
|
pry
|
|
68
71
|
rack-graphql!
|
data/README.md
CHANGED
|
@@ -23,11 +23,13 @@ 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
|
-
|
|
30
|
-
|
|
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
|
|
32
|
+
error_status_code_map: { IamTeapotError => 418 }, # optional
|
|
31
33
|
)
|
|
32
34
|
```
|
|
33
35
|
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
module RackGraphql
|
|
2
2
|
class Application
|
|
3
|
-
def self.call(
|
|
4
|
-
|
|
3
|
+
def self.call(
|
|
4
|
+
schema:,
|
|
5
|
+
app_name: 'rack-graphql-service',
|
|
6
|
+
logger: nil,
|
|
7
|
+
context_handler: nil,
|
|
8
|
+
log_exception_backtrace: RackGraphql.log_exception_backtrace,
|
|
9
|
+
health_route: true,
|
|
10
|
+
health_response_builder: RackGraphql::HealthResponseBuilder,
|
|
11
|
+
error_status_code_map: {}
|
|
12
|
+
)
|
|
5
13
|
|
|
6
14
|
::Rack::Builder.new do
|
|
7
15
|
map '/graphql' do
|
|
8
|
-
run RackGraphql::Middleware.new(
|
|
16
|
+
run RackGraphql::Middleware.new(
|
|
17
|
+
app_name: app_name,
|
|
18
|
+
schema: schema,
|
|
19
|
+
context_handler: context_handler,
|
|
20
|
+
logger: logger,
|
|
21
|
+
log_exception_backtrace: log_exception_backtrace,
|
|
22
|
+
error_status_code_map: error_status_code_map,
|
|
23
|
+
)
|
|
9
24
|
end
|
|
10
25
|
|
|
11
26
|
if health_route
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
module RackGraphql
|
|
2
2
|
class Middleware
|
|
3
|
-
|
|
3
|
+
DEFAULT_ERROR_STATUS_CODE = 500
|
|
4
|
+
|
|
5
|
+
def initialize(
|
|
6
|
+
schema:,
|
|
7
|
+
app_name: nil,
|
|
8
|
+
context_handler: nil,
|
|
9
|
+
logger: nil,
|
|
10
|
+
log_exception_backtrace: RackGraphql.log_exception_backtrace,
|
|
11
|
+
error_status_code_map: {}
|
|
12
|
+
)
|
|
13
|
+
|
|
4
14
|
@schema = schema
|
|
5
|
-
@
|
|
15
|
+
@app_name = app_name
|
|
6
16
|
@context_handler = context_handler || ->(_) {}
|
|
17
|
+
@logger = logger
|
|
18
|
+
@log_exception_backtrace = log_exception_backtrace
|
|
19
|
+
@error_status_code_map = error_status_code_map
|
|
7
20
|
end
|
|
8
21
|
|
|
9
22
|
def call(env)
|
|
@@ -43,9 +56,9 @@ module RackGraphql
|
|
|
43
56
|
env[Rack::RACK_ERRORS].puts(exception_string)
|
|
44
57
|
env[Rack::RACK_ERRORS].flush
|
|
45
58
|
[
|
|
46
|
-
|
|
59
|
+
error_status_code_map[e.class] || DEFAULT_ERROR_STATUS_CODE,
|
|
47
60
|
{ 'Content-Type' => 'application/json' },
|
|
48
|
-
[Oj.dump(errors
|
|
61
|
+
[Oj.dump('errors' => [exception_hash(e)])]
|
|
49
62
|
]
|
|
50
63
|
ensure
|
|
51
64
|
ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
|
|
@@ -53,7 +66,7 @@ module RackGraphql
|
|
|
53
66
|
|
|
54
67
|
private
|
|
55
68
|
|
|
56
|
-
attr_reader :schema, :logger, :context_handler
|
|
69
|
+
attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace, :error_status_code_map
|
|
57
70
|
|
|
58
71
|
def post_request?(env)
|
|
59
72
|
env['REQUEST_METHOD'] == 'POST'
|
|
@@ -151,14 +164,15 @@ module RackGraphql
|
|
|
151
164
|
# Based on https://github.com/rack/rack/blob/master/lib/rack/show_exceptions.rb
|
|
152
165
|
def dump_exception(exception)
|
|
153
166
|
string = "#{exception.class}: #{exception.message}\n"
|
|
154
|
-
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n") if
|
|
167
|
+
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n") if log_exception_backtrace
|
|
155
168
|
string
|
|
156
169
|
end
|
|
157
170
|
|
|
158
171
|
def exception_hash(exception)
|
|
159
172
|
{
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
'app_name' => app_name,
|
|
174
|
+
'message' => "#{exception.class}: #{exception.message}",
|
|
175
|
+
'backtrace' => log_exception_backtrace ? exception.backtrace : "[FILTERED]"
|
|
162
176
|
}
|
|
163
177
|
end
|
|
164
178
|
end
|
data/lib/rack_graphql/version.rb
CHANGED
data/rack-graphql.gemspec
CHANGED
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
|
|
15
15
|
spec.metadata['homepage_uri'] = 'https://github.com/RenoFi/rack-graphql'
|
|
16
16
|
spec.metadata['source_code_uri'] = 'https://github.com/RenoFi/rack-graphql'
|
|
17
|
+
spec.metadata['changelog_uri'] = 'https://github.com/RenoFi/rack-graphql/blob/master/CHANGELOG.md'
|
|
17
18
|
|
|
18
19
|
spec.files = Dir.chdir(__dir__) do
|
|
19
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin/|spec/|\.rub)}) }
|
|
@@ -28,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
|
28
29
|
spec.add_dependency 'oj'
|
|
29
30
|
spec.add_dependency 'rack', '~> 2.2'
|
|
30
31
|
|
|
32
|
+
spec.add_development_dependency 'awesome_print'
|
|
31
33
|
spec.add_development_dependency 'bundler'
|
|
32
34
|
spec.add_development_dependency 'pry'
|
|
33
35
|
spec.add_development_dependency 'rack-test'
|
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.3.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-09-
|
|
12
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: graphql
|
|
@@ -53,6 +53,20 @@ dependencies:
|
|
|
53
53
|
- - "~>"
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: '2.2'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: awesome_print
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
56
70
|
- !ruby/object:Gem::Dependency
|
|
57
71
|
name: bundler
|
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -202,6 +216,7 @@ licenses:
|
|
|
202
216
|
metadata:
|
|
203
217
|
homepage_uri: https://github.com/RenoFi/rack-graphql
|
|
204
218
|
source_code_uri: https://github.com/RenoFi/rack-graphql
|
|
219
|
+
changelog_uri: https://github.com/RenoFi/rack-graphql/blob/master/CHANGELOG.md
|
|
205
220
|
post_install_message:
|
|
206
221
|
rdoc_options: []
|
|
207
222
|
require_paths:
|