graphql-permissions 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +33 -3
- data/graphql-permissions.gemspec +1 -1
- data/lib/graphql/permissions/interface_permissions.rb +1 -1
- data/lib/graphql/permissions/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acad633b6804921ff87dd79146fc94ca570025f8193befafa6cfa72d7d96da17
|
4
|
+
data.tar.gz: 5e4271b38e08dd0d90ae6e577e378cbb804170ee2fecad4e38f08ac27c249497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e75e87548d22f8f1d4c89e3b6019022fe93b0dc9bcc86c91bf7ceb43289467f64904dd9eaf57241d718717db2e54344d61e4dafb7c90fa38d4e760218d0e0bc8
|
7
|
+
data.tar.gz: 51bd2550553f9412c30a8509f332c3000f0f2acfb047e298777cf6aec2944ecf82959d834a55dbc82b5081b7db9a63379b76893c8bd1fe94b6e7e367e17aee51
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphql-permissions (0.1.
|
5
|
-
graphql
|
4
|
+
graphql-permissions (0.1.1)
|
5
|
+
graphql (~> 2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
-
graphql (2.0.
|
11
|
+
graphql (2.0.15)
|
12
12
|
parallel (1.22.1)
|
13
13
|
parser (3.1.2.0)
|
14
14
|
ast (~> 2.4.1)
|
data/README.md
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
# GraphQL::Permissions
|
2
2
|
|
3
|
-
|
3
|
+
GraphQL Permissions allows you to model permissions directly in your GraphQL schema. It works together with your authorization library to communicate which actions are and are not allowed to your client.
|
4
4
|
|
5
|
-
|
5
|
+
At the highest level, it lets you write queries like this:
|
6
|
+
```graphql
|
7
|
+
query PostById($id: ID!) {
|
8
|
+
post(id: $id) {
|
9
|
+
id
|
10
|
+
body
|
11
|
+
permissions {
|
12
|
+
canEdit
|
13
|
+
canDelete
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
```
|
18
|
+
|
19
|
+
This helps keep all of your authorization logic in one place, and prevent disagreements between the server and client about whether a user can perform an action.
|
20
|
+
|
21
|
+
GraphQL Permissions was designed with the [Pundit](https://github.com/varvet/pundit) gem in mind, but should work with most authorization libraries.
|
6
22
|
|
7
23
|
## Installation
|
8
24
|
|
@@ -24,7 +40,21 @@ Then run the Rails generator:
|
|
24
40
|
|
25
41
|
$ bin/rails generate graphql:permissions:install
|
26
42
|
|
27
|
-
This will create the base permissions object and interface types, as well as an initializer
|
43
|
+
This will create the base permissions object and interface types, as well as an initializer in `config/initializers/graphql_permissions.rb`
|
44
|
+
|
45
|
+
### Configuring a Permission Handler
|
46
|
+
|
47
|
+
GraphQL Permissions requires a default permission handler callback to be defined by your application. This callback receives the action performed, the object being authorized, and your GraphQL context, and must return a Boolean value to indicate whether the action is or is not allowed.
|
48
|
+
|
49
|
+
For example, integration for the Pundit gem might look like so:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
GraphQL::Permissions.default_permission_handler = lambda do |action, object, context|
|
53
|
+
Pundit.policy(context[:current_user], object).send(:"#{action}?")
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
A stub permissions handler callback is defined under `config/initializers/graphql_permissions.rb` by the Rails generator.
|
28
58
|
|
29
59
|
## Usage
|
30
60
|
|
data/graphql-permissions.gemspec
CHANGED
@@ -18,7 +18,7 @@ module GraphQL
|
|
18
18
|
|
19
19
|
# @return [Array<Module>]
|
20
20
|
def interfaces_with_permissions
|
21
|
-
|
21
|
+
interfaces.select { |interface| interface.respond_to?(:permissions_type) && interface.permissions_type }
|
22
22
|
end
|
23
23
|
|
24
24
|
def permissions(&block)
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-permissions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minty Fresh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
description: Expose user permissions in your GraphQL schema
|
28
28
|
email:
|
29
29
|
- 7896757+mintyfresh@users.noreply.github.com
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.3.7
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Permissions DSL for GraphQL Ruby
|