rack-graphql 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -5
- data/lib/rack_graphql/application.rb +10 -3
- data/lib/rack_graphql/middleware.rb +5 -4
- 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: 89001cf0e27af277a4e74c423e6ebaed600057a5528d9c0b850a76f704690454
|
4
|
+
data.tar.gz: d5250dddf85e2203701d5357f6479001294e64f7d3f28457bc10b55698e0f0c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0975735f7f595af62aeece22cb537e454eef1608b0f012af59e0cc65e14b3015c1db2dd9b7e15402b19bbf1cf564e9982bcd8c79c22681e486d23ae2a96be25
|
7
|
+
data.tar.gz: 508d6a5276bfbc8914c9870e4cfa390455ef687634f7de4fc314f28f2c19feedcf7f78de7a39add4543947a44e08e1b0e2de978a1598ac3e8369e5c921c12140
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,11 +23,12 @@ Add following to your `config.ru` file:
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
run RackGraphql::Application.call(
|
26
|
-
schema: YourGraqphqlSchema,
|
27
|
-
app_name: 'your-service-name',
|
28
|
-
context_handler: YourGraphqlContextHandler,
|
29
|
-
|
30
|
-
|
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
|
31
32
|
)
|
32
33
|
```
|
33
34
|
|
@@ -1,11 +1,18 @@
|
|
1
1
|
module RackGraphql
|
2
2
|
class Application
|
3
|
-
def self.call(
|
4
|
-
|
3
|
+
def self.call(
|
4
|
+
schema:,
|
5
|
+
app_name: 'rack-graphql-service',
|
6
|
+
logger: nil,
|
7
|
+
context_handler: nil,
|
8
|
+
log_exception_backtrace: RackGraphql.log_exception_backtrace,
|
9
|
+
health_route: true,
|
10
|
+
health_response_builder: RackGraphql::HealthResponseBuilder
|
11
|
+
)
|
5
12
|
|
6
13
|
::Rack::Builder.new do
|
7
14
|
map '/graphql' do
|
8
|
-
run RackGraphql::Middleware.new(schema: schema, context_handler: context_handler, logger: logger)
|
15
|
+
run RackGraphql::Middleware.new(schema: schema, context_handler: context_handler, log_exception_backtrace: log_exception_backtrace, logger: logger)
|
9
16
|
end
|
10
17
|
|
11
18
|
if health_route
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module RackGraphql
|
2
2
|
class Middleware
|
3
|
-
def initialize(schema:, logger: nil, context_handler: nil)
|
3
|
+
def initialize(schema:, logger: nil, context_handler: nil, log_exception_backtrace: RackGraphql.log_exception_backtrace)
|
4
4
|
@schema = schema
|
5
5
|
@logger = logger
|
6
6
|
@context_handler = context_handler || ->(_) {}
|
7
|
+
@log_exception_backtrace = log_exception_backtrace
|
7
8
|
end
|
8
9
|
|
9
10
|
def call(env)
|
@@ -53,7 +54,7 @@ module RackGraphql
|
|
53
54
|
|
54
55
|
private
|
55
56
|
|
56
|
-
attr_reader :schema, :logger, :context_handler
|
57
|
+
attr_reader :schema, :logger, :context_handler, :log_exception_backtrace
|
57
58
|
|
58
59
|
def post_request?(env)
|
59
60
|
env['REQUEST_METHOD'] == 'POST'
|
@@ -151,14 +152,14 @@ module RackGraphql
|
|
151
152
|
# Based on https://github.com/rack/rack/blob/master/lib/rack/show_exceptions.rb
|
152
153
|
def dump_exception(exception)
|
153
154
|
string = "#{exception.class}: #{exception.message}\n"
|
154
|
-
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n") if
|
155
|
+
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n") if log_exception_backtrace
|
155
156
|
string
|
156
157
|
end
|
157
158
|
|
158
159
|
def exception_hash(exception)
|
159
160
|
{
|
160
161
|
message: "#{exception.class}: #{exception.message}",
|
161
|
-
backtrace:
|
162
|
+
backtrace: log_exception_backtrace ? exception.backtrace : "[FILTERED]"
|
162
163
|
}
|
163
164
|
end
|
164
165
|
end
|
data/lib/rack_graphql/version.rb
CHANGED