rack-graphql 2.0.0.rc2 → 2.3.0

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: 404f5193946ee5d9dabc5aeedd7a36506a3594ccedca888e38b3f9abc4a25929
4
- data.tar.gz: 9f702646a34bbc872cf74fd4889049b0258b9a6c0ec159b4f18e75d79b3f3e2c
3
+ metadata.gz: 19eaa68b6aad14dfbfe885f5853e1697a81549d278508ea3ba997894b160f686
4
+ data.tar.gz: 68e94bab40fbf24668dd55074698128e3f8014208a1fa8e6fa82330584bc4a29
5
5
  SHA512:
6
- metadata.gz: 1b9293e01c37cfc1a2c459b7d022793f422c8004bc505378faf88dff831325599bb8b4d4f2c095d7f9665ff94624e79cb0adbb4e59860f4150c1b7faa3eae0c0
7
- data.tar.gz: 82b068ff658f4aea8372666f3cb42f9c837a551ace9977009870de9078e101981e9afa3e8f6b6cdca7ee3f96998e62f983a7bd33b2cbc0fff3c15da5bb80c43d
6
+ metadata.gz: a349fc1e92684778a146af524b4e179cf10abbbe156b5a7f28b44d8860a008c7b18b2159f59327b9bbe4de20c2caa5eed7ecc908031e71b175a7ba850a01cfc6
7
+ data.tar.gz: 3d6ad7f221c8606175778807a7c5d09f3a534c9131eea1d8bf350552146fdec1517a3499cb073dc1295738fa849bc6721285101769e7c01049ea713ac32ab88b
@@ -1,6 +1,22 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 2.0.0.rc - 2020-09-11
3
+ ## 2.3.0 - 2020-09-39
4
+
5
+ - Add `error_status_code_map` option to `RackGraphql::Application`. It allows for return custom http code when specific errors are raised.
6
+
7
+ ## 2.2.1 - 2020-09-14
8
+
9
+ - Rename `source_app` to `app_name` in error payload.
10
+
11
+ ## 2.2.0 - 2020-09-14
12
+
13
+ - Add `source_app` to error payload.
14
+
15
+ ## 2.1.0 - 2020-09-14
16
+
17
+ - Add `log_exception_backtrace` option to `RackGraphql::Application`
18
+
19
+ ## 2.0.0 - 2020-09-14
4
20
 
5
21
  - Catch all exceptions raised by the app respond with 500 status codea and json content type
6
22
  - Add ability to not log exception backtrace with `RackGraphql.log_exception_backtrace = false`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.0.0.rc2)
4
+ rack-graphql (2.3.0)
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.4)
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.7.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.90.0)
45
+ rubocop (0.92.0)
45
46
  parallel (~> 1.10)
46
- parser (>= 2.7.1.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.3.0, < 1.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.3.0)
54
- parser (>= 2.7.1.4)
55
- rubocop-performance (1.8.0)
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,12 @@ 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
- health_route: true, # optional, true by default
30
- logger: A9n.logger, # optional, not set by 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, `true` default
30
+ health_route: true, # optional, true by default
31
+ logger: A9n.logger, # optional, not set by default
31
32
  )
32
33
  ```
33
34
 
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ require 'rubocop/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  RuboCop::RakeTask.new
7
7
 
8
- task default: %i[rubocop:auto_correct spec]
8
+ task default: %i[spec rubocop:auto_correct]
@@ -1,11 +1,26 @@
1
1
  module RackGraphql
2
2
  class Application
3
- def self.call(schema:, app_name: 'rack-graphql-service', logger: nil, context_handler: nil,
4
- health_route: true, health_response_builder: RackGraphql::HealthResponseBuilder)
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(schema: schema, context_handler: context_handler, logger: logger)
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
- def initialize(schema:, logger: nil, context_handler: nil)
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
- @logger = logger
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
- 500,
59
+ error_status_code_map[e.class] || DEFAULT_ERROR_STATUS_CODE,
47
60
  { 'Content-Type' => 'application/json' },
48
- [Oj.dump(errors: [exception_hash(e)])]
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 RackGraphql.log_exception_backtrace
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
- message: "#{exception.class}: #{exception.message}",
161
- backtrace: RackGraphql.log_exception_backtrace ? exception.backtrace : "[FILTERED]"
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
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.0.0.rc2'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'oj'
29
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: 2.0.0.rc2
4
+ version: 2.3.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-14 00:00:00.000000000 Z
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
@@ -213,9 +227,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
227
  version: '2.6'
214
228
  required_rubygems_version: !ruby/object:Gem::Requirement
215
229
  requirements:
216
- - - ">"
230
+ - - ">="
217
231
  - !ruby/object:Gem::Version
218
- version: 1.3.1
232
+ version: '0'
219
233
  requirements: []
220
234
  rubygems_version: 3.1.2
221
235
  signing_key: