rack-graphql 2.1.0 → 2.4.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: 89001cf0e27af277a4e74c423e6ebaed600057a5528d9c0b850a76f704690454
4
- data.tar.gz: d5250dddf85e2203701d5357f6479001294e64f7d3f28457bc10b55698e0f0c7
3
+ metadata.gz: 0d1aad090a41b8371934fb35708504a1c08d473aa4991607119fd98485adefbf
4
+ data.tar.gz: 25902f5ffc962398799a20fe3bdeb4dd7b3dae772d7f5bbcddbd267c8f9eb6d4
5
5
  SHA512:
6
- metadata.gz: e0975735f7f595af62aeece22cb537e454eef1608b0f012af59e0cc65e14b3015c1db2dd9b7e15402b19bbf1cf564e9982bcd8c79c22681e486d23ae2a96be25
7
- data.tar.gz: 508d6a5276bfbc8914c9870e4cfa390455ef687634f7de4fc314f28f2c19feedcf7f78de7a39add4543947a44e08e1b0e2de978a1598ac3e8369e5c921c12140
6
+ metadata.gz: d5daf847af3b599990248a75664aed30015c88b136bf8a91f530a81716d8739a8dbd3fc272e46bfe36abbc9b1b1f2ad50968e1da64697df23e85adee5183b519
7
+ data.tar.gz: dd3e2c521fa4112b3c177f29e4a0a53d94036e4aabca5c50b43c79518828ac5140ddd2b94bd41a571aa23ebb7cc45f66af4c1fc1c27df92b8ebbffa8ade55612
@@ -1,5 +1,23 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.4.0 - 2020-09-39
4
+
5
+ - Use `http_status` from `ExecutionError` for http response
6
+
7
+ ## 2.3.0 - 2020-09-39
8
+
9
+ - Add `error_status_code_map` option to `RackGraphql::Application`.
10
+
11
+ `error_status_code_map` allows for return custom http code when specific errors are raised.
12
+
13
+ ## 2.2.1 - 2020-09-14
14
+
15
+ - Rename `source_app` to `app_name` in error payload.
16
+
17
+ ## 2.2.0 - 2020-09-14
18
+
19
+ - Add `source_app` to error payload.
20
+
3
21
  ## 2.1.0 - 2020-09-14
4
22
 
5
23
  - Add `log_exception_backtrace` option to `RackGraphql::Application`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.1.0)
4
+ rack-graphql (2.4.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
- graphql (1.11.4)
16
+ graphql (1.11.5)
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,12 +23,13 @@ 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
- 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
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
32
33
  )
33
34
  ```
34
35
 
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]
@@ -7,12 +7,20 @@ module RackGraphql
7
7
  context_handler: nil,
8
8
  log_exception_backtrace: RackGraphql.log_exception_backtrace,
9
9
  health_route: true,
10
- health_response_builder: RackGraphql::HealthResponseBuilder
10
+ health_response_builder: RackGraphql::HealthResponseBuilder,
11
+ error_status_code_map: {}
11
12
  )
12
13
 
13
14
  ::Rack::Builder.new do
14
15
  map '/graphql' do
15
- run RackGraphql::Middleware.new(schema: schema, context_handler: context_handler, log_exception_backtrace: log_exception_backtrace, 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
+ )
16
24
  end
17
25
 
18
26
  if health_route
@@ -1,10 +1,23 @@
1
1
  module RackGraphql
2
2
  class Middleware
3
- def initialize(schema:, logger: nil, context_handler: nil, log_exception_backtrace: RackGraphql.log_exception_backtrace)
3
+ DEFAULT_STATUS_CODE = 200
4
+ DEFAULT_ERROR_STATUS_CODE = 500
5
+
6
+ def initialize(
7
+ schema:,
8
+ app_name: nil,
9
+ context_handler: nil,
10
+ logger: nil,
11
+ log_exception_backtrace: RackGraphql.log_exception_backtrace,
12
+ error_status_code_map: {}
13
+ )
14
+
4
15
  @schema = schema
5
- @logger = logger
16
+ @app_name = app_name
6
17
  @context_handler = context_handler || ->(_) {}
18
+ @logger = logger
7
19
  @log_exception_backtrace = log_exception_backtrace
20
+ @error_status_code_map = error_status_code_map
8
21
  end
9
22
 
10
23
  def call(env)
@@ -22,7 +35,7 @@ module RackGraphql
22
35
  result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
23
36
 
24
37
  [
25
- 200,
38
+ response_status(result),
26
39
  response_headers(result),
27
40
  [response_body(result)]
28
41
  ]
@@ -44,9 +57,9 @@ module RackGraphql
44
57
  env[Rack::RACK_ERRORS].puts(exception_string)
45
58
  env[Rack::RACK_ERRORS].flush
46
59
  [
47
- 500,
60
+ error_status_code_map[e.class] || DEFAULT_ERROR_STATUS_CODE,
48
61
  { 'Content-Type' => 'application/json' },
49
- [Oj.dump(errors: [exception_hash(e)])]
62
+ [Oj.dump('errors' => [exception_hash(e)])]
50
63
  ]
51
64
  ensure
52
65
  ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
@@ -54,7 +67,7 @@ module RackGraphql
54
67
 
55
68
  private
56
69
 
57
- attr_reader :schema, :logger, :context_handler, :log_exception_backtrace
70
+ attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace, :error_status_code_map
58
71
 
59
72
  def post_request?(env)
60
73
  env['REQUEST_METHOD'] == 'POST'
@@ -124,6 +137,13 @@ module RackGraphql
124
137
  end
125
138
  end
126
139
 
140
+ def response_status(result)
141
+ return DEFAULT_STATUS_CODE if result.is_a?(Array)
142
+
143
+ errors = result.to_h["errors"] || []
144
+ errors.map { |e| e["http_status"] }.compact.first || DEFAULT_STATUS_CODE
145
+ end
146
+
127
147
  def response_body(result = nil)
128
148
  if result_subscription?(result)
129
149
  body = result.to_h
@@ -158,8 +178,9 @@ module RackGraphql
158
178
 
159
179
  def exception_hash(exception)
160
180
  {
161
- message: "#{exception.class}: #{exception.message}",
162
- backtrace: log_exception_backtrace ? exception.backtrace : "[FILTERED]"
181
+ 'app_name' => app_name,
182
+ 'message' => "#{exception.class}: #{exception.message}",
183
+ 'backtrace' => log_exception_backtrace ? exception.backtrace : "[FILTERED]"
163
184
  }
164
185
  end
165
186
  end
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.1.0'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -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.1.0
4
+ version: 2.4.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
@@ -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: