rack-graphql 1.2.5 → 2.2.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-approve.yml +3 -3
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +8 -6
- data/README.md +14 -4
- data/Rakefile +1 -1
- data/lib/rack_graphql.rb +8 -0
- data/lib/rack_graphql/application.rb +16 -3
- data/lib/rack_graphql/middleware.rb +46 -6
- data/lib/rack_graphql/version.rb +1 -1
- data/rack-graphql.gemspec +3 -2
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6598f80d99758463e5b906b46793eb99e00a4289d575e4a9947049a1a365cad2
|
4
|
+
data.tar.gz: d255f35c7dae31102576f2c20024b3627c5cfe47f41f6c84e91d2d284c297ea9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccfe829dc5cb515d817d670ed2f41a414c089cbd959f24c71db11f3ff2aeaa00b365ef2e3db429921db80bf872ed36c3e27fd0915b9645281eb2c383138f79ca
|
7
|
+
data.tar.gz: f10803e7f9fc3db00ba5b6fdbce23b7d52d023d5e8aeafb8201fa1880c5f25f9517fea2ab452ff82b0889a070316f9c8892022d935e95c1ba14d58d2b0cb5472
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# automatically approve PRs submitted by Dependabot
|
1
|
+
# automatically approve PRs submitted by Dependabot or Renofidev
|
2
2
|
# this will allow Dependabot to automatically merge dependency update PRs where CI passes
|
3
3
|
# from: https://github.com/hmarr/auto-approve-action
|
4
|
-
name: Auto approve
|
4
|
+
name: Auto approve dependency upgrades PRs
|
5
5
|
|
6
6
|
on:
|
7
7
|
pull_request
|
@@ -11,6 +11,6 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
steps:
|
13
13
|
- uses: hmarr/auto-approve-action@v2.0.0
|
14
|
-
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
|
14
|
+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' || github.actor == 'renofidev'
|
15
15
|
with:
|
16
16
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 2.2.0 - 2020-09-14
|
4
|
+
|
5
|
+
- Add `source_app` to error payload.
|
6
|
+
|
7
|
+
## 2.1.0 - 2020-09-14
|
8
|
+
|
9
|
+
- Add `log_exception_backtrace` option to `RackGraphql::Application`
|
10
|
+
|
11
|
+
## 2.0.0 - 2020-09-14
|
12
|
+
|
13
|
+
- Catch all exceptions raised by the app respond with 500 status codea and json content type
|
14
|
+
- Add ability to not log exception backtrace with `RackGraphql.log_exception_backtrace = false`
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-graphql (
|
5
|
-
graphql (~> 1.
|
4
|
+
rack-graphql (2.2.0)
|
5
|
+
graphql (~> 1.11)
|
6
6
|
oj
|
7
|
-
rack (~> 2.
|
7
|
+
rack (~> 2.2)
|
8
8
|
|
9
9
|
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
|
-
oj (3.10.
|
18
|
+
oj (3.10.14)
|
18
19
|
parallel (1.19.2)
|
19
20
|
parser (2.7.1.4)
|
20
21
|
ast (~> 2.4.1)
|
@@ -52,8 +53,8 @@ GEM
|
|
52
53
|
unicode-display_width (>= 1.4.0, < 2.0)
|
53
54
|
rubocop-ast (0.3.0)
|
54
55
|
parser (>= 2.7.1.4)
|
55
|
-
rubocop-performance (1.
|
56
|
-
rubocop (>= 0.
|
56
|
+
rubocop-performance (1.8.0)
|
57
|
+
rubocop (>= 0.87.0)
|
57
58
|
rubocop-rspec (1.43.2)
|
58
59
|
rubocop (~> 0.87)
|
59
60
|
ruby-progressbar (1.10.1)
|
@@ -63,6 +64,7 @@ PLATFORMS
|
|
63
64
|
ruby
|
64
65
|
|
65
66
|
DEPENDENCIES
|
67
|
+
awesome_print
|
66
68
|
bundler
|
67
69
|
pry
|
68
70
|
rack-graphql!
|
data/README.md
CHANGED
@@ -23,10 +23,12 @@ 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
|
-
|
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
|
30
32
|
)
|
31
33
|
```
|
32
34
|
|
@@ -69,6 +71,14 @@ class GraphqlContextHandler
|
|
69
71
|
end
|
70
72
|
```
|
71
73
|
|
74
|
+
### Logging exception backtrace
|
75
|
+
|
76
|
+
RackGraphql catches all errors and respond with 500 code. By default it adds exception backtrace to the response body. If you don't want to have the backtrace in the response set:
|
77
|
+
|
78
|
+
```
|
79
|
+
RackGraphql.log_exception_backtrace = false
|
80
|
+
```
|
81
|
+
|
72
82
|
## Contributing
|
73
83
|
|
74
84
|
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
data/lib/rack_graphql.rb
CHANGED
@@ -7,3 +7,11 @@ require 'rack_graphql/exceptions'
|
|
7
7
|
require 'rack_graphql/health_response_builder'
|
8
8
|
require 'rack_graphql/middleware'
|
9
9
|
require 'rack_graphql/application'
|
10
|
+
|
11
|
+
module RackGraphql
|
12
|
+
class << self
|
13
|
+
attr_accessor :log_exception_backtrace
|
14
|
+
end
|
15
|
+
|
16
|
+
self.log_exception_backtrace = true
|
17
|
+
end
|
@@ -1,11 +1,24 @@
|
|
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
|
+
)
|
5
12
|
|
6
13
|
::Rack::Builder.new do
|
7
14
|
map '/graphql' do
|
8
|
-
run RackGraphql::Middleware.new(
|
15
|
+
run RackGraphql::Middleware.new(
|
16
|
+
app_name: app_name,
|
17
|
+
schema: schema,
|
18
|
+
context_handler: context_handler,
|
19
|
+
logger: logger,
|
20
|
+
log_exception_backtrace: log_exception_backtrace,
|
21
|
+
)
|
9
22
|
end
|
10
23
|
|
11
24
|
if health_route
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module RackGraphql
|
2
2
|
class Middleware
|
3
|
-
def initialize(schema:,
|
3
|
+
def initialize(schema:, app_name: nil, context_handler: nil, logger: nil, log_exception_backtrace: RackGraphql.log_exception_backtrace)
|
4
4
|
@schema = schema
|
5
|
-
@
|
5
|
+
@app_name = app_name
|
6
6
|
@context_handler = context_handler || ->(_) {}
|
7
|
+
@logger = logger
|
8
|
+
@log_exception_backtrace = log_exception_backtrace
|
7
9
|
end
|
8
10
|
|
9
11
|
def call(env)
|
@@ -20,17 +22,40 @@ module RackGraphql
|
|
20
22
|
log("Executing with params: #{params.inspect}, operationName: #{operation_name}, variables: #{variables.inspect}")
|
21
23
|
result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
|
22
24
|
|
23
|
-
[
|
25
|
+
[
|
26
|
+
200,
|
27
|
+
response_headers(result),
|
28
|
+
[response_body(result)]
|
29
|
+
]
|
24
30
|
rescue AmbiguousParamError => e
|
25
|
-
|
26
|
-
|
31
|
+
exception_string = dump_exception(e)
|
32
|
+
log(exception_string)
|
33
|
+
env[Rack::RACK_ERRORS].puts(exception_string)
|
34
|
+
env[Rack::RACK_ERRORS].flush
|
35
|
+
[
|
36
|
+
400,
|
37
|
+
{ 'Content-Type' => 'application/json' },
|
38
|
+
[Oj.dump({})]
|
39
|
+
]
|
40
|
+
rescue StandardError, LoadError, SyntaxError => e
|
41
|
+
# To respect the graphql spec, all errors need to be returned as json.
|
42
|
+
# It needs to take Rack::ShowExceptions role of catching all exceptions raised by the app.
|
43
|
+
exception_string = dump_exception(e)
|
44
|
+
log(exception_string)
|
45
|
+
env[Rack::RACK_ERRORS].puts(exception_string)
|
46
|
+
env[Rack::RACK_ERRORS].flush
|
47
|
+
[
|
48
|
+
500,
|
49
|
+
{ 'Content-Type' => 'application/json' },
|
50
|
+
[Oj.dump('errors' => [exception_hash(e)])]
|
51
|
+
]
|
27
52
|
ensure
|
28
53
|
ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
|
29
54
|
end
|
30
55
|
|
31
56
|
private
|
32
57
|
|
33
|
-
attr_reader :schema, :logger, :context_handler
|
58
|
+
attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace
|
34
59
|
|
35
60
|
def post_request?(env)
|
36
61
|
env['REQUEST_METHOD'] == 'POST'
|
@@ -124,5 +149,20 @@ module RackGraphql
|
|
124
149
|
return unless logger
|
125
150
|
logger.debug("[rack-graphql] #{message}")
|
126
151
|
end
|
152
|
+
|
153
|
+
# Based on https://github.com/rack/rack/blob/master/lib/rack/show_exceptions.rb
|
154
|
+
def dump_exception(exception)
|
155
|
+
string = "#{exception.class}: #{exception.message}\n"
|
156
|
+
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n") if log_exception_backtrace
|
157
|
+
string
|
158
|
+
end
|
159
|
+
|
160
|
+
def exception_hash(exception)
|
161
|
+
{
|
162
|
+
'source_app' => app_name,
|
163
|
+
'message' => "#{exception.class}: #{exception.message}",
|
164
|
+
'backtrace' => log_exception_backtrace ? exception.backtrace : "[FILTERED]"
|
165
|
+
}
|
166
|
+
end
|
127
167
|
end
|
128
168
|
end
|
data/lib/rack_graphql/version.rb
CHANGED
data/rack-graphql.gemspec
CHANGED
@@ -24,10 +24,11 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.required_ruby_version = '>= 2.6'
|
26
26
|
|
27
|
-
spec.add_dependency 'graphql', '~> 1.
|
27
|
+
spec.add_dependency 'graphql', '~> 1.11'
|
28
28
|
spec.add_dependency 'oj'
|
29
|
-
spec.add_dependency 'rack', '~> 2.
|
29
|
+
spec.add_dependency 'rack', '~> 2.2'
|
30
30
|
|
31
|
+
spec.add_development_dependency 'awesome_print'
|
31
32
|
spec.add_development_dependency 'bundler'
|
32
33
|
spec.add_development_dependency 'pry'
|
33
34
|
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:
|
4
|
+
version: 2.2.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: 2020-09-
|
12
|
+
date: 2020-09-14 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.
|
20
|
+
version: '1.11'
|
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.
|
27
|
+
version: '1.11'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: oj
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,14 +45,28 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '2.
|
48
|
+
version: '2.2'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '2.
|
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
|
@@ -182,6 +196,7 @@ files:
|
|
182
196
|
- ".gitignore"
|
183
197
|
- ".rspec"
|
184
198
|
- ".travis.yml"
|
199
|
+
- CHANGELOG.md
|
185
200
|
- Gemfile
|
186
201
|
- Gemfile.lock
|
187
202
|
- LICENSE
|