search_object_graphql 0.3.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/.rubocop.yml +6 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.md +19 -0
- data/README.md +19 -21
- data/example/app/graphql/resolvers/base_resolver.rb +6 -0
- data/example/app/graphql/resolvers/base_search_resolver.rb +1 -1
- data/example/app/graphql/resolvers/category_search.rb +1 -1
- data/example/app/graphql/resolvers/post_search.rb +1 -1
- 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/example/app/graphql/types/category_type.rb +1 -1
- data/example/app/graphql/types/query_type.rb +1 -1
- data/lib/search_object/plugin/graphql/version.rb +1 -1
- data/lib/search_object/plugin/graphql.rb +14 -92
- data/spec/search_object/plugin/graphql_spec.rb +157 -108
- metadata +8 -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/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 1.0.1
|
4
|
+
|
5
|
+
* __[feature]__ Added `argument_options` to `options` (@wuz)
|
6
|
+
|
7
|
+
## Version 1.0.1
|
8
|
+
|
9
|
+
* __[fix]__ `camelize` defaults to false when not specified (@haines)
|
10
|
+
|
11
|
+
## Version 1.0.0
|
12
|
+
|
13
|
+
* __[break]__ Removed support for defining types via `type` method (@rstankov)
|
14
|
+
* __[break]__ Require `GraphQL::Schema::Resolver` inheritance (@rstankov)
|
15
|
+
* __[break]__ Removed support for legacy `GraphQL::Function` (@rstankov)
|
16
|
+
* __[break]__ `type` creates type based on `GraphQL::Schema::Object`, not the deprecated `GraphQL::ObjectType.define` (@rstankov)
|
17
|
+
|
18
|
+
## Version 0.3.2
|
19
|
+
|
20
|
+
* __[feature]__ Added `camelize` argument to `option`, *`true` by default* (@glenbray)
|
21
|
+
|
3
22
|
## Version 0.3.1
|
4
23
|
|
5
24
|
* __[fix]__ Support for GraphQL gem version v1.9.16 (@ardinusawan)
|
data/README.md
CHANGED
@@ -57,7 +57,7 @@ require 'search_object/plugin/graphql'
|
|
57
57
|
Just include the ```SearchObject.module``` and define your search options and their types:
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
class PostResolver
|
60
|
+
class PostResolver < GraphQL::Schema::Resolver
|
61
61
|
include SearchObject.module(:graphql)
|
62
62
|
|
63
63
|
type [PostType], null: false
|
@@ -94,7 +94,7 @@ You can find example of most important features and plugins - [here](https://git
|
|
94
94
|
Search object itself can be documented, as well as its options:
|
95
95
|
|
96
96
|
```ruby
|
97
|
-
class PostResolver
|
97
|
+
class PostResolver < GraphQL::Schema::Resolver
|
98
98
|
include SearchObject.module(:graphql)
|
99
99
|
|
100
100
|
description 'Lists all posts'
|
@@ -107,7 +107,7 @@ end
|
|
107
107
|
### Default Values
|
108
108
|
|
109
109
|
```ruby
|
110
|
-
class PostResolver
|
110
|
+
class PostResolver < GraphQL::Schema::Resolver
|
111
111
|
include SearchObject.module(:graphql)
|
112
112
|
|
113
113
|
scope { Post.all }
|
@@ -116,12 +116,26 @@ class PostResolver
|
|
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:
|
122
136
|
|
123
137
|
```ruby
|
124
|
-
class PostResolver
|
138
|
+
class PostResolver < GraphQL::Schema::Resolver
|
125
139
|
include SearchObject.module(:graphql)
|
126
140
|
|
127
141
|
# lists only posts from certain category
|
@@ -168,7 +182,7 @@ end
|
|
168
182
|
Search objects can be used as [Relay Connections](https://graphql-ruby.org/relay/connections.html):
|
169
183
|
|
170
184
|
```ruby
|
171
|
-
class PostResolver
|
185
|
+
class PostResolver < GraphQL::Schema::Resolver
|
172
186
|
include SearchObject.module(:graphql)
|
173
187
|
|
174
188
|
type PostType.connection_type, null: false
|
@@ -181,22 +195,6 @@ end
|
|
181
195
|
field :posts, resolver: PostResolver
|
182
196
|
```
|
183
197
|
|
184
|
-
### Legacy Function Support
|
185
|
-
|
186
|
-
```ruby
|
187
|
-
class PostResolver
|
188
|
-
include SearchObject.module(:graphql)
|
189
|
-
|
190
|
-
type [PostType], null: false
|
191
|
-
|
192
|
-
# ...
|
193
|
-
end
|
194
|
-
```
|
195
|
-
|
196
|
-
```ruby
|
197
|
-
field :posts, function: PostResolver
|
198
|
-
```
|
199
|
-
|
200
198
|
## Contributing
|
201
199
|
|
202
200
|
1. Fork it
|
@@ -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
|
@@ -4,8 +4,9 @@ module SearchObject
|
|
4
4
|
module Plugin
|
5
5
|
module Graphql
|
6
6
|
def self.included(base)
|
7
|
+
raise NotIncludedInResolverError, base unless base.ancestors.include? GraphQL::Schema::Resolver
|
8
|
+
|
7
9
|
base.include SearchObject::Plugin::Enum
|
8
|
-
base.include ::GraphQL::Schema::Member::GraphQLTypeNames
|
9
10
|
base.extend ClassMethods
|
10
11
|
end
|
11
12
|
|
@@ -26,111 +27,32 @@ module SearchObject
|
|
26
27
|
end
|
27
28
|
|
28
29
|
module ClassMethods
|
29
|
-
KEYS = %i[type default description required].freeze
|
30
30
|
def option(name, options = {}, &block)
|
31
|
-
config[:arguments] ||= {}
|
32
|
-
config[:arguments][name.to_s] = KEYS.inject({}) do |acc, key|
|
33
|
-
acc[key] = options[key] if options.key?(key)
|
34
|
-
acc
|
35
|
-
end
|
36
|
-
|
37
31
|
type = options.fetch(:type) { raise MissingTypeDefinitionError, name }
|
38
|
-
options[:enum] = type.values.map { |value, enum_value| enum_value.value || value } if type.respond_to?(:values)
|
39
|
-
|
40
|
-
super(name, options, &block)
|
41
|
-
end
|
42
32
|
|
43
|
-
|
44
|
-
return config[:type] if value == :default && !block_given?
|
33
|
+
argument_options = options[:argument_options] || {}
|
45
34
|
|
46
|
-
|
47
|
-
config[:null] = null
|
48
|
-
end
|
49
|
-
|
50
|
-
def complexity(value = :default)
|
51
|
-
return config[:complexity] || 1 if value == :default
|
52
|
-
|
53
|
-
config[:complexity] = value
|
54
|
-
end
|
55
|
-
|
56
|
-
def description(value = :default)
|
57
|
-
return config[:description] if value == :default
|
35
|
+
argument_options[:required] = options[:required] || false
|
58
36
|
|
59
|
-
|
60
|
-
|
37
|
+
argument_options[:camelize] = options[:camelize] if options.include?(:camelize)
|
38
|
+
argument_options[:default_value] = options[:default] if options.include?(:default)
|
39
|
+
argument_options[:description] = options[:description] if options.include?(:description)
|
61
40
|
|
62
|
-
|
63
|
-
return config[:deprecation_reason] if value == :default
|
41
|
+
argument(name.to_s, type, **argument_options)
|
64
42
|
|
65
|
-
|
66
|
-
end
|
43
|
+
options[:enum] = type.values.map { |value, enum_value| enum_value.value || value } if type.respond_to?(:values)
|
67
44
|
|
68
|
-
|
69
|
-
# Documentation - http://graphql-ruby.org/guides
|
70
|
-
def call(object, args, context)
|
71
|
-
new(filters: args.to_h, object: object, context: context).results
|
45
|
+
super(name, options, &block)
|
72
46
|
end
|
73
47
|
|
74
|
-
# NOTE(rstankov): Used for GraphQL::Function
|
75
48
|
def types
|
76
49
|
GraphQL::Define::TypeDefiner.instance
|
77
50
|
end
|
51
|
+
end
|
78
52
|
|
79
|
-
|
80
|
-
def
|
81
|
-
|
82
|
-
argument = GraphQL::Argument.new
|
83
|
-
argument.name = name.to_s
|
84
|
-
argument.type = options.fetch(:type) { raise MissingTypeDefinitionError, name }
|
85
|
-
argument.default_value = options[:default] if options.key? :default
|
86
|
-
argument.description = options[:description] if options.key? :description
|
87
|
-
|
88
|
-
acc[name] = argument
|
89
|
-
acc
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# NOTE(rstankov): Used for GraphQL::Schema::Resolver
|
94
|
-
def field_options
|
95
|
-
{
|
96
|
-
type: type,
|
97
|
-
description: description,
|
98
|
-
extras: [],
|
99
|
-
resolver_method: :resolve_with_support,
|
100
|
-
resolver_class: self,
|
101
|
-
deprecation_reason: deprecation_reason,
|
102
|
-
arguments: (config[:arguments] || {}).inject({}) do |acc, (name, options)|
|
103
|
-
name = name.to_s.split('_').map(&:capitalize).join
|
104
|
-
name[0] = name[0].downcase
|
105
|
-
|
106
|
-
acc[name] = ::GraphQL::Schema::Argument.new(
|
107
|
-
name: name.to_s,
|
108
|
-
type: options.fetch(:type) { raise MissingTypeDefinitionError, name },
|
109
|
-
description: options[:description],
|
110
|
-
required: !!options[:required],
|
111
|
-
default_value: options.fetch(:default) { ::GraphQL::Schema::Argument::NO_DEFAULT },
|
112
|
-
owner: self
|
113
|
-
)
|
114
|
-
acc
|
115
|
-
end,
|
116
|
-
null: !!config[:null],
|
117
|
-
complexity: complexity
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
# NOTE(rstankov): Used for GraphQL::Schema::Resolver
|
122
|
-
def visible?(_context)
|
123
|
-
true
|
124
|
-
end
|
125
|
-
|
126
|
-
# NOTE(rstankov): Used for GraphQL::Schema::Resolver
|
127
|
-
def accessible?(_context)
|
128
|
-
true
|
129
|
-
end
|
130
|
-
|
131
|
-
# NOTE(rstankov): Used for GraphQL::Schema::Resolver
|
132
|
-
def authorized?(_object, _context)
|
133
|
-
true
|
53
|
+
class NotIncludedInResolverError < ArgumentError
|
54
|
+
def initialize(base)
|
55
|
+
super "#{base.name} should inherit from GraphQL::Schema::Resolver. Current ancestors #{base.ancestors}"
|
134
56
|
end
|
135
57
|
end
|
136
58
|
|
@@ -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)
|
34
|
-
Class.new do
|
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
|
+
|
55
|
+
Class.new(GraphQL::Schema::Resolver) do
|
56
|
+
argument_class argument_type
|
35
57
|
include SearchObject.module(:graphql)
|
36
58
|
|
37
59
|
scope { [] }
|
@@ -52,6 +74,12 @@ describe SearchObject::Plugin::Graphql do
|
|
52
74
|
end
|
53
75
|
end
|
54
76
|
|
77
|
+
it 'requires class to inherit from GraphQL::Schema::Resolver' do
|
78
|
+
expect do
|
79
|
+
Class.new { include SearchObject.module(:graphql) }
|
80
|
+
end.to raise_error SearchObject::Plugin::Graphql::NotIncludedInResolverError
|
81
|
+
end
|
82
|
+
|
55
83
|
it 'can be used as GraphQL::Schema::Resolver' do
|
56
84
|
post_type = Class.new(GraphQL::Schema::Object) do
|
57
85
|
graphql_name 'Post'
|
@@ -62,7 +90,7 @@ describe SearchObject::Plugin::Graphql do
|
|
62
90
|
search_object = define_search_class do
|
63
91
|
scope { [Post.new('1'), Post.new('2'), Post.new('3')] }
|
64
92
|
|
65
|
-
type [post_type]
|
93
|
+
type [post_type], null: 1
|
66
94
|
|
67
95
|
option(:id, type: !types.ID) { |scope, value| scope.select { |p| p.id == value } }
|
68
96
|
end
|
@@ -80,34 +108,6 @@ describe SearchObject::Plugin::Graphql do
|
|
80
108
|
)
|
81
109
|
end
|
82
110
|
|
83
|
-
it 'can be used as GraphQL::Function' do
|
84
|
-
post_type = GraphQL::ObjectType.define do
|
85
|
-
name 'Post'
|
86
|
-
|
87
|
-
field :id, !types.ID
|
88
|
-
end
|
89
|
-
|
90
|
-
search_object = define_search_class do
|
91
|
-
scope { [Post.new('1'), Post.new('2'), Post.new('3')] }
|
92
|
-
|
93
|
-
type types[post_type]
|
94
|
-
|
95
|
-
option(:id, type: !types.ID) { |scope, value| scope.select { |p| p.id == value } }
|
96
|
-
end
|
97
|
-
|
98
|
-
schema = define_schema do
|
99
|
-
field :posts, function: search_object
|
100
|
-
end
|
101
|
-
|
102
|
-
result = schema.execute '{ posts(id: "2") { id } }'
|
103
|
-
|
104
|
-
expect(result).to eq(
|
105
|
-
'data' => {
|
106
|
-
'posts' => [Post.new('2').to_json]
|
107
|
-
}
|
108
|
-
)
|
109
|
-
end
|
110
|
-
|
111
111
|
it 'can access to parent object' do
|
112
112
|
search_object = define_search_class do
|
113
113
|
scope { object.posts }
|
@@ -164,81 +164,6 @@ describe SearchObject::Plugin::Graphql do
|
|
164
164
|
)
|
165
165
|
end
|
166
166
|
|
167
|
-
it 'can define a custom type' do
|
168
|
-
schema = define_search_class_and_return_schema do
|
169
|
-
type do
|
170
|
-
name 'Test'
|
171
|
-
|
172
|
-
field :title, types.String
|
173
|
-
end
|
174
|
-
|
175
|
-
description 'Test description'
|
176
|
-
end
|
177
|
-
|
178
|
-
result = schema.execute <<-SQL
|
179
|
-
{
|
180
|
-
__type(name: "Query") {
|
181
|
-
name
|
182
|
-
fields {
|
183
|
-
name
|
184
|
-
deprecationReason
|
185
|
-
type {
|
186
|
-
name
|
187
|
-
fields {
|
188
|
-
name
|
189
|
-
}
|
190
|
-
}
|
191
|
-
}
|
192
|
-
}
|
193
|
-
}
|
194
|
-
SQL
|
195
|
-
|
196
|
-
expect(result).to eq(
|
197
|
-
'data' => {
|
198
|
-
'__type' => {
|
199
|
-
'name' => 'Query',
|
200
|
-
'fields' => [{
|
201
|
-
'name' => 'posts',
|
202
|
-
'deprecationReason' => nil,
|
203
|
-
'type' => {
|
204
|
-
'name' => 'Test',
|
205
|
-
'fields' => [{
|
206
|
-
'name' => 'title'
|
207
|
-
}]
|
208
|
-
}
|
209
|
-
}]
|
210
|
-
}
|
211
|
-
}
|
212
|
-
)
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'can be marked as deprecated' do
|
216
|
-
schema = define_search_class_and_return_schema do
|
217
|
-
type [PostType]
|
218
|
-
deprecation_reason 'Not needed any more'
|
219
|
-
end
|
220
|
-
|
221
|
-
result = schema.execute <<-QUERY
|
222
|
-
{
|
223
|
-
__type(name: "Query") {
|
224
|
-
name
|
225
|
-
fields {
|
226
|
-
name
|
227
|
-
}
|
228
|
-
}
|
229
|
-
}
|
230
|
-
QUERY
|
231
|
-
|
232
|
-
expect(result.to_h).to eq(
|
233
|
-
'data' => {
|
234
|
-
'__type' => {
|
235
|
-
'name' => 'Query',
|
236
|
-
'fields' => []
|
237
|
-
}
|
238
|
-
}
|
239
|
-
)
|
240
|
-
end
|
241
|
-
|
242
167
|
describe 'option' do
|
243
168
|
it 'converts GraphQL::Schema::Enum to SearchObject enum' do
|
244
169
|
schema = define_search_class_and_return_schema do
|
@@ -271,8 +196,8 @@ describe SearchObject::Plugin::Graphql do
|
|
271
196
|
|
272
197
|
it 'converts GraphQL::EnumType to SearchObject enum' do
|
273
198
|
schema = define_search_class_and_return_schema do
|
274
|
-
enum_type = GraphQL::
|
275
|
-
|
199
|
+
enum_type = Class.new(GraphQL::Schema::Enum) do
|
200
|
+
graphql_name 'TestEnum'
|
276
201
|
|
277
202
|
value 'PRICE'
|
278
203
|
value 'DATE'
|
@@ -314,6 +239,42 @@ describe SearchObject::Plugin::Graphql do
|
|
314
239
|
)
|
315
240
|
end
|
316
241
|
|
242
|
+
it 'sets default_value on the argument' do
|
243
|
+
schema = define_search_class_and_return_schema do
|
244
|
+
type PostType, null: true
|
245
|
+
|
246
|
+
option('option', type: types.String, default: 'default') { [] }
|
247
|
+
end
|
248
|
+
|
249
|
+
result = schema.execute <<~GRAPHQL
|
250
|
+
{
|
251
|
+
__type(name: "Query") {
|
252
|
+
name
|
253
|
+
fields {
|
254
|
+
args {
|
255
|
+
name
|
256
|
+
defaultValue
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}
|
261
|
+
GRAPHQL
|
262
|
+
|
263
|
+
expect(result).to eq(
|
264
|
+
'data' => {
|
265
|
+
'__type' => {
|
266
|
+
'name' => 'Query',
|
267
|
+
'fields' => [{
|
268
|
+
'args' => [{
|
269
|
+
'name' => 'option',
|
270
|
+
'defaultValue' => '"default"'
|
271
|
+
}]
|
272
|
+
}]
|
273
|
+
}
|
274
|
+
}
|
275
|
+
)
|
276
|
+
end
|
277
|
+
|
317
278
|
it 'accepts "required"' do
|
318
279
|
schema = define_search_class_and_return_schema do
|
319
280
|
option(:id, type: types.String, required: true) do |_scope, value|
|
@@ -326,9 +287,29 @@ describe SearchObject::Plugin::Graphql do
|
|
326
287
|
expect(result['errors'][0]['message']).to eq("Field 'posts' is missing required arguments: id")
|
327
288
|
end
|
328
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
|
+
|
329
310
|
it 'accepts description' do
|
330
311
|
schema = define_search_class_and_return_schema do
|
331
|
-
type PostType
|
312
|
+
type PostType, null: true
|
332
313
|
|
333
314
|
option('option', type: types.String, description: 'what this argument does') { [] }
|
334
315
|
end
|
@@ -362,6 +343,74 @@ describe SearchObject::Plugin::Graphql do
|
|
362
343
|
)
|
363
344
|
end
|
364
345
|
|
346
|
+
it 'accepts camelize' do
|
347
|
+
schema = define_search_class_and_return_schema do
|
348
|
+
type PostType, null: true
|
349
|
+
|
350
|
+
option('option_field', type: types.String, camelize: false)
|
351
|
+
end
|
352
|
+
|
353
|
+
result = schema.execute <<-SQL
|
354
|
+
{
|
355
|
+
__type(name: "Query") {
|
356
|
+
name
|
357
|
+
fields {
|
358
|
+
args {
|
359
|
+
name
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
}
|
364
|
+
SQL
|
365
|
+
|
366
|
+
expect(result.to_h).to eq(
|
367
|
+
'data' => {
|
368
|
+
'__type' => {
|
369
|
+
'name' => 'Query',
|
370
|
+
'fields' => [{
|
371
|
+
'args' => [{
|
372
|
+
'name' => 'option_field'
|
373
|
+
}]
|
374
|
+
}]
|
375
|
+
}
|
376
|
+
}
|
377
|
+
)
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'does not override the default camelize option' do
|
381
|
+
schema = define_search_class_and_return_schema do
|
382
|
+
type PostType, null: true
|
383
|
+
|
384
|
+
option('option_field', type: types.String)
|
385
|
+
end
|
386
|
+
|
387
|
+
result = schema.execute <<~GRAPHQL
|
388
|
+
{
|
389
|
+
__type(name: "Query") {
|
390
|
+
name
|
391
|
+
fields {
|
392
|
+
args {
|
393
|
+
name
|
394
|
+
}
|
395
|
+
}
|
396
|
+
}
|
397
|
+
}
|
398
|
+
GRAPHQL
|
399
|
+
|
400
|
+
expect(result.to_h).to eq(
|
401
|
+
'data' => {
|
402
|
+
'__type' => {
|
403
|
+
'name' => 'Query',
|
404
|
+
'fields' => [{
|
405
|
+
'args' => [{
|
406
|
+
'name' => 'optionField'
|
407
|
+
}]
|
408
|
+
}]
|
409
|
+
}
|
410
|
+
}
|
411
|
+
)
|
412
|
+
end
|
413
|
+
|
365
414
|
it 'raises error when no type is given' do
|
366
415
|
expect { define_search_class { option :name } }.to raise_error described_class::MissingTypeDefinitionError
|
367
416
|
end
|
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: 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:
|
11
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -134,12 +134,15 @@ files:
|
|
134
134
|
- example/app/controllers/application_controller.rb
|
135
135
|
- example/app/controllers/graphql_controller.rb
|
136
136
|
- example/app/graphql/mutations/.keep
|
137
|
+
- example/app/graphql/resolvers/base_resolver.rb
|
137
138
|
- example/app/graphql/resolvers/base_search_resolver.rb
|
138
139
|
- example/app/graphql/resolvers/category_search.rb
|
139
140
|
- example/app/graphql/resolvers/post_search.rb
|
140
141
|
- example/app/graphql/schema.rb
|
141
142
|
- example/app/graphql/types/.keep
|
143
|
+
- example/app/graphql/types/base_argument.rb
|
142
144
|
- example/app/graphql/types/base_enum.rb
|
145
|
+
- example/app/graphql/types/base_field.rb
|
143
146
|
- example/app/graphql/types/base_input_object.rb
|
144
147
|
- example/app/graphql/types/base_interface.rb
|
145
148
|
- example/app/graphql/types/base_object.rb
|
@@ -189,7 +192,7 @@ homepage: https://github.com/RStankov/SearchObjectGraphQL
|
|
189
192
|
licenses:
|
190
193
|
- MIT
|
191
194
|
metadata: {}
|
192
|
-
post_install_message:
|
195
|
+
post_install_message:
|
193
196
|
rdoc_options: []
|
194
197
|
require_paths:
|
195
198
|
- lib
|
@@ -205,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
208
|
version: '0'
|
206
209
|
requirements: []
|
207
210
|
rubygems_version: 3.0.3
|
208
|
-
signing_key:
|
211
|
+
signing_key:
|
209
212
|
specification_version: 4
|
210
213
|
summary: Maps search objects to GraphQL resolvers
|
211
214
|
test_files:
|