graphql-guard 1.3.0 → 1.3.1

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: b06636860d44863e738be1b6e7bfd9431559d4bb32271526144cdcdd2b8ad97c
4
- data.tar.gz: 47bd22cf638fd78deee5d1e6ff211ca465be8dfaacf2a792553bdd31a15fe892
3
+ metadata.gz: fbde911695d5151407974b87a6ddd6ab4e02c726685ed35c1c59ad270a541a3c
4
+ data.tar.gz: 877dfa834f5b5880fe11f020567d55dfda0e8e012e3ea3d6c2a4e8acb9ed6ce7
5
5
  SHA512:
6
- metadata.gz: 5ff2142a28b03afd323ec97755b3e4e3f21fd1b07246023b14154af1a31b783fad9bcda934e3c287adc3ce7dbf1fc76c3560f0650d9366078e4937e04203fefd
7
- data.tar.gz: 17a671a32a162bd40773509f07f94d50df969ed4060b1bd24b2fe44f734d04e2749816c04ac21e8f3f5f9f0a722b7b9ab2312489910bd2bd0ada2f00c0565749
6
+ metadata.gz: 5a485275f3e04a296a2fe0b5362aa8c15ee6002edab671f817758f4540ba05761675532d5b05b0ded05c78c05fd974e44c145085b8237aab59fb3df023e421a1
7
+ data.tar.gz: 52cade5337f95be53a0200663ecbe039a4026f63d21d54069b243676a65a23c594ada684defe85c194217caae0d1807ca487015196560a75a5fe2eab4adf786a
@@ -6,24 +6,24 @@ matrix:
6
6
  - gemfile: graphql-1.7.gemfile
7
7
  env: GRAPHQL_RUBY_VERSION=1_7 CI=true
8
8
  rvm: 2.3.8
9
- - gemfile: graphql-1.8.gemfile
10
- env: GRAPHQL_RUBY_VERSION=1_8 CI=true
9
+ - gemfile: graphql-latest.gemfile
10
+ env: GRAPHQL_RUBY_VERSION=LATEST CI=true
11
11
  rvm: 2.3.8
12
12
  - gemfile: graphql-1.7.gemfile
13
13
  env: GRAPHQL_RUBY_VERSION=1_7 CI=true
14
14
  rvm: 2.4.5
15
- - gemfile: graphql-1.8.gemfile
16
- env: GRAPHQL_RUBY_VERSION=1_8 CI=true
15
+ - gemfile: graphql-latest.gemfile
16
+ env: GRAPHQL_RUBY_VERSION=LATEST CI=true
17
17
  rvm: 2.4.5
18
18
  - gemfile: graphql-1.7.gemfile
19
19
  env: GRAPHQL_RUBY_VERSION=1_7 CI=true
20
20
  rvm: 2.5.7
21
- - gemfile: graphql-1.8.gemfile
22
- env: GRAPHQL_RUBY_VERSION=1_8 CI=true
21
+ - gemfile: graphql-latest.gemfile
22
+ env: GRAPHQL_RUBY_VERSION=LATEST CI=true
23
23
  rvm: 2.5.7
24
24
  - gemfile: graphql-1.7.gemfile
25
25
  env: GRAPHQL_RUBY_VERSION=1_7 CI=true
26
26
  rvm: 2.6.5
27
- - gemfile: graphql-1.8.gemfile
28
- env: GRAPHQL_RUBY_VERSION=1_8 CI=true
27
+ - gemfile: graphql-latest.gemfile
28
+ env: GRAPHQL_RUBY_VERSION=LATEST CI=true
29
29
  rvm: 2.6.5
@@ -12,6 +12,10 @@ that you can set version constraints properly.
12
12
 
13
13
  * WIP
14
14
 
15
+ #### [v1.3.1](https://github.com/exAspArk/graphql-guard/compare/v1.3.0...v1.3.1) – 2020-01-22
16
+
17
+ * `Fixed`: compatibility with `graphql` gem version 1.10. [#36](https://github.com/exAspArk/graphql-guard/pull/36)
18
+
15
19
  #### [v1.3.0](https://github.com/exAspArk/graphql-guard/compare/v1.2.2...v1.3.0) – 2019-10-24
16
20
 
17
21
  * `Added`: More descriptive default error message for `NotAuthorizedError`. [#32](https://github.com/exAspArk/graphql-guard/pull/32)
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "pry"
4
4
 
5
- gem "graphql", "~> 1.8.4"
5
+ gem "graphql", "~> 1.10"
6
6
 
7
7
  # Specify your gem's dependencies in graphql-guard.gemspec
8
8
  gemspec
data/README.md CHANGED
@@ -120,11 +120,20 @@ class <b>GraphqlPolicy</b>
120
120
  end
121
121
  </pre>
122
122
 
123
- With `graphql-ruby` gem version >= 1.8 and class-based type definitions, `type` doesn't return the actual type class [rmosolgo/graphql-ruby#1429](https://github.com/rmosolgo/graphql-ruby/issues/1429). To get the actual type class:
123
+ With `graphql-ruby` gem version >= 1.8 and class-based type definitions, use `camelCased` field names in the policy object.
124
+ You'd also need to use `type.metadata` (related to [rmosolgo/graphql-ruby#1429](https://github.com/rmosolgo/graphql-ruby/issues/1429)) to get the type class:
124
125
 
125
126
  <pre>
126
- def self.guard(type, field)
127
- RULES.dig(<b>type.metadata[:type_class]</b>, field)
127
+ class GraphqlPolicy
128
+ RULES = {
129
+ MutationType => {
130
+ <b>createPost</b>: ->(obj, args, cts) { ctx[:current_user].admin? }
131
+ }
132
+ }
133
+
134
+ def self.guard(type, field)
135
+ RULES.dig(<b>type.metadata[:type_class]</b>, field)
136
+ end
128
137
  end
129
138
  </pre>
130
139
 
@@ -3,6 +3,6 @@ source "https://rubygems.org"
3
3
  gem "pry"
4
4
  gem 'coveralls'
5
5
 
6
- gem "graphql", "~> 1.8.4"
6
+ gem "graphql", "~> 1.10"
7
7
 
8
8
  gemspec
@@ -19,13 +19,7 @@ module GraphQL
19
19
 
20
20
  def use(schema_definition)
21
21
  schema_definition.instrument(:field, self)
22
- schema_definition.target.instance_eval do
23
- def default_filter
24
- GraphQL::Filter.new(except: default_mask).merge(only: ->(schema_member, ctx) {
25
- schema_member.metadata[:mask] ? schema_member.metadata[:mask].call(ctx) : true
26
- })
27
- end
28
- end
22
+ add_schema_masking!(schema_definition)
29
23
  end
30
24
 
31
25
  def instrument(type, field)
@@ -55,6 +49,22 @@ module GraphQL
55
49
 
56
50
  private
57
51
 
52
+ def add_schema_masking!(schema_definition)
53
+ default_filter_proc = Proc.new do
54
+ def default_filter
55
+ GraphQL::Filter.new(except: default_mask).merge(only: ->(schema_member, ctx) {
56
+ schema_member.metadata[:mask] ? schema_member.metadata[:mask].call(ctx) : true
57
+ })
58
+ end
59
+ end
60
+
61
+ if schema_definition.is_a?(Class) # GraphQL-Ruby version >= 1.10
62
+ schema_definition.class_eval(&default_filter_proc)
63
+ else
64
+ schema_definition.target.instance_eval(&default_filter_proc)
65
+ end
66
+ end
67
+
58
68
  def policy_object_guard(type, field_name)
59
69
  policy_object && policy_object.guard(type, field_name)
60
70
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  class Guard
5
- VERSION = "1.3.0"
5
+ VERSION = "1.3.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - exAspArk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-24 00:00:00.000000000 Z
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -92,8 +92,8 @@ files:
92
92
  - bin/console
93
93
  - bin/setup
94
94
  - graphql-1.7.gemfile
95
- - graphql-1.8.gemfile
96
95
  - graphql-guard.gemspec
96
+ - graphql-latest.gemfile
97
97
  - lib/graphql/guard.rb
98
98
  - lib/graphql/guard/testing.rb
99
99
  - lib/graphql/guard/version.rb