graphql_rails 0.5.0 → 0.5.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: f314505789425775da7e899dd4d30bbc6558da828af5b3f617a84d42eb8f4933
4
- data.tar.gz: 9afab45a8f249aadf6540715514d2f7e21a713290fa7f753fc1933bc574cb18a
3
+ metadata.gz: f63b8e5d3c98d472ff1ec382261d772e83d70d7d8af6df29da806b72f8563858
4
+ data.tar.gz: d075ad40f236b39d0f57e7a47469c6de5a7a3b5ebba5ab62fff30981b7e536ce
5
5
  SHA512:
6
- metadata.gz: 0c5709a879b830f8beeccfd391ec0f4f7de83cc3af0d4a37880f3051ab00d2d06fc88794087c5b0f8a18331c5d059caca389894cdc36c722e11d4393546fb289
7
- data.tar.gz: 9df5208778bfbe2a47c8e652ec2b5442747e51a5e5c4a315fbada63c92248d96d37a85d4598ec8210b5c2e8cc34e8df2f7731faf988ceefb6c91c499da38a68b
6
+ metadata.gz: 5edf95451b857f27d304701402e8a18c771150385cf1fbc7a72db0d446ee7848c4de6ff0c85466fc6129e9adde4e14057c9b11b244cc388d2f6ee692547511e2
7
+ data.tar.gz: dfd50167b6c86ee5f371e0183eac93bb8b32d6a3572c85b2cdc1b218c3ca026afc501a44d4534728b45dd0594c4fb9ad451d8d240e1ad9a8fbf12246b2200091
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ## [Unreleased]
2
2
 
3
- * Your contribution here.
3
+ * Fixed controller action hooks context [@povilasjurcys](https://github.com/povilasjurcys).
4
+ * Added options for controller actions [@vastas1996](https://github.com/vastas1996).
4
5
 
5
6
  ## 0.5.0 (2019-04-03)
6
7
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_rails (0.5.0)
4
+ graphql_rails (0.5.1)
5
5
  activesupport (>= 4)
6
6
  graphql (~> 1)
7
7
 
@@ -31,7 +31,7 @@ GEM
31
31
  concurrent-ruby (1.1.5)
32
32
  diff-lcs (1.3)
33
33
  docile (1.3.1)
34
- graphql (1.9.3)
34
+ graphql (1.9.4)
35
35
  i18n (1.6.0)
36
36
  concurrent-ruby (~> 1.0)
37
37
  jaro_winkler (1.5.2)
@@ -107,4 +107,4 @@ DEPENDENCIES
107
107
  simplecov
108
108
 
109
109
  BUNDLED WITH
110
- 1.16.2
110
+ 1.16.4
@@ -138,6 +138,21 @@ class UsersController < GraphqlRails::Controller
138
138
  end
139
139
  ```
140
140
 
141
+ ### *options*
142
+
143
+ You can customize your queries using `options` method. So far we've added `input_format` and allowed value is `:original` which specifies to keep the field name format.
144
+ `options` method can be used like so:
145
+
146
+ ```ruby
147
+ class UsersController < GraphqlRails::Controller
148
+ action(:create).options(input_format: :original).permit(:full_name)
149
+
150
+ def create
151
+ User.create(params)
152
+ end
153
+ end
154
+ ```
155
+
141
156
  ## *before_action*
142
157
 
143
158
  You can add `before_action` to run some filters before calling your controller action. Here is an example:
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['po.jurcys@gmail.com']
11
11
 
12
12
  spec.summary = %q{GraphQL server and client for rails}
13
- spec.homepage = 'https://github.com/povilasjurcys/graphql_rails'
13
+ spec.homepage = 'https://github.com/samesystem/graphql_rails'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -39,6 +39,10 @@ module GraphqlRails
39
39
 
40
40
  protected
41
41
 
42
+ def options
43
+ {}
44
+ end
45
+
42
46
  def nullable_type
43
47
  type = type_parser.graphql_type
44
48
  type.non_null? ? type.of_type : type
@@ -51,7 +55,7 @@ module GraphqlRails
51
55
  end
52
56
 
53
57
  def attribute_name_parser
54
- @attribute_name_parser ||= AttributeNameParser.new(initial_name)
58
+ @attribute_name_parser ||= AttributeNameParser.new(initial_name, options: options)
55
59
  end
56
60
  end
57
61
  end
@@ -7,23 +7,20 @@ module GraphqlRails
7
7
  class AttributeNameParser
8
8
  attr_reader :name
9
9
 
10
- def initialize(original_name)
10
+ def initialize(original_name, options: {})
11
11
  name = original_name.to_s
12
12
  @required = !name['!'].nil?
13
13
  @name = name.tr('!', '')
14
+ @options = options
14
15
  end
15
16
 
16
17
  def field_name
17
- @field_name ||= begin
18
- field =
19
- if name.end_with?('?')
20
- "is_#{name.remove(/\?\Z/)}"
21
- else
22
- name
23
- end
24
-
25
- field.camelize(:lower)
26
- end
18
+ @field_name ||= \
19
+ if original_format?
20
+ preprocesed_name
21
+ else
22
+ preprocesed_name.camelize(:lower)
23
+ end
27
24
  end
28
25
 
29
26
  def graphql_type
@@ -41,6 +38,22 @@ module GraphqlRails
41
38
  def required?
42
39
  @required
43
40
  end
41
+
42
+ private
43
+
44
+ attr_reader :options
45
+
46
+ def original_format?
47
+ options[:input_format] == :original
48
+ end
49
+
50
+ def preprocesed_name
51
+ if name.end_with?('?')
52
+ "is_#{name.remove(/\?\Z/)}"
53
+ else
54
+ name
55
+ end
56
+ end
44
57
  end
45
58
  end
46
59
  end
@@ -18,9 +18,15 @@ module GraphqlRails
18
18
 
19
19
  def initialize
20
20
  @attributes = {}
21
+ @action_options = {}
21
22
  @can_return_nil = false
22
23
  end
23
24
 
25
+ def options(input_format:)
26
+ @action_options[:input_format] = input_format
27
+ self
28
+ end
29
+
24
30
  def permit(*no_type_attributes, **typed_attributes)
25
31
  no_type_attributes.each { |attribute| permit_attribute(attribute) }
26
32
  typed_attributes.each { |attribute, type| permit_attribute(attribute, type) }
@@ -67,7 +73,7 @@ module GraphqlRails
67
73
 
68
74
  private
69
75
 
70
- attr_reader :custom_return_type
76
+ attr_reader :custom_return_type, :action_options
71
77
 
72
78
  def build_return_type
73
79
  return nil if custom_return_type.nil?
@@ -85,7 +91,7 @@ module GraphqlRails
85
91
 
86
92
  def permit_attribute(name, type = nil)
87
93
  field_name = name.to_s.remove(/!\Z/)
88
- attributes[field_name] = Model::InputAttribute.new(name.to_s, type)
94
+ attributes[field_name] = Model::InputAttribute.new(name.to_s, type, options: action_options)
89
95
  end
90
96
  end
91
97
  end
@@ -9,10 +9,10 @@ module GraphqlRails
9
9
  @controller = controller
10
10
  end
11
11
 
12
- def call
12
+ def call(&block)
13
13
  result = nil
14
14
  run_action_hooks(:before)
15
- run_around_action_hooks { result = yield }
15
+ run_around_action_hooks { result = controller.instance_exec(&block) }
16
16
  run_action_hooks(:after)
17
17
  result
18
18
  end
@@ -42,7 +42,7 @@ module GraphqlRails
42
42
 
43
43
  def execute_hook(action_hook, &block)
44
44
  if action_hook.anonymous?
45
- action_hook.action_proc.call(controller, *block)
45
+ controller.instance_exec(controller, *block, &action_hook.action_proc)
46
46
  else
47
47
  controller.send(action_hook.name, &block)
48
48
  end
@@ -8,10 +8,11 @@ module GraphqlRails
8
8
 
9
9
  attr_reader :description
10
10
 
11
- def initialize(name, type = nil, description: nil)
11
+ def initialize(name, type = nil, description: nil, options: {})
12
12
  @initial_name = name
13
13
  @initial_type = type
14
14
  @description = description
15
+ @options = options
15
16
  end
16
17
 
17
18
  def function_argument_args
@@ -29,7 +30,7 @@ module GraphqlRails
29
30
 
30
31
  private
31
32
 
32
- attr_reader :initial_name, :initial_type
33
+ attr_reader :initial_name, :initial_type, :options
33
34
 
34
35
  def raw_input_type
35
36
  return initial_type if initial_type.is_a?(GraphQL::InputObjectType)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlRails
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Povilas Jurčys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -159,7 +159,7 @@ files:
159
159
  - lib/graphql_rails/router/schema_builder.rb
160
160
  - lib/graphql_rails/rspec_controller_helpers.rb
161
161
  - lib/graphql_rails/version.rb
162
- homepage: https://github.com/povilasjurcys/graphql_rails
162
+ homepage: https://github.com/samesystem/graphql_rails
163
163
  licenses:
164
164
  - MIT
165
165
  metadata: {}
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  requirements: []
181
181
  rubyforge_project:
182
- rubygems_version: 2.7.7
182
+ rubygems_version: 2.7.6
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: GraphQL server and client for rails