rack-graphql 2.2.0 → 2.5.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: 6598f80d99758463e5b906b46793eb99e00a4289d575e4a9947049a1a365cad2
4
- data.tar.gz: d255f35c7dae31102576f2c20024b3627c5cfe47f41f6c84e91d2d284c297ea9
3
+ metadata.gz: dc3ae3d43695a7a533d43610adbc28395dcba6b2c53e7c1811402c98599c74bc
4
+ data.tar.gz: d0fa5477c6fc8006337dd5653f13fb9b486d79e019b24fd58956dc24867d4d71
5
5
  SHA512:
6
- metadata.gz: ccfe829dc5cb515d817d670ed2f41a414c089cbd959f24c71db11f3ff2aeaa00b365ef2e3db429921db80bf872ed36c3e27fd0915b9645281eb2c383138f79ca
7
- data.tar.gz: f10803e7f9fc3db00ba5b6fdbce23b7d52d023d5e8aeafb8201fa1880c5f25f9517fea2ab452ff82b0889a070316f9c8892022d935e95c1ba14d58d2b0cb5472
6
+ metadata.gz: cb4510a840bcc8450fb96ce824118fe9908bec545da22222484f32f1ca061b68a502c9fb30a5041f05e521c16dbd7c4f2241dec2ccb6e649c727b7c3ebf1ac36
7
+ data.tar.gz: f423c41a32de086c507006b5b2bea6c557931ce329505b25649dc09a93b6d2c1695c052f553f0fd699c53a2f9a16e6c863b2c5b0af62af6a304e114f0944d626
@@ -0,0 +1,19 @@
1
+ name: automerge
2
+ on:
3
+ pull_request_review:
4
+ types:
5
+ - submitted
6
+ check_suite:
7
+ types:
8
+ - completed
9
+ status: {}
10
+ jobs:
11
+ automerge:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: automerge
15
+ uses: "pascalgn/automerge-action@v0.11.0"
16
+ env:
17
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18
+ MERGE_METHOD: squash
19
+ MERGE_DELETE_BRANCH: true
@@ -1,5 +1,23 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.5.0 - 2020-11-18
4
+
5
+ - make `log_exception_backtrace` false by default and allow to be controlled by `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var
6
+
7
+ ## 2.4.0 - 2020-09-39
8
+
9
+ - Use `http_status` from `ExecutionError` for http response
10
+
11
+ ## 2.3.0 - 2020-09-39
12
+
13
+ - Add `error_status_code_map` option to `RackGraphql::Application`.
14
+
15
+ `error_status_code_map` allows for return custom http code when specific errors are raised.
16
+
17
+ ## 2.2.1 - 2020-09-14
18
+
19
+ - Rename `source_app` to `app_name` in error payload.
20
+
3
21
  ## 2.2.0 - 2020-09-14
4
22
 
5
23
  - Add `source_app` to error payload.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.2.0)
4
+ rack-graphql (2.5.0)
5
5
  graphql (~> 1.11)
6
6
  oj
7
7
  rack (~> 2.2)
@@ -13,11 +13,11 @@ GEM
13
13
  awesome_print (1.8.0)
14
14
  coderay (1.1.3)
15
15
  diff-lcs (1.4.4)
16
- graphql (1.11.4)
16
+ graphql (1.11.6)
17
17
  method_source (1.0.0)
18
- oj (3.10.14)
19
- parallel (1.19.2)
20
- parser (2.7.1.4)
18
+ oj (3.10.16)
19
+ parallel (1.20.0)
20
+ parser (2.7.2.0)
21
21
  ast (~> 2.4.1)
22
22
  pry (0.13.1)
23
23
  coderay (~> 1.1)
@@ -27,36 +27,38 @@ GEM
27
27
  rack (>= 1.0, < 3)
28
28
  rainbow (3.0.0)
29
29
  rake (13.0.1)
30
- regexp_parser (1.7.1)
30
+ regexp_parser (1.8.2)
31
31
  rexml (3.2.4)
32
- rspec (3.9.0)
33
- rspec-core (~> 3.9.0)
34
- rspec-expectations (~> 3.9.0)
35
- rspec-mocks (~> 3.9.0)
36
- rspec-core (3.9.2)
37
- rspec-support (~> 3.9.3)
38
- rspec-expectations (3.9.2)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.0)
39
39
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.9.0)
41
- rspec-mocks (3.9.1)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.0)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.9.0)
44
- rspec-support (3.9.3)
45
- rubocop (0.90.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.0)
45
+ rubocop (1.3.1)
46
46
  parallel (~> 1.10)
47
- parser (>= 2.7.1.1)
47
+ parser (>= 2.7.1.5)
48
48
  rainbow (>= 2.2.2, < 4.0)
49
- regexp_parser (>= 1.7)
49
+ regexp_parser (>= 1.8)
50
50
  rexml
51
- rubocop-ast (>= 0.3.0, < 1.0)
51
+ rubocop-ast (>= 1.1.1)
52
52
  ruby-progressbar (~> 1.7)
53
53
  unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (0.3.0)
55
- parser (>= 2.7.1.4)
56
- rubocop-performance (1.8.0)
57
- rubocop (>= 0.87.0)
58
- rubocop-rspec (1.43.2)
59
- rubocop (~> 0.87)
54
+ rubocop-ast (1.1.1)
55
+ parser (>= 2.7.1.5)
56
+ rubocop-performance (1.9.0)
57
+ rubocop (>= 0.90.0, < 2.0)
58
+ rubocop-ast (>= 0.4.0)
59
+ rubocop-rspec (2.0.0)
60
+ rubocop (~> 1.0)
61
+ rubocop-ast (>= 1.1.0)
60
62
  ruby-progressbar (1.10.1)
61
63
  unicode-display_width (1.7.0)
62
64
 
data/README.md CHANGED
@@ -23,12 +23,14 @@ 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, `false` default
30
+ # `true` when `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var is set to `'1'` or `'true'`
31
+ health_route: true, # optional, true by default
32
+ logger: A9n.logger, # optional, not set by default
33
+ error_status_code_map: { IamTeapotError => 418 }, # optional
32
34
  )
33
35
  ```
34
36
 
@@ -10,8 +10,12 @@ require 'rack_graphql/application'
10
10
 
11
11
  module RackGraphql
12
12
  class << self
13
- attr_accessor :log_exception_backtrace
14
- end
13
+ def log_exception_backtrace
14
+ return @log_exception_backtrace unless @log_exception_backtrace.nil?
15
+
16
+ %w[1 true].include?(ENV['RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE'].to_s)
17
+ end
15
18
 
16
- self.log_exception_backtrace = true
19
+ attr_writer :log_exception_backtrace
20
+ end
17
21
  end
@@ -7,7 +7,8 @@ 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
@@ -18,6 +19,7 @@ module RackGraphql
18
19
  context_handler: context_handler,
19
20
  logger: logger,
20
21
  log_exception_backtrace: log_exception_backtrace,
22
+ error_status_code_map: error_status_code_map,
21
23
  )
22
24
  end
23
25
 
@@ -1,11 +1,23 @@
1
1
  module RackGraphql
2
2
  class Middleware
3
- def initialize(schema:, app_name: nil, context_handler: nil, logger: 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
16
  @app_name = app_name
6
17
  @context_handler = context_handler || ->(_) {}
7
18
  @logger = logger
8
19
  @log_exception_backtrace = log_exception_backtrace
20
+ @error_status_code_map = error_status_code_map
9
21
  end
10
22
 
11
23
  def call(env)
@@ -23,7 +35,7 @@ module RackGraphql
23
35
  result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
24
36
 
25
37
  [
26
- 200,
38
+ response_status(result),
27
39
  response_headers(result),
28
40
  [response_body(result)]
29
41
  ]
@@ -45,7 +57,7 @@ module RackGraphql
45
57
  env[Rack::RACK_ERRORS].puts(exception_string)
46
58
  env[Rack::RACK_ERRORS].flush
47
59
  [
48
- 500,
60
+ error_status_code_map[e.class] || DEFAULT_ERROR_STATUS_CODE,
49
61
  { 'Content-Type' => 'application/json' },
50
62
  [Oj.dump('errors' => [exception_hash(e)])]
51
63
  ]
@@ -55,7 +67,7 @@ module RackGraphql
55
67
 
56
68
  private
57
69
 
58
- attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace
70
+ attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace, :error_status_code_map
59
71
 
60
72
  def post_request?(env)
61
73
  env['REQUEST_METHOD'] == 'POST'
@@ -125,6 +137,13 @@ module RackGraphql
125
137
  end
126
138
  end
127
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
+
128
147
  def response_body(result = nil)
129
148
  if result_subscription?(result)
130
149
  body = result.to_h
@@ -159,7 +178,7 @@ module RackGraphql
159
178
 
160
179
  def exception_hash(exception)
161
180
  {
162
- 'source_app' => app_name,
181
+ 'app_name' => app_name,
163
182
  'message' => "#{exception.class}: #{exception.message}",
164
183
  'backtrace' => log_exception_backtrace ? exception.backtrace : "[FILTERED]"
165
184
  }
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.2.0'.freeze
2
+ VERSION = '2.5.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)}) }
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.2.0
4
+ version: 2.5.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-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -193,6 +193,7 @@ files:
193
193
  - ".github/ISSUE_TEMPLATE/story.md"
194
194
  - ".github/PULL_REQUEST_TEMPLATE.md"
195
195
  - ".github/workflows/auto-approve.yml"
196
+ - ".github/workflows/auto-merge.yml"
196
197
  - ".gitignore"
197
198
  - ".rspec"
198
199
  - ".travis.yml"
@@ -216,6 +217,7 @@ licenses:
216
217
  metadata:
217
218
  homepage_uri: https://github.com/RenoFi/rack-graphql
218
219
  source_code_uri: https://github.com/RenoFi/rack-graphql
220
+ changelog_uri: https://github.com/RenoFi/rack-graphql/blob/master/CHANGELOG.md
219
221
  post_install_message:
220
222
  rdoc_options: []
221
223
  require_paths:
@@ -231,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
233
  - !ruby/object:Gem::Version
232
234
  version: '0'
233
235
  requirements: []
234
- rubygems_version: 3.1.2
236
+ rubygems_version: 3.1.4
235
237
  signing_key:
236
238
  specification_version: 4
237
239
  summary: Rack middleware implementing graphql endpoint.