graphiform 0.1.1 → 0.1.2

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: 4fc3e0cf5b5240d32be9aeb6d008bd81c56e8b5cee03e1bda37b080ad56fbf1f
4
- data.tar.gz: cfaf0727fedb282ab4ee4bfb58c1fcb0529e0c3c48eb51331c18e76d05651870
3
+ metadata.gz: d348d5da31c862403a9127ada31cbb135e892c21928ca48b8ccfb5eb2d64d047
4
+ data.tar.gz: 73db372bee299b12a56e219218d04c4977436f3457379def8d0dd952a5e97aec
5
5
  SHA512:
6
- metadata.gz: 04b52523d7a06c73d7241259053cb4a6e3c090d70878f4e30b598800cc02492f5eae4e1b70bb7801a29a419a725ce8196b03dbbc015c5fdc748a9ecba18aad22
7
- data.tar.gz: 4c1cf12e92d5cc1c74b235a76baeb3b2be47044dd81c703e59fea199268094b34e98f85bb83d3c8b4e58ae98221bd7449e72e30f5392104e6ac0aaa72c75bccd
6
+ metadata.gz: b22a9b8d9e6b612406ab06a1d8fc86e8ad9e6305a8f1d222d7dc36a08f72cf95d911445ab5e2c1d852714f565b8d8758b6f3c2b3a1ebb1e62199a11f1a4880cb
7
+ data.tar.gz: c5766eb8d166b5311189ede79a26e21b5d55155199f24f995a763c9ddcc6540a5973bf360e1f5edb6ed75959085661f597e81946102a04b9022ad2ada48f5a61
@@ -26,6 +26,11 @@ module Graphiform
26
26
  name,
27
27
  type: nil,
28
28
  required: false,
29
+ write_prepare: nil,
30
+ prepare: nil,
31
+ description: nil,
32
+ default_value: ::GraphQL::Schema::Argument::NO_DEFAULT,
33
+ as: nil,
29
34
  **_options
30
35
  )
31
36
  name = name.to_sym
@@ -34,8 +39,17 @@ module Graphiform
34
39
 
35
40
  return Helpers.logger.warn "Graphiform: Missing `type` for argument #{name}" if argument_type.nil?
36
41
 
42
+ prepare = write_prepare || prepare
43
+
37
44
  graphql_input.class_eval do
38
- argument argument_name, argument_type, required: required
45
+ argument \
46
+ argument_name,
47
+ argument_type,
48
+ required: required,
49
+ prepare: prepare,
50
+ description: description,
51
+ default_value: default_value,
52
+ as: as
39
53
  end
40
54
  end
41
55
 
@@ -79,7 +93,7 @@ module Graphiform
79
93
  end
80
94
 
81
95
  def graphql_resolve_argument_type(name, type)
82
- return type if type.present?
96
+ return Helpers.graphql_type(type) if type.present?
83
97
 
84
98
  column_def = column(name)
85
99
 
@@ -160,9 +174,24 @@ module Graphiform
160
174
  end
161
175
  end
162
176
 
163
- def graphql_add_field_to_type(field_name, type, null = nil)
177
+ def graphql_add_field_to_type(
178
+ field_name,
179
+ type,
180
+ null = nil,
181
+ description: nil,
182
+ deprecation_reason: nil,
183
+ method: nil,
184
+ read_prepare: nil,
185
+ **_options
186
+ )
164
187
  field_name = field_name.to_sym
165
- field_options = {}
188
+ field_options = {
189
+ description: description,
190
+ deprecation_reason: deprecation_reason,
191
+ method: method,
192
+ }
193
+
194
+ type = Helpers.graphql_type(type)
166
195
 
167
196
  if Helpers.resolver?(type)
168
197
  field_options[:resolver] = type
@@ -172,19 +201,21 @@ module Graphiform
172
201
  end
173
202
 
174
203
  graphql_type.class_eval do
175
- field(field_name, **field_options)
204
+ added_field = field(field_name, **field_options)
205
+
206
+ define_method(added_field.method_sym, -> { read_prepare.call(object.public_send(added_field.method_sym)) }) if read_prepare
176
207
  end
177
208
  end
178
209
 
179
- def graphql_add_column_field(field_name, column_def, type: nil, null: nil, **_options)
210
+ def graphql_add_column_field(field_name, column_def, type: nil, null: nil, **options)
180
211
  type = :string if type.blank? && enum_attribute?(field_name)
181
- type = Helpers.graphql_type(type || column_def.type)
212
+ type ||= column_def.type
182
213
  null = column_def.null if null.nil?
183
214
 
184
- graphql_add_field_to_type(field_name, type, null)
215
+ graphql_add_field_to_type(field_name, type, null, **options)
185
216
  end
186
217
 
187
- def graphql_add_association_field(field_name, association_def, type: nil, null: nil, **_options)
218
+ def graphql_add_association_field(field_name, association_def, type: nil, null: nil, **options)
188
219
  unless association_def.klass.respond_to?(:graphql_type)
189
220
  return Helpers.logger.warn(
190
221
  "Graphiform: `#{name}` trying to add association `#{field_name}` - `#{association_def.klass.name}` does not include Graphiform"
@@ -204,20 +235,21 @@ module Graphiform
204
235
  graphql_add_field_to_type(
205
236
  "#{field_name}_connection",
206
237
  klass.graphql_create_resolver(association_def.name, graphql_connection),
207
- false
238
+ false,
239
+ **options
208
240
  )
209
241
  end
210
242
 
211
243
  type = has_many ? klass.graphql_create_resolver(association_def.name, [klass.graphql_type]) : klass.graphql_type if type.nil?
212
244
  null = association_def.macro != :has_many if null.nil?
213
245
 
214
- graphql_add_field_to_type(field_name, type, null)
246
+ graphql_add_field_to_type(field_name, type, null, **options)
215
247
  end
216
248
 
217
- def graphql_add_method_field(field_name, type:, null: true, **_options)
249
+ def graphql_add_method_field(field_name, type:, null: true, **options)
218
250
  return Helpers.logger.warn "Graphiform: Missing `type` for field `#{field_name}` in model `#{name}`" if type.nil?
219
251
 
220
- graphql_add_field_to_type(field_name, type, null)
252
+ graphql_add_field_to_type(field_name, type, null, **options)
221
253
  end
222
254
  end
223
255
  end
@@ -3,8 +3,6 @@ require 'graphiform/helpers'
3
3
 
4
4
  module Graphiform
5
5
  def self.create_skeleton
6
- return if defined? @skeleton_created
7
-
8
6
  # Types
9
7
  Helpers.get_const_or_create('Types') do
10
8
  Module.new
@@ -89,7 +87,5 @@ module Graphiform
89
87
  value 'DESC', 'Sort results in descending order'
90
88
  end
91
89
  end
92
-
93
- @skeleton_created = true
94
90
  end
95
91
  end
@@ -1,3 +1,3 @@
1
1
  module Graphiform
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
data/lib/graphiform.rb CHANGED
@@ -8,9 +8,9 @@ require 'graphiform/fields'
8
8
 
9
9
  module Graphiform
10
10
  def self.included(base)
11
- base.class_eval do
12
- Graphiform.create_skeleton
11
+ Graphiform.create_skeleton
13
12
 
13
+ base.class_eval do
14
14
  include Scopiform
15
15
 
16
16
  include Graphiform::ActiveRecordHelpers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-17 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: spy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: sqlite3
71
85
  requirement: !ruby/object:Gem::Requirement