rack-graphql 2.3.0 → 2.6.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: 19eaa68b6aad14dfbfe885f5853e1697a81549d278508ea3ba997894b160f686
4
- data.tar.gz: 68e94bab40fbf24668dd55074698128e3f8014208a1fa8e6fa82330584bc4a29
3
+ metadata.gz: 845b505da7e26dbe5a9e5065514f0420de0c0394f09692afb6d49a134a35dcc2
4
+ data.tar.gz: 570b9ce45188d4371f18dd371468f77341535e54f574e06cc184e4e2aaf97adc
5
5
  SHA512:
6
- metadata.gz: a349fc1e92684778a146af524b4e179cf10abbbe156b5a7f28b44d8860a008c7b18b2159f59327b9bbe4de20c2caa5eed7ecc908031e71b175a7ba850a01cfc6
7
- data.tar.gz: 3d6ad7f221c8606175778807a7c5d09f3a534c9131eea1d8bf350552146fdec1517a3499cb073dc1295738fa849bc6721285101769e7c01049ea713ac32ab88b
6
+ metadata.gz: cbc0bbdad9edd52702b4bf7ad70dc46cf592a39e5a47fdb4031f87d1fcb29ca846555a8e05fa0e9620eb198f30212a17169444c6fe53be0a7083941bb8563a83
7
+ data.tar.gz: 11e95a8121612f0cd206cea8ac3109e02c5cc30a24524b1032b9d378926e0314a8c474b49e6c494a26d489e14f1e444b240c1f61ee330d5784d1d7c29639846e
@@ -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.12.0"
16
+ env:
17
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18
+ MERGE_METHOD: squash
19
+ MERGE_DELETE_BRANCH: true
@@ -5,6 +5,7 @@ cache: bundler
5
5
  rvm:
6
6
  - 2.6
7
7
  - 2.7
8
+ - 3.0
8
9
  before_install: gem install bundler
9
10
  script:
10
11
  - bundle exec rake rubocop
@@ -1,8 +1,26 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.6.0 - 2021-01-14
4
+
5
+ - Add ability to re-raise exception (`re_raise_exceptions` option)
6
+
7
+ ## 2.5.1 - 2020-11-19
8
+
9
+ - respond with http status `400` when UTF null byte is passed as a part of the input
10
+
11
+ ## 2.5.0 - 2020-11-18
12
+
13
+ - make `log_exception_backtrace` false by default and allow to be controlled by `RACK_GRAPHQL_LOG_EXCEPTION_BACKTRACE` env var
14
+
15
+ ## 2.4.0 - 2020-09-39
16
+
17
+ - Use `http_status` from `ExecutionError` for http response
18
+
3
19
  ## 2.3.0 - 2020-09-39
4
20
 
5
- - Add `error_status_code_map` option to `RackGraphql::Application`. It allows for return custom http code when specific errors are raised.
21
+ - Add `error_status_code_map` option to `RackGraphql::Application`.
22
+
23
+ `error_status_code_map` allows for return custom http code when specific errors are raised.
6
24
 
7
25
  ## 2.2.1 - 2020-09-14
8
26
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (2.3.0)
4
+ rack-graphql (2.6.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.5)
18
+ oj (3.11.0)
19
+ parallel (1.20.1)
20
+ parser (3.0.0.0)
21
21
  ast (~> 2.4.1)
22
22
  pry (0.13.1)
23
23
  coderay (~> 1.1)
@@ -26,43 +26,44 @@ GEM
26
26
  rack-test (1.1.0)
27
27
  rack (>= 1.0, < 3)
28
28
  rainbow (3.0.0)
29
- rake (13.0.1)
30
- regexp_parser (1.8.1)
29
+ rake (13.0.3)
30
+ regexp_parser (2.0.3)
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.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.1)
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.1)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.9.0)
44
- rspec-support (3.9.3)
45
- rubocop (0.92.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.1)
45
+ rubocop (1.8.0)
46
46
  parallel (~> 1.10)
47
- parser (>= 2.7.1.5)
47
+ parser (>= 3.0.0.0)
48
48
  rainbow (>= 2.2.2, < 4.0)
49
- regexp_parser (>= 1.7)
49
+ regexp_parser (>= 1.8, < 3.0)
50
50
  rexml
51
- rubocop-ast (>= 0.5.0)
51
+ rubocop-ast (>= 1.2.0, < 2.0)
52
52
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (0.7.1)
53
+ unicode-display_width (>= 1.4.0, < 3.0)
54
+ rubocop-ast (1.4.0)
55
55
  parser (>= 2.7.1.5)
56
- rubocop-performance (1.8.1)
57
- rubocop (>= 0.87.0)
58
- rubocop-ast (>= 0.4.0)
59
- rubocop-rspec (1.43.2)
60
- rubocop (~> 0.87)
61
- ruby-progressbar (1.10.1)
62
- unicode-display_width (1.7.0)
56
+ rubocop-rake (0.5.1)
57
+ rubocop
58
+ rubocop-rspec (2.1.0)
59
+ rubocop (~> 1.0)
60
+ rubocop-ast (>= 1.1.0)
61
+ ruby-progressbar (1.11.0)
62
+ unicode-display_width (2.0.0)
63
63
 
64
64
  PLATFORMS
65
65
  ruby
66
+ x86_64-linux
66
67
 
67
68
  DEPENDENCIES
68
69
  awesome_print
@@ -73,8 +74,8 @@ DEPENDENCIES
73
74
  rake
74
75
  rspec
75
76
  rubocop
76
- rubocop-performance
77
+ rubocop-rake
77
78
  rubocop-rspec
78
79
 
79
80
  BUNDLED WITH
80
- 2.1.4
81
+ 2.2.4
data/README.md CHANGED
@@ -23,12 +23,15 @@ 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
34
+ re_raise_exceptions: true, # optional, false by default
32
35
  )
33
36
  ```
34
37
 
@@ -79,6 +82,39 @@ RackGraphql catches all errors and respond with 500 code. By default it adds exc
79
82
  RackGraphql.log_exception_backtrace = false
80
83
  ```
81
84
 
85
+ ### Error tracking/reporting
86
+
87
+ To respect the graphql spec, all errors need to be returned as json and `rack-graphql` catches all exceptions and does NOT re-raise them. You can change this behavior via `re_raise_exceptions` argument.
88
+ Because of this, using error tracking middleware (`use Sentry::Rack::CaptureExceptions`, `use Raven::Rack`) does not take any effect for graphql requests.
89
+
90
+ To use Sentry or other reporting tool for graphql queries, you can use `GraphQL::Schema` middleware:
91
+
92
+ ```ruby
93
+ class GraphqlErrorTrackerMiddleware
94
+ def self.call(parent_type, parent_object, field_definition, field_args, query_context)
95
+ yield
96
+ rescue StandardError => e
97
+ extra = {
98
+ parent_type: parent_type.inspect,
99
+ parent_object: parent_object.inspect,
100
+ field_definition: field_definition.to_s,
101
+ field_args: field_args&.to_h,
102
+ query_context: query_context&.to_h
103
+ }
104
+ Sentry.capture_exception(e, extra: extra)
105
+ raise
106
+ end
107
+ end
108
+
109
+ # MySchema.middleware GraphqlErrorTrackerMiddleware
110
+ # or
111
+ # GraphQL::Schema.middleware GraphqlErrorTrackerMiddleware
112
+ # or
113
+ # class MySchema < GraphQL::Schema
114
+ # middleware GraphqlErrorTrackerMiddleware
115
+ # end
116
+ ```
117
+
82
118
  ## Contributing
83
119
 
84
120
  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.
@@ -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
@@ -5,6 +5,7 @@ module RackGraphql
5
5
  app_name: 'rack-graphql-service',
6
6
  logger: nil,
7
7
  context_handler: nil,
8
+ re_raise_exceptions: false,
8
9
  log_exception_backtrace: RackGraphql.log_exception_backtrace,
9
10
  health_route: true,
10
11
  health_response_builder: RackGraphql::HealthResponseBuilder,
@@ -17,6 +18,7 @@ module RackGraphql
17
18
  app_name: app_name,
18
19
  schema: schema,
19
20
  context_handler: context_handler,
21
+ re_raise_exceptions: re_raise_exceptions,
20
22
  logger: logger,
21
23
  log_exception_backtrace: log_exception_backtrace,
22
24
  error_status_code_map: error_status_code_map,
@@ -1,6 +1,8 @@
1
1
  module RackGraphql
2
2
  class Middleware
3
+ DEFAULT_STATUS_CODE = 200
3
4
  DEFAULT_ERROR_STATUS_CODE = 500
5
+ NULL_BYTE = '\u0000'.freeze
4
6
 
5
7
  def initialize(
6
8
  schema:,
@@ -8,6 +10,7 @@ module RackGraphql
8
10
  context_handler: nil,
9
11
  logger: nil,
10
12
  log_exception_backtrace: RackGraphql.log_exception_backtrace,
13
+ re_raise_exceptions: false,
11
14
  error_status_code_map: {}
12
15
  )
13
16
 
@@ -16,6 +19,7 @@ module RackGraphql
16
19
  @context_handler = context_handler || ->(_) {}
17
20
  @logger = logger
18
21
  @log_exception_backtrace = log_exception_backtrace
22
+ @re_raise_exceptions = re_raise_exceptions
19
23
  @error_status_code_map = error_status_code_map
20
24
  end
21
25
 
@@ -34,7 +38,7 @@ module RackGraphql
34
38
  result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
35
39
 
36
40
  [
37
- 200,
41
+ response_status(result),
38
42
  response_headers(result),
39
43
  [response_body(result)]
40
44
  ]
@@ -50,9 +54,14 @@ module RackGraphql
50
54
  ]
51
55
  rescue StandardError, LoadError, SyntaxError => e
52
56
  # To respect the graphql spec, all errors need to be returned as json.
53
- # It needs to take Rack::ShowExceptions role of catching all exceptions raised by the app.
57
+ # By default exceptions are not re-raised,
58
+ # so they cannot be caught by error tracking rack middlewares.
59
+ # You can change this behavior via `re_raise_exceptions` argument.
54
60
  exception_string = dump_exception(e)
55
61
  log(exception_string)
62
+
63
+ raise e if re_raise_exceptions
64
+
56
65
  env[Rack::RACK_ERRORS].puts(exception_string)
57
66
  env[Rack::RACK_ERRORS].flush
58
67
  [
@@ -66,14 +75,18 @@ module RackGraphql
66
75
 
67
76
  private
68
77
 
69
- attr_reader :schema, :app_name, :logger, :context_handler, :log_exception_backtrace, :error_status_code_map
78
+ attr_reader :schema, :app_name, :logger, :context_handler,
79
+ :log_exception_backtrace, :error_status_code_map, :re_raise_exceptions
70
80
 
71
81
  def post_request?(env)
72
82
  env['REQUEST_METHOD'] == 'POST'
73
83
  end
74
84
 
75
85
  def post_data(env)
76
- ::Oj.load(env['rack.input'].gets.to_s)
86
+ payload = env['rack.input'].read.to_s
87
+ return nil if payload.index(NULL_BYTE)
88
+
89
+ ::Oj.load(payload)
77
90
  rescue Oj::ParseError
78
91
  nil
79
92
  end
@@ -136,6 +149,13 @@ module RackGraphql
136
149
  end
137
150
  end
138
151
 
152
+ def response_status(result)
153
+ return DEFAULT_STATUS_CODE if result.is_a?(Array)
154
+
155
+ errors = result.to_h["errors"] || []
156
+ errors.map { |e| e["http_status"] }.compact.first || DEFAULT_STATUS_CODE
157
+ end
158
+
139
159
  def response_body(result = nil)
140
160
  if result_subscription?(result)
141
161
  body = result.to_h
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '2.3.0'.freeze
2
+ VERSION = '2.6.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)}) }
@@ -35,6 +36,6 @@ Gem::Specification.new do |spec|
35
36
  spec.add_development_dependency 'rake'
36
37
  spec.add_development_dependency 'rspec'
37
38
  spec.add_development_dependency 'rubocop'
38
- spec.add_development_dependency 'rubocop-performance'
39
+ spec.add_development_dependency 'rubocop-rake'
39
40
  spec.add_development_dependency 'rubocop-rspec'
40
41
  end
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.3.0
4
+ version: 2.6.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-30 00:00:00.000000000 Z
12
+ date: 2021-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -152,7 +152,7 @@ dependencies:
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
- name: rubocop-performance
155
+ name: rubocop-rake
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
@@ -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.2.3
235
237
  signing_key:
236
238
  specification_version: 4
237
239
  summary: Rack middleware implementing graphql endpoint.