stardust_rails 0.1.3 → 0.1.4
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/README.md +49 -0
- data/app/controllers/stardust/graphql_controller.rb +6 -1
- data/lib/stardust/errors/failed_authorization.rb +6 -0
- data/lib/stardust/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4da8d57c78d5f8b8846e37bda9834e3ad13ff610d1898cff611705bc82786272
|
4
|
+
data.tar.gz: 7063dd3eeb686ccf9a7896b42bd594f37f64971be7113aabd035d72ef194e0b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff316897ecb898b079c5c49c58e944fbfdb658c65132e00698522333dbf4037d4aaa65d42b72d26987dce94c73d85d5154ffe45bd4f9bc6bf52b052b3a5f030
|
7
|
+
data.tar.gz: b132e3d1f5969db1d5f1da57c32391d9d73aaac8d69dc3425c18e571a06ce9be31c4e2c9483539b399b06347c4822d606176c7c58468f31d32e8ae831b16c4de
|
data/README.md
CHANGED
@@ -78,6 +78,53 @@ Stardust::GraphQL.define_query :items do
|
|
78
78
|
end
|
79
79
|
```
|
80
80
|
|
81
|
+
### Authorization
|
82
|
+
|
83
|
+
|
84
|
+
#### Initializer
|
85
|
+
To use authorization with this gem, you must set it up with an initializer to process setup the context in light of the request.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
Stardust.configure do |config|
|
89
|
+
|
90
|
+
config.configure_graphql do |graphql|
|
91
|
+
# Hook to setup context
|
92
|
+
graphql.setup_context do |request|
|
93
|
+
{
|
94
|
+
current_user: Accounts::User::VerifyAuthorization.(request),
|
95
|
+
ip: request.remote_ip,
|
96
|
+
user_agent: request.headers["HTTP_USER_AGENT"],
|
97
|
+
timezone: "Eastern Time (US & Canada)"
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
In the code above there was an authorizer method to get the current user.
|
105
|
+
|
106
|
+
**Authorizer method**
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
Accounts::User::VerifyAuthorization.(request)
|
110
|
+
```
|
111
|
+
|
112
|
+
This is not presently built into the stardust_rails gem. You will need to provide your own method for processing the request.
|
113
|
+
|
114
|
+
<hr/>
|
115
|
+
|
116
|
+
#### Queries and Mutations
|
117
|
+
|
118
|
+
For a query or mutation, define self.authorized?(_,ctx) on your class. Within that you may define whatever you'd like for specifying who has access to run it.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
def self.authorized?(_, ctx)
|
122
|
+
ctx[:current_user]
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
|
127
|
+
|
81
128
|
### Type
|
82
129
|
|
83
130
|
```ruby
|
@@ -94,6 +141,8 @@ end
|
|
94
141
|
|
95
142
|
|
96
143
|
|
144
|
+
|
145
|
+
|
97
146
|
## Installation
|
98
147
|
Add this line to your application's Gemfile:
|
99
148
|
|
@@ -3,7 +3,7 @@ module Stardust
|
|
3
3
|
|
4
4
|
def execute
|
5
5
|
result = nil
|
6
|
-
|
6
|
+
|
7
7
|
around_execute do
|
8
8
|
result = GraphQL::Schema.execute(
|
9
9
|
query,
|
@@ -14,6 +14,11 @@ module Stardust
|
|
14
14
|
end
|
15
15
|
render json: result
|
16
16
|
|
17
|
+
|
18
|
+
rescue Stardust::Errors::FailedAuthorization => e
|
19
|
+
render json: {
|
20
|
+
error: { message: e.message }
|
21
|
+
}, status: 401
|
17
22
|
rescue StandardError => e
|
18
23
|
raise e unless Rails.env.development?
|
19
24
|
handle_error_in_development e
|
data/lib/stardust/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stardust_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley Wittenbrook
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/stardust.rb
|
117
117
|
- lib/stardust/configuration.rb
|
118
118
|
- lib/stardust/engine.rb
|
119
|
+
- lib/stardust/errors/failed_authorization.rb
|
119
120
|
- lib/stardust/generators.rb
|
120
121
|
- lib/stardust/generators/example.rb
|
121
122
|
- lib/stardust/generators/mutation.rb
|