rack-graphql 2.2.1 → 2.5.1

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: 47a62b744316bad0bebd1d5016bd506a8927322cce95d4df7b81bf93b480d779
4
- data.tar.gz: 3a42f2f0f8886a628b6f8f0cebf3d268ad5ec668e267f949c10da364d15df805
3
+ metadata.gz: bd612f51ed5029ea31f162ccb63419bbda93203c1c4dc32fd8fe8dc8cb3df296
4
+ data.tar.gz: b58c4efcf02014ea60969fdd8d4375c19fa1f0bd143f7b6c1496b2e6f977ac05
5
5
  SHA512:
6
- metadata.gz: 41be36de74a80a87ff07a876f5e6e2b1a428438786693e10b61815faf9d98477cd8e959729ce0063cea0c7bb9d37fcf5d75fd42f7ef6339da45162739525d18d
7
- data.tar.gz: 7714e9edd009252d252350e9704dd46ec70c859e05a646537b8f86ef30e9be4dcb56b8389d2d7334c471d1cd25df430d82694f99941ee5715a163676e488f6cf
6
+ metadata.gz: f8e5816abcb0fc2b487331784dd29b23322a83c788a3f43ac11f02f435d67ed2bc61c9bedc544eb6dabc55376eeaba7d1a2a906f8e4077ad0d488fcce9e24adf
7
+ data.tar.gz: a7ab2a91badf6bdf080f023beb4e989a2883308896691fa52512fb2034c33ea93e5ed9deb6216cec43918a3e1d0af5e3d51917adbc0c429a924751271129826f
@@ -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.1 - 2020-11-18
4
+
5
+ - respond with http status 400 when UTF null byte passed as part of input
6
+
7
+ ## 2.5.0 - 2020-11-18
8
+
9
+ - make `log_exception_backtrace` false by default and allow to be controlled by `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var
10
+
11
+ ## 2.4.0 - 2020-09-39
12
+
13
+ - Use `http_status` from `ExecutionError` for http response
14
+
15
+ ## 2.3.0 - 2020-09-39
16
+
17
+ - Add `error_status_code_map` option to `RackGraphql::Application`.
18
+
19
+ `error_status_code_map` allows for return custom http code when specific errors are raised.
20
+
3
21
  ## 2.2.1 - 2020-09-14
4
22
 
5
23
  - Rename `source_app` to `app_name` in error payload.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.2.1)
4
+ rack-graphql (2.5.1)
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,14 +67,17 @@ 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'
62
74
  end
63
75
 
64
76
  def post_data(env)
65
- ::Oj.load(env['rack.input'].gets.to_s)
77
+ payload = env['rack.input'].read.to_s
78
+ return nil if payload.index('\u0000')
79
+
80
+ ::Oj.load(payload)
66
81
  rescue Oj::ParseError
67
82
  nil
68
83
  end
@@ -125,6 +140,13 @@ module RackGraphql
125
140
  end
126
141
  end
127
142
 
143
+ def response_status(result)
144
+ return DEFAULT_STATUS_CODE if result.is_a?(Array)
145
+
146
+ errors = result.to_h["errors"] || []
147
+ errors.map { |e| e["http_status"] }.compact.first || DEFAULT_STATUS_CODE
148
+ end
149
+
128
150
  def response_body(result = nil)
129
151
  if result_subscription?(result)
130
152
  body = result.to_h
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.5.1'.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.1
4
+ version: 2.5.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-14 00:00:00.000000000 Z
12
+ date: 2020-11-19 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.