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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e69b413c11c9ffcfe8f71f6028e1705b1ce41866f534b8f5a334b250e62555d4
4
- data.tar.gz: 802e055347ec762a5d8d2fe7bb21a1cfa550bdf1025252c1b4d64223fc34773e
3
+ metadata.gz: f1f6210f9dd519a4d0126f0233030a78dd9bcaa7c3d461cbe0444dafb71b9390
4
+ data.tar.gz: aa3f41e2f0630c77f0863c29299dac49c1ac54ec35f43ce4c18b6725755c0955
5
5
  SHA512:
6
- metadata.gz: d1287d8512398086dc312be90fa689abf0107afa9503b871570d4185e670033e9bc5f7c970ee5d2cf0e4074f681dcd7a83fc1559256df6a8d6d5aeed7ba6cf42
7
- data.tar.gz: 46d1ea9285fcc9fee9db13e7374539361bca874474086dec3fd98b2d09a4df54015fc96e5d3bb47abedbfaa5ada2caa6f4bc01926c11807457033de9929ff729
6
+ metadata.gz: a873134d698b5e0841a38d81a8ea91c876b396f194b5774b4dbad66ce302b1fcc5cb16defefd71a41a445b37cf44b6202187f2528ad12dcc4820c57f1681dc03
7
+ data.tar.gz: 799751d5575822fe3a8553779ed4bd7a24d717344065b39d98c4cc9f7066e2d6432fc63caa02f4a435555e47fb61f0dc39f692e50f89e73ef4c6456010491b08
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (0.3.0)
4
+ rack-graphql (0.4.0)
5
5
  graphql (>= 1.9.0)
6
6
  multi_json
7
7
  rack (>= 2.0.0)
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, # required
27
- context_handler: YourGraphqlContextHandler # optional, empty `proc` 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
+ health_route: true, # optional, true by default
28
30
  )
29
31
  ```
30
32
 
data/lib/rack-graphql.rb CHANGED
@@ -3,5 +3,6 @@ require 'rack'
3
3
  require 'graphql'
4
4
 
5
5
  require 'rack_graphql/version'
6
+ require 'rack_graphql/health_response_builder'
6
7
  require 'rack_graphql/middleware'
7
8
  require 'rack_graphql/application'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  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: 0.3.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