rack-graphql 0.1.0 → 0.2.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: bacf440a72a93e3a15d93d3250673e3e881a7b9c00baeb23a3b492a7bd173726
4
- data.tar.gz: b025f5b71e3523a9cb420eeb7e84b32244e7b8b2733e2e9233534e7fd15b3235
3
+ metadata.gz: afa1d729bd08ddcda6bb8f5b0d6a64b7c4d339bb96abc34ae75840cb30c00175
4
+ data.tar.gz: a0fe1c3fb2b0aa9104f44db024305f98f9901567fd5f3765c8c5b5b76bd55c4e
5
5
  SHA512:
6
- metadata.gz: 37c256d2391cd25a8100885dc46bd7fe09b43441204f8f6265664663759c0bfe5e0329f59e421181074f8153d4eb4f778f6eeb27353053b79608cf5e596c0271
7
- data.tar.gz: 017c9499ad224dd3ff714f4f28438c69298be871222ed2a639e5ce4bab3f2207b8c645dd3164ddd0628a300d30f6dde84d1a85aebd6bbaec63f64a5ac9c5ca33
6
+ metadata.gz: 2793fd223e882a6e91f4389d65dd9a95e4ec40df68c77d11392599c1775ec04228287a797781e01c41dba5d4972fd5ac13b03346c6e78a87b7cd99467d3e5c32
7
+ data.tar.gz: f4feff581c4ea565a2bb5672a45fd6aac01d7f8cd4962b53eecab128ba41e81b66e931deb28615dcaef4e53ca58fd766be7230d904dd03ac8be3524add09d24c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-graphql (0.1.0)
4
+ rack-graphql (0.2.0)
5
5
  graphql (>= 1.9.0)
6
6
  multi_json
7
7
  rack (>= 2.0.0)
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
- [![Gem Version](https://badge.fury.io/rb/rack-pagination.svg)](https://rubygems.org/gems/rack-graphql)
2
- [![Build Status](https://travis-ci.org/RenoFi/rack-pagination.svg?branch=master)](https://travis-ci.org/RenoFi/rack-graphql)
1
+ [![Gem Version](https://badge.fury.io/rb/rack-graphql.svg)](https://rubygems.org/gems/rack-graphql)
2
+ [![Build Status](https://travis-ci.org/RenoFi/rack-graphql.svg?branch=master)](https://travis-ci.org/RenoFi/rack-graphql)
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.
7
+
8
+ It also handles [subscriptions](https://graphql-ruby.org/guides#subscriptions-guides) and [multiplex](https://graphql-ruby.org/queries/multiplex.html).
6
9
 
7
10
  ## Installation
8
11
 
@@ -14,6 +17,55 @@ gem 'rack-graphql'
14
17
 
15
18
  ## Usage example
16
19
 
20
+ Add to your `config.ru` file
21
+
22
+ ```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
28
+ )
29
+ ```
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).
32
+
33
+ ### Example: using context handler for JWT authentication
34
+
35
+ ```ruby
36
+ class GraphqlContextHandler
37
+ class << self
38
+ def call(env)
39
+ payload = decode_payload(env)
40
+
41
+ graphql_context_hash(payload)
42
+ end
43
+
44
+ private
45
+
46
+ def graphql_context_hash(payload)
47
+ {
48
+ current_user: current_user(payload)
49
+ }
50
+ end
51
+
52
+ def decode_payload(env)
53
+ jwt = env["HTTP_AUTHORIZATION"].to_s.split(' ').last
54
+
55
+ return if jwt.blank?
56
+
57
+ DecodeJwt.call(jwt) || {}
58
+ end
59
+
60
+ def current_user(payload)
61
+ return unless payload
62
+ return unless payload['user_id']
63
+
64
+ UserRepo.find_by_id(payload['user_id])
65
+ end
66
+ end
67
+ end
68
+ ```
17
69
 
18
70
  ## Contributing
19
71
 
@@ -1,17 +1,19 @@
1
1
  module RackGraphql
2
2
  class Application
3
- def self.call(schema:, app_name: 'rack-graphql-service', 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
8
 
9
- map '/health' do
10
- run ->(env) { RackGraphql::HealthResponseBuilder.new(app_name: app_name).build }
11
- end
9
+ if health_route
10
+ map '/health' do
11
+ run ->(env) { RackGraphql::HealthResponseBuilder.new(app_name: app_name).build }
12
+ end
12
13
 
13
- map '/' do
14
- run ->(env) { RackGraphql::HealthResponseBuilder.new(app_name: app_name).build }
14
+ map '/' do
15
+ run ->(env) { RackGraphql::HealthResponseBuilder.new(app_name: app_name).build }
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -1,3 +1,3 @@
1
1
  module RackGraphql
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/rack-graphql.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
+ spec.required_ruby_version = '>= 2.4'
26
+
25
27
  spec.add_dependency 'graphql', '>= 1.9.0'
26
28
  spec.add_dependency 'multi_json'
27
29
  spec.add_dependency 'rack', '>= 2.0.0'
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Knapik
@@ -178,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
178
  requirements:
179
179
  - - ">="
180
180
  - !ruby/object:Gem::Version
181
- version: '0'
181
+ version: '2.4'
182
182
  required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - ">="