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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -10
- data/lib/rack-graphql.rb +0 -1
- data/lib/rack_graphql/application.rb +1 -11
- data/lib/rack_graphql/version.rb +1 -1
- metadata +2 -3
- data/lib/rack_graphql/health_response_builder.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69b413c11c9ffcfe8f71f6028e1705b1ce41866f534b8f5a334b250e62555d4
|
4
|
+
data.tar.gz: 802e055347ec762a5d8d2fe7bb21a1cfa550bdf1025252c1b4d64223fc34773e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1287d8512398086dc312be90fa689abf0107afa9503b871570d4185e670033e9bc5f7c970ee5d2cf0e4074f681dcd7a83fc1559256df6a8d6d5aeed7ba6cf42
|
7
|
+
data.tar.gz: 46d1ea9285fcc9fee9db13e7374539361bca874474086dec3fd98b2d09a4df54015fc96e5d3bb47abedbfaa5ada2caa6f4bc01926c11807457033de9929ff729
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
|
4
4
|
# rack-graphql
|
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
|
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,
|
25
|
-
|
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
|
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
@@ -1,20 +1,10 @@
|
|
1
1
|
module RackGraphql
|
2
2
|
class Application
|
3
|
-
def self.call(schema:,
|
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
|
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.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-
|
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
|