rack-graphql 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundler-version +1 -1
- data/.dependabot/config.yml +3 -0
- data/.github/workflows/auto-merge.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +18 -15
- data/lib/rack_graphql/middleware.rb +12 -7
- data/lib/rack_graphql/version.rb +1 -1
- data/rack-graphql.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d6b07dd0b65feaf7bf1f42b8f5ed607e47c865a6fb1c774b8c79265a699618
|
4
|
+
data.tar.gz: c733bce94eae77c43c12ce94213c049ca20dea104da4a46de5a3ae182cbf3a44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de1e1d0ad8a05da26ab297161a06df874d0a2192c3ea3c9d98e6501ee0b4f6af1844c0d5b79ddad668f25bda11bb5eafb16c97fe2627c4b6783e05cb973e03b0
|
7
|
+
data.tar.gz: b421f740d27f958728fb07f287ae4666cec11e7312362ae863a7d5f120b1241f2fdd163fc640f7565e369fc9bd81d4956893a2342b2f47ee08d9a10aae5de355
|
data/.bundler-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3
|
1
|
+
2.4.3
|
data/.dependabot/config.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.1.0 - 2023-01-17
|
4
|
+
|
5
|
+
- Add X-Http-Status-Code to every response, so clients can recognize graphql errors w/o parsing gql response.
|
6
|
+
|
7
|
+
## 3.0.1 - 2023-01-17
|
8
|
+
|
9
|
+
- allow running on rack 2.x, so it can work with apps having sinatra installed (sinatra doesn't support rack 3.x)
|
10
|
+
|
3
11
|
## 3.0.0 - 2022-12-15
|
4
12
|
|
5
13
|
- support rack 3.x and graphql 2.x
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-graphql (3.
|
4
|
+
rack-graphql (3.1.0)
|
5
5
|
graphql (~> 2.0)
|
6
6
|
oj
|
7
|
-
rack (
|
7
|
+
rack (>= 2.2.6)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -13,17 +13,17 @@ GEM
|
|
13
13
|
awesome_print (1.9.2)
|
14
14
|
coderay (1.1.3)
|
15
15
|
diff-lcs (1.5.0)
|
16
|
-
graphql (2.0.
|
16
|
+
graphql (2.0.16)
|
17
17
|
json (2.6.3)
|
18
18
|
method_source (1.0.0)
|
19
19
|
oj (3.13.23)
|
20
20
|
parallel (1.22.1)
|
21
|
-
parser (3.
|
21
|
+
parser (3.2.0.0)
|
22
22
|
ast (~> 2.4.1)
|
23
|
-
pry (0.14.
|
23
|
+
pry (0.14.2)
|
24
24
|
coderay (~> 1.1)
|
25
25
|
method_source (~> 1.0)
|
26
|
-
rack (3.0.
|
26
|
+
rack (3.0.4)
|
27
27
|
rack-test (2.0.2)
|
28
28
|
rack (>= 1.3)
|
29
29
|
rainbow (3.1.1)
|
@@ -36,31 +36,34 @@ GEM
|
|
36
36
|
rspec-mocks (~> 3.12.0)
|
37
37
|
rspec-core (3.12.0)
|
38
38
|
rspec-support (~> 3.12.0)
|
39
|
-
rspec-expectations (3.12.
|
39
|
+
rspec-expectations (3.12.2)
|
40
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
41
|
rspec-support (~> 3.12.0)
|
42
|
-
rspec-mocks (3.12.
|
42
|
+
rspec-mocks (3.12.3)
|
43
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
44
|
rspec-support (~> 3.12.0)
|
45
45
|
rspec-support (3.12.0)
|
46
|
-
rubocop (1.
|
46
|
+
rubocop (1.43.0)
|
47
47
|
json (~> 2.3)
|
48
48
|
parallel (~> 1.10)
|
49
|
-
parser (>= 3.
|
49
|
+
parser (>= 3.2.0.0)
|
50
50
|
rainbow (>= 2.2.2, < 4.0)
|
51
51
|
regexp_parser (>= 1.8, < 3.0)
|
52
52
|
rexml (>= 3.2.5, < 4.0)
|
53
|
-
rubocop-ast (>= 1.
|
53
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
54
54
|
ruby-progressbar (~> 1.7)
|
55
|
-
unicode-display_width (>=
|
56
|
-
rubocop-ast (1.24.
|
55
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.24.1)
|
57
57
|
parser (>= 3.1.1.0)
|
58
|
+
rubocop-capybara (2.17.0)
|
59
|
+
rubocop (~> 1.41)
|
58
60
|
rubocop-rake (0.6.0)
|
59
61
|
rubocop (~> 1.0)
|
60
|
-
rubocop-rspec (2.
|
62
|
+
rubocop-rspec (2.18.0)
|
61
63
|
rubocop (~> 1.33)
|
64
|
+
rubocop-capybara
|
62
65
|
ruby-progressbar (1.11.0)
|
63
|
-
unicode-display_width (2.
|
66
|
+
unicode-display_width (2.4.2)
|
64
67
|
|
65
68
|
PLATFORMS
|
66
69
|
aarch64-linux-musl
|
@@ -2,6 +2,7 @@ module RackGraphql
|
|
2
2
|
class Middleware
|
3
3
|
DEFAULT_STATUS_CODE = 200
|
4
4
|
DEFAULT_ERROR_STATUS_CODE = 500
|
5
|
+
STATUS_CODE_HEADER_NAME = 'X-Http-Status-Code'.freeze
|
5
6
|
NULL_BYTE = '\u0000'.freeze
|
6
7
|
|
7
8
|
def initialize(
|
@@ -36,10 +37,11 @@ module RackGraphql
|
|
36
37
|
|
37
38
|
log("Executing with params: #{params.inspect}, operationName: #{operation_name}, variables: #{variables.inspect}")
|
38
39
|
result = execute(params: params, operation_name: operation_name, variables: variables, context: context)
|
40
|
+
status_code = response_status(result)
|
39
41
|
|
40
42
|
[
|
41
|
-
|
42
|
-
response_headers(result),
|
43
|
+
status_code,
|
44
|
+
response_headers(result, status_code: status_code),
|
43
45
|
[response_body(result)]
|
44
46
|
]
|
45
47
|
rescue AmbiguousParamError => e
|
@@ -49,7 +51,7 @@ module RackGraphql
|
|
49
51
|
env[Rack::RACK_ERRORS].flush
|
50
52
|
[
|
51
53
|
400,
|
52
|
-
{ 'Content-Type' => 'application/json' },
|
54
|
+
{ 'Content-Type' => 'application/json', STATUS_CODE_HEADER_NAME => 400 },
|
53
55
|
[Oj.dump({})]
|
54
56
|
]
|
55
57
|
rescue StandardError, LoadError, SyntaxError => e
|
@@ -64,9 +66,11 @@ module RackGraphql
|
|
64
66
|
|
65
67
|
env[Rack::RACK_ERRORS].puts(exception_string)
|
66
68
|
env[Rack::RACK_ERRORS].flush
|
69
|
+
|
70
|
+
status_code = error_status_code_map[e.class] || DEFAULT_ERROR_STATUS_CODE
|
67
71
|
[
|
68
|
-
|
69
|
-
{ 'Content-Type' => 'application/json' },
|
72
|
+
status_code,
|
73
|
+
{ 'Content-Type' => 'application/json', STATUS_CODE_HEADER_NAME => status_code },
|
70
74
|
[Oj.dump('errors' => [exception_hash(e)])]
|
71
75
|
]
|
72
76
|
ensure
|
@@ -140,10 +144,11 @@ module RackGraphql
|
|
140
144
|
schema.multiplex(queries)
|
141
145
|
end
|
142
146
|
|
143
|
-
def response_headers(result = nil)
|
147
|
+
def response_headers(result = nil, status_code: DEFAULT_STATUS_CODE)
|
144
148
|
{
|
145
149
|
'Access-Control-Expose-Headers' => 'X-Subscription-ID',
|
146
|
-
'Content-Type' => 'application/json'
|
150
|
+
'Content-Type' => 'application/json',
|
151
|
+
STATUS_CODE_HEADER_NAME => status_code,
|
147
152
|
}.tap do |headers|
|
148
153
|
headers['X-Subscription-ID'] = result.context[:subscription_id] if result_subscription?(result)
|
149
154
|
end
|
data/lib/rack_graphql/version.rb
CHANGED
data/rack-graphql.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_dependency 'graphql', '~> 2.0'
|
30
30
|
spec.add_dependency 'oj'
|
31
|
-
spec.add_dependency 'rack', '
|
31
|
+
spec.add_dependency 'rack', '>= 2.2.6'
|
32
32
|
|
33
33
|
spec.add_development_dependency 'awesome_print'
|
34
34
|
spec.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Knapik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.2.6
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.2.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: awesome_print
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|