search_object_graphql 0.2 → 0.3
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 +3 -3
- data/.ruby-version +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +8 -0
- data/example/app/controllers/graphql_controller.rb +3 -3
- data/lib/search_object/plugin/graphql.rb +5 -2
- data/lib/search_object/plugin/graphql/version.rb +1 -1
- data/spec/search_object/plugin/graphql_spec.rb +20 -8
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32484e9833398944d93a6063ed233b284dcda248692d2a228bdaebcb1e67dba0
|
4
|
+
data.tar.gz: f39b91bef57a39d6c61af8547f9feaf6f12537533343eb92bab31ea049a87c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0eff7af30a54e609f5175e33c5e5c5477a942629960cbba9e0091662ba76a51e7ab6e4ef4f3ef55f12ce930442126676fbc1efef7659a7a45cf78c08d546912
|
7
|
+
data.tar.gz: d7406e278c879b3ddf17ab1b394d6886626ec08a051052cbaab8c2c21f13038c7aeb73ec1d13307a0ad770787c6142684b63fbcf301ce08957875c9abc74eea9
|
data/.rubocop.yml
CHANGED
@@ -7,15 +7,15 @@ AllCops:
|
|
7
7
|
- search_object.gemspec
|
8
8
|
|
9
9
|
# Disables "Line is too long"
|
10
|
-
LineLength:
|
10
|
+
Metrics/LineLength:
|
11
11
|
Enabled: false
|
12
12
|
|
13
13
|
# Disables Module has too many lines
|
14
|
-
ModuleLength:
|
14
|
+
Metrics/ModuleLength:
|
15
15
|
Enabled: false
|
16
16
|
|
17
17
|
# Disables "Missing top-level class documentation comment"
|
18
|
-
Documentation:
|
18
|
+
Style/Documentation:
|
19
19
|
Enabled: false
|
20
20
|
|
21
21
|
# Disables "Use each_with_object instead of inject"
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,14 @@ Or install it yourself as:
|
|
39
39
|
|
40
40
|
$ gem install search_object_graphql
|
41
41
|
|
42
|
+
|
43
|
+
**Require manually in your project**
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'search_object'
|
47
|
+
require 'search_object/plugin/graphql'
|
48
|
+
```
|
49
|
+
|
42
50
|
## Dependencies
|
43
51
|
|
44
52
|
- `SearchObject` >= 1.2
|
@@ -7,10 +7,10 @@ class GraphqlController < ApplicationController
|
|
7
7
|
context: {},
|
8
8
|
operation_name: params[:operationName])
|
9
9
|
render json: result
|
10
|
-
rescue StandardError =>
|
11
|
-
raise
|
10
|
+
rescue StandardError => e
|
11
|
+
raise e unless Rails.env.development?
|
12
12
|
|
13
|
-
handle_error_in_development
|
13
|
+
handle_error_in_development e
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -26,7 +26,7 @@ module SearchObject
|
|
26
26
|
end
|
27
27
|
|
28
28
|
module ClassMethods
|
29
|
-
KEYS = %i[type default description].freeze
|
29
|
+
KEYS = %i[type default description required].freeze
|
30
30
|
def option(name, options = {}, &block)
|
31
31
|
config[:arguments] ||= {}
|
32
32
|
config[:arguments][name.to_s] = KEYS.inject({}) do |acc, key|
|
@@ -35,7 +35,7 @@ module SearchObject
|
|
35
35
|
end
|
36
36
|
|
37
37
|
type = options.fetch(:type) { raise MissingTypeDefinitionError, name }
|
38
|
-
options[:enum] = type.values.
|
38
|
+
options[:enum] = type.values.map { |value, enum_value| enum_value.value || value } if type.respond_to?(:values)
|
39
39
|
|
40
40
|
super(name, options, &block)
|
41
41
|
end
|
@@ -100,6 +100,9 @@ module SearchObject
|
|
100
100
|
resolver_class: self,
|
101
101
|
deprecation_reason: deprecation_reason,
|
102
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
|
+
|
103
106
|
acc[name] = ::GraphQL::Schema::Argument.new(
|
104
107
|
name: name.to_s,
|
105
108
|
type: options.fetch(:type) { raise MissingTypeDefinitionError, name },
|
@@ -5,17 +5,17 @@ require 'graphql'
|
|
5
5
|
require 'ostruct'
|
6
6
|
require 'search_object/plugin/graphql'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
{ 'id' => id }
|
12
|
-
end
|
8
|
+
Post = Struct.new(:id) do
|
9
|
+
def to_json(_options = {})
|
10
|
+
{ 'id' => id }
|
13
11
|
end
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
class PostType < GraphQL::Schema::Object
|
15
|
+
field :id, ID, null: false
|
16
|
+
end
|
18
17
|
|
18
|
+
describe SearchObject::Plugin::Graphql do
|
19
19
|
def define_schema(&block)
|
20
20
|
query_type = Class.new(GraphQL::Schema::Object) do
|
21
21
|
graphql_name 'Query'
|
@@ -314,6 +314,18 @@ describe SearchObject::Plugin::Graphql do
|
|
314
314
|
)
|
315
315
|
end
|
316
316
|
|
317
|
+
it 'accepts "required"' do
|
318
|
+
schema = define_search_class_and_return_schema do
|
319
|
+
option(:id, type: types.String, required: true) do |_scope, value|
|
320
|
+
[Post.new(value)]
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
result = schema.execute '{ posts { id } }'
|
325
|
+
|
326
|
+
expect(result['errors'][0]['message']).to eq("Field 'posts' is missing required arguments: id")
|
327
|
+
end
|
328
|
+
|
317
329
|
it 'accepts description' do
|
318
330
|
schema = define_search_class_and_return_schema do
|
319
331
|
type PostType
|
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: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radoslav Stankov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -204,8 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
- !ruby/object:Gem::Version
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
|
-
|
208
|
-
rubygems_version: 2.7.6
|
207
|
+
rubygems_version: 3.0.3
|
209
208
|
signing_key:
|
210
209
|
specification_version: 4
|
211
210
|
summary: Maps search objects to GraphQL resolvers
|