search_object_graphql 0.2 → 0.3

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: 3f77197a83b86e6ec05a3cb7f0f814bcd8e2d9d5590319b995657eccc64700f3
4
- data.tar.gz: f31f8c4374c23da84bcccc42b6fc8307e08661cab1c67bed324aea90c2780faf
3
+ metadata.gz: 32484e9833398944d93a6063ed233b284dcda248692d2a228bdaebcb1e67dba0
4
+ data.tar.gz: f39b91bef57a39d6c61af8547f9feaf6f12537533343eb92bab31ea049a87c15
5
5
  SHA512:
6
- metadata.gz: 223b83055eaa7e7630694aee66c69abaa01d28a00f091535613b26c7d2f037370f6953ebcaba9d534315fcc381d0aecfbda06b0e0b25b9a0e015b01a233f29c8
7
- data.tar.gz: 24a16c64a585f012bf10a10d0deefe724fec63338b7d901571595ccd92c7f8643373391f63165c2c30bb52d23a7d0e258f936dc7039ff06840140d303f9c5549
6
+ metadata.gz: e0eff7af30a54e609f5175e33c5e5c5477a942629960cbba9e0091662ba76a51e7ab6e4ef4f3ef55f12ce930442126676fbc1efef7659a7a45cf78c08d546912
7
+ data.tar.gz: d7406e278c879b3ddf17ab1b394d6886626ec08a051052cbaab8c2c21f13038c7aeb73ec1d13307a0ad770787c6142684b63fbcf301ce08957875c9abc74eea9
@@ -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"
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.6.2
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.3
4
+
5
+ * __[feature]__ Allow passing `required` key to option definition (@vfonic)
6
+ * __[fix]__ Support for GraphQL gem enums (@Postmodum37)
7
+
3
8
  ## Version 0.2
4
9
 
5
10
  * Added support for GraphQL::Schema::Resolver (@rstankov)
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 => error
11
- raise error unless Rails.env.development?
10
+ rescue StandardError => e
11
+ raise e unless Rails.env.development?
12
12
 
13
- handle_error_in_development error
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.keys if type.respond_to?(: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 },
@@ -3,7 +3,7 @@
3
3
  module SearchObject
4
4
  module Plugin
5
5
  module Graphql
6
- VERSION = '0.2'
6
+ VERSION = '0.3'
7
7
  end
8
8
  end
9
9
  end
@@ -5,17 +5,17 @@ require 'graphql'
5
5
  require 'ostruct'
6
6
  require 'search_object/plugin/graphql'
7
7
 
8
- describe SearchObject::Plugin::Graphql do
9
- Post = Struct.new(:id) do
10
- def to_json
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
- class PostType < GraphQL::Schema::Object
16
- field :id, ID, null: false
17
- end
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.2'
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-06-19 00:00:00.000000000 Z
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
- rubyforge_project:
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