rack-graphql 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afa1d729bd08ddcda6bb8f5b0d6a64b7c4d339bb96abc34ae75840cb30c00175
4
- data.tar.gz: a0fe1c3fb2b0aa9104f44db024305f98f9901567fd5f3765c8c5b5b76bd55c4e
3
+ metadata.gz: e69b413c11c9ffcfe8f71f6028e1705b1ce41866f534b8f5a334b250e62555d4
4
+ data.tar.gz: 802e055347ec762a5d8d2fe7bb21a1cfa550bdf1025252c1b4d64223fc34773e
5
5
  SHA512:
6
- metadata.gz: 2793fd223e882a6e91f4389d65dd9a95e4ec40df68c77d11392599c1775ec04228287a797781e01c41dba5d4972fd5ac13b03346c6e78a87b7cd99467d3e5c32
7
- data.tar.gz: f4feff581c4ea565a2bb5672a45fd6aac01d7f8cd4962b53eecab128ba41e81b66e931deb28615dcaef4e53ca58fd766be7230d904dd03ac8be3524add09d24c
6
+ metadata.gz: d1287d8512398086dc312be90fa689abf0107afa9503b871570d4185e670033e9bc5f7c970ee5d2cf0e4074f681dcd7a83fc1559256df6a8d6d5aeed7ba6cf42
7
+ data.tar.gz: 46d1ea9285fcc9fee9db13e7374539361bca874474086dec3fd98b2d09a4df54015fc96e5d3bb47abedbfaa5ada2caa6f4bc01926c11807457033de9929ff729
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (0.2.0)
4
+ rack-graphql (0.3.0)
5
5
  graphql (>= 1.9.0)
6
6
  multi_json
7
7
  rack (>= 2.0.0)
data/README.md CHANGED
@@ -3,9 +3,11 @@
3
3
 
4
4
  # rack-graphql
5
5
 
6
- Rack middleware implementing graphql endpoint for ruby (non-`ActionController`) services. It uses pure rack and none of `ActionController` or `Sinatra` is required. By default it implements health route on `/health` and `/`, since it's only expected to be used on graphql-only services.
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 also handles [subscriptions](https://graphql-ruby.org/guides#subscriptions-guides) and [multiplex](https://graphql-ruby.org/queries/multiplex.html).
8
+ It works on pure rack and none of `ActionController`/`ActionDispatch`/`ActionPack` or `Sinatra` is required.
9
+
10
+ It can be used together with rails to not make graphql requests be routed with `ActionDispatch` or more pure ruby apps.
9
11
 
10
12
  ## Installation
11
13
 
@@ -17,18 +19,16 @@ gem 'rack-graphql'
17
19
 
18
20
  ## Usage example
19
21
 
20
- Add to your `config.ru` file
22
+ Add following to your `config.ru` file:
21
23
 
22
24
  ```ruby
23
- run RackGraphql::Application.call(
24
- schema: YourGraqphqlSchema, # required
25
- app_name: 'your-service-name', # optional, used for health route
26
- context_handler: YourGraphqlContextHandler, # optional, empty proc by default
27
- health_route: true, # optional, true by default
25
+ run RackGraphql::Application.call(
26
+ schema: YourGraqphqlSchema, # required
27
+ context_handler: YourGraphqlContextHandler # optional, empty `proc` by default
28
28
  )
29
29
  ```
30
30
 
31
- `context_handler` can be a class, object or proc. It only must respond to `call` merhod taking `env` as an argument. It is supposed to decode request properties to graphql context (eg. jwt token to user object, as shown below).
31
+ `context_handler` can be a class, object or proc. It must respond to `call` method taking `env` as an argument. It is supposed to decode or transform request properties to graphql context (eg. jwt token to user object, as shown on an example below).
32
32
 
33
33
  ### Example: using context handler for JWT authentication
34
34
 
@@ -61,7 +61,7 @@ class GraphqlContextHandler
61
61
  return unless payload
62
62
  return unless payload['user_id']
63
63
 
64
- UserRepo.find_by_id(payload['user_id])
64
+ UserRepo.find_by_id(payload['user_id'])
65
65
  end
66
66
  end
67
67
  end
data/lib/rack-graphql.rb CHANGED
@@ -3,6 +3,5 @@ require 'rack'
3
3
  require 'graphql'
4
4
 
5
5
  require 'rack_graphql/version'
6
- require 'rack_graphql/health_response_builder'
7
6
  require 'rack_graphql/middleware'
8
7
  require 'rack_graphql/application'
@@ -1,20 +1,10 @@
1
1
  module RackGraphql
2
2
  class Application
3
- def self.call(schema:, app_name: 'rack-graphql-service', context_handler: nil, health_route: true)
3
+ def self.call(schema:, context_handler: nil)
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
18
8
  end
19
9
  end
20
10
  end
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-06-13 00:00:00.000000000 Z
12
+ date: 2019-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql
@@ -160,7 +160,6 @@ 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
164
163
  - lib/rack_graphql/middleware.rb
165
164
  - lib/rack_graphql/version.rb
166
165
  - rack-graphql.gemspec
@@ -1,29 +0,0 @@
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