rack-graphql 3.0.1 → 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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/rack_graphql/middleware.rb +12 -7
- data/lib/rack_graphql/version.rb +1 -1
- metadata +1 -1
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/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
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
|
+
|
3
7
|
## 3.0.1 - 2023-01-17
|
4
8
|
|
5
9
|
- allow running on rack 2.x, so it can work with apps having sinatra installed (sinatra doesn't support rack 3.x)
|
data/Gemfile.lock
CHANGED
@@ -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