search_object_graphql 1.0.1 → 1.0.2
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/CHANGELOG.md +4 -0
- data/README.md +14 -0
- data/example/app/graphql/types/base_argument.rb +11 -0
- data/example/app/graphql/types/base_field.rb +7 -0
- data/example/app/graphql/types/base_object.rb +1 -0
- data/lib/search_object/plugin/graphql/version.rb +1 -1
- data/lib/search_object/plugin/graphql.rb +4 -1
- data/spec/search_object/plugin/graphql_spec.rb +42 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f509887b8c20f3fde861d5dc9cb0588a5d69c167a42d7348f3839ef34ed007b
|
4
|
+
data.tar.gz: '08124c03eb5127693e68fd3c191aceab436eab0463bfe82151d82207acb13ef4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76bdb08d7b81f1ca59787ae1895fb3bef3befa60c6086204b63fdc01441f0e819e293f14aa8abcac611f6ed9455b3fc556672cb2f980c21b1a699c124297514
|
7
|
+
data.tar.gz: 3dd7bdfea7fec0148d3d39db9eab1c340f1b05779b6137f71468e2fdb1ee9cb90a98339dc400f984a9f548f4ec7e3527a5d1e8cb71396e22bded52544a07047b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -116,6 +116,20 @@ class PostResolver < GraphQL::Schema::Resolver
|
|
116
116
|
end
|
117
117
|
```
|
118
118
|
|
119
|
+
### Additional Argument Options
|
120
|
+
|
121
|
+
Sometimes you need to pass additional options to the graphql argument method.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
class PostResolver < GraphQL::Schema::Resolver
|
125
|
+
include SearchObject.module(:graphql)
|
126
|
+
|
127
|
+
scope { Post.all }
|
128
|
+
|
129
|
+
option(:published, type: types.Boolean, argument_options: { pundit_role: :read }) { |scope, value| value ? scope.published : scope.unpublished }
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
119
133
|
### Accessing Parent Object
|
120
134
|
|
121
135
|
Sometimes you want to scope posts based on parent object, it is accessible as `object` property:
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Types
|
4
|
+
class BaseArgument < GraphQL::Schema::Argument
|
5
|
+
def initialize(*args, permission: true, **kwargs, &block)
|
6
|
+
super(*args, **kwargs, &block)
|
7
|
+
|
8
|
+
raise GraphQL::ExecutionError, 'No permission' unless permission
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -30,7 +30,10 @@ module SearchObject
|
|
30
30
|
def option(name, options = {}, &block)
|
31
31
|
type = options.fetch(:type) { raise MissingTypeDefinitionError, name }
|
32
32
|
|
33
|
-
argument_options =
|
33
|
+
argument_options = options[:argument_options] || {}
|
34
|
+
|
35
|
+
argument_options[:required] = options[:required] || false
|
36
|
+
|
34
37
|
argument_options[:camelize] = options[:camelize] if options.include?(:camelize)
|
35
38
|
argument_options[:default_value] = options[:default] if options.include?(:default)
|
36
39
|
argument_options[:description] = options[:description] if options.include?(:description)
|
@@ -17,7 +17,20 @@ end
|
|
17
17
|
|
18
18
|
describe SearchObject::Plugin::Graphql do
|
19
19
|
def define_schema(&block)
|
20
|
+
argument_type = Class.new(GraphQL::Schema::Argument) do
|
21
|
+
def initialize(*args, permission: true, **kwargs, &block)
|
22
|
+
super(*args, **kwargs, &block)
|
23
|
+
|
24
|
+
raise 'No permission' unless permission
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
field_type = Class.new(GraphQL::Schema::Field) do
|
29
|
+
argument_class argument_type
|
30
|
+
end
|
31
|
+
|
20
32
|
query_type = Class.new(GraphQL::Schema::Object) do
|
33
|
+
field_class field_type
|
21
34
|
graphql_name 'Query'
|
22
35
|
|
23
36
|
instance_eval(&block)
|
@@ -31,7 +44,16 @@ describe SearchObject::Plugin::Graphql do
|
|
31
44
|
end
|
32
45
|
|
33
46
|
def define_search_class(&block)
|
47
|
+
argument_type = Class.new(GraphQL::Schema::Argument) do
|
48
|
+
def initialize(*args, permission: true, **kwargs, &block)
|
49
|
+
super(*args, **kwargs, &block)
|
50
|
+
|
51
|
+
raise 'No permission' unless permission
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
34
55
|
Class.new(GraphQL::Schema::Resolver) do
|
56
|
+
argument_class argument_type
|
35
57
|
include SearchObject.module(:graphql)
|
36
58
|
|
37
59
|
scope { [] }
|
@@ -265,6 +287,26 @@ describe SearchObject::Plugin::Graphql do
|
|
265
287
|
expect(result['errors'][0]['message']).to eq("Field 'posts' is missing required arguments: id")
|
266
288
|
end
|
267
289
|
|
290
|
+
it 'accepts "argument_options"' do
|
291
|
+
argument_options = {
|
292
|
+
permission: true
|
293
|
+
}
|
294
|
+
schema = define_search_class_and_return_schema do
|
295
|
+
option(:id, type: types.String, argument_options: argument_options) do |_scope, value|
|
296
|
+
[Post.new(value)]
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
result = schema.execute '{ posts(id: "2") { id } }'
|
301
|
+
|
302
|
+
expect(result).to eq(
|
303
|
+
'data' => {
|
304
|
+
'posts' => [Post.new('2').to_json]
|
305
|
+
}
|
306
|
+
)
|
307
|
+
|
308
|
+
end
|
309
|
+
|
268
310
|
it 'accepts description' do
|
269
311
|
schema = define_search_class_and_return_schema do
|
270
312
|
type PostType, null: true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_object_graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radoslav Stankov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -140,7 +140,9 @@ files:
|
|
140
140
|
- example/app/graphql/resolvers/post_search.rb
|
141
141
|
- example/app/graphql/schema.rb
|
142
142
|
- example/app/graphql/types/.keep
|
143
|
+
- example/app/graphql/types/base_argument.rb
|
143
144
|
- example/app/graphql/types/base_enum.rb
|
145
|
+
- example/app/graphql/types/base_field.rb
|
144
146
|
- example/app/graphql/types/base_input_object.rb
|
145
147
|
- example/app/graphql/types/base_interface.rb
|
146
148
|
- example/app/graphql/types/base_object.rb
|
@@ -190,7 +192,7 @@ homepage: https://github.com/RStankov/SearchObjectGraphQL
|
|
190
192
|
licenses:
|
191
193
|
- MIT
|
192
194
|
metadata: {}
|
193
|
-
post_install_message:
|
195
|
+
post_install_message:
|
194
196
|
rdoc_options: []
|
195
197
|
require_paths:
|
196
198
|
- lib
|
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
208
|
version: '0'
|
207
209
|
requirements: []
|
208
210
|
rubygems_version: 3.0.3
|
209
|
-
signing_key:
|
211
|
+
signing_key:
|
210
212
|
specification_version: 4
|
211
213
|
summary: Maps search objects to GraphQL resolvers
|
212
214
|
test_files:
|