rack-graphql 0.3.0 → 0.4.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/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/rack-graphql.rb +1 -0
- data/lib/rack_graphql/application.rb +11 -1
- data/lib/rack_graphql/health_response_builder.rb +29 -0
- data/lib/rack_graphql/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f6210f9dd519a4d0126f0233030a78dd9bcaa7c3d461cbe0444dafb71b9390
|
4
|
+
data.tar.gz: aa3f41e2f0630c77f0863c29299dac49c1ac54ec35f43ce4c18b6725755c0955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a873134d698b5e0841a38d81a8ea91c876b396f194b5774b4dbad66ce302b1fcc5cb16defefd71a41a445b37cf44b6202187f2528ad12dcc4820c57f1681dc03
|
7
|
+
data.tar.gz: 799751d5575822fe3a8553779ed4bd7a24d717344065b39d98c4cc9f7066e2d6432fc63caa02f4a435555e47fb61f0dc39f692e50f89e73ef4c6456010491b08
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
`rack-graphql` is designed to build ruby services with graphql api. It provides `/graphql` endpoint and can handle [subscriptions](https://graphql-ruby.org/guides#subscriptions-guides) and [multiplex](https://graphql-ruby.org/queries/multiplex.html).
|
7
7
|
|
8
|
-
It works on pure rack and none of `ActionController`/`ActionDispatch`/`ActionPack` or `Sinatra` is required.
|
8
|
+
It works on pure rack and none of `ActionController`/`ActionDispatch`/`ActionPack` or `Sinatra` is required. By default it provides health route on `/health` and `/`, which can be disabled.
|
9
9
|
|
10
10
|
It can be used together with rails to not make graphql requests be routed with `ActionDispatch` or more pure ruby apps.
|
11
11
|
|
@@ -23,8 +23,10 @@ Add following to your `config.ru` file:
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
run RackGraphql::Application.call(
|
26
|
-
schema: YourGraqphqlSchema,
|
27
|
-
|
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
|
+
health_route: true, # optional, true by default
|
28
30
|
)
|
29
31
|
```
|
30
32
|
|
data/lib/rack-graphql.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
module RackGraphql
|
2
2
|
class Application
|
3
|
-
def self.call(schema:, context_handler: nil)
|
3
|
+
def self.call(schema:, app_name: 'rack-graphql-service', context_handler: nil, health_route: true)
|
4
4
|
::Rack::Builder.new do
|
5
5
|
map '/graphql' do
|
6
6
|
run RackGraphql::Middleware.new(schema: schema, context_handler: context_handler)
|
7
7
|
end
|
8
|
+
|
9
|
+
if health_route
|
10
|
+
map '/health' do
|
11
|
+
run ->(env) { RackGraphql::HealthResponseBuilder.new(app_name: app_name).build }
|
12
|
+
end
|
13
|
+
|
14
|
+
map '/' do
|
15
|
+
run ->(env) { RackGraphql::HealthResponseBuilder.new(app_name: app_name).build }
|
16
|
+
end
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RackGraphql
|
2
|
+
class HealthResponseBuilder
|
3
|
+
def initialize(app_name:)
|
4
|
+
@app_name = app_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def build
|
8
|
+
[200, headers, [body]]
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
attr_reader :app_name
|
14
|
+
|
15
|
+
def headers
|
16
|
+
{ 'Content-Type' => 'application/json' }
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
MultiJson.dump(
|
21
|
+
status: :ok,
|
22
|
+
app_name: app_name,
|
23
|
+
env: ENV['RACK_ENV'],
|
24
|
+
host: ENV['HOSTNAME'],
|
25
|
+
revision: ENV['REVISION']
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/rack_graphql/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Knapik
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/rack-graphql.rb
|
161
161
|
- lib/rack_graphql.rb
|
162
162
|
- lib/rack_graphql/application.rb
|
163
|
+
- lib/rack_graphql/health_response_builder.rb
|
163
164
|
- lib/rack_graphql/middleware.rb
|
164
165
|
- lib/rack_graphql/version.rb
|
165
166
|
- rack-graphql.gemspec
|