graphiform 0.3.1 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 843abce3fab5e2fcc03b27f6a4edf4a1635b7648f1fb8eaca1cff602d155e3d0
4
- data.tar.gz: 10e6c019669c55183c96041bb8862bd9505eba7c6ff7d604dd72127df8b3455b
3
+ metadata.gz: 79311a028aff4bd3c7446554c4661ab87841fdbc82697c2d49080047d614afa1
4
+ data.tar.gz: 6da53e957a2d9494cc5efdfa7d962200626cb8d70affd1b54f8201b958a54f23
5
5
  SHA512:
6
- metadata.gz: 1ddd81b9eaa52a0b92db63c41f4f0948fca928c33937b0bd5f5b8d5e08cafa2b4187c0cc7b7c3ab8d115c85488231f2bdd282f2579e35e195d3fc64c1cdbdd81
7
- data.tar.gz: c700abaaeca982cf422e720bb9f87c05342733ea78e36074e7e4262b62c5fca00905217290d586f2066e14e930e8e6317f87c8a1395694f19668d614ecea329f
6
+ metadata.gz: 6b126781364fd8bcd1981cbb014a1b0a69b1ddc966c786e83ebd1d6b985e3fdf808bf3f1d56bc207fde7fc9db941da57eafd5cff08856c3b92aa36ed2ee0aa65
7
+ data.tar.gz: fa9f8f19ac3820edb8ccf20465c67c4ab74aac074ef0dca32b6f723d566fa204396fc0aeec5d17fdf0a341da856eba60a852d9e1484dd5e578dc96cf0b1d15d3
@@ -11,21 +11,33 @@ module Graphiform
11
11
 
12
12
  module ClassMethods
13
13
  def graphql_type
14
- local_demodulized_name = demodulized_name
15
- Helpers.get_const_or_create(local_demodulized_name, ::Types) do
16
- Class.new(::Types::BaseObject) do
17
- graphql_name local_demodulized_name
14
+ unless defined? @graphql_type
15
+ local_demodulized_name = demodulized_name
16
+ @graphql_type = Helpers.get_const_or_create(local_demodulized_name, ::Types) do
17
+ Class.new(::Types::BaseObject) do
18
+ graphql_name local_demodulized_name
19
+ end
20
+ end
21
+ @graphql_type.class_eval do
22
+ field_class Graphiform.configuration[:field_class] if Graphiform.configuration[:field_class].present?
18
23
  end
19
24
  end
25
+ @graphql_type
20
26
  end
21
27
 
22
28
  def graphql_input
23
- local_demodulized_name = demodulized_name
24
- Helpers.get_const_or_create(local_demodulized_name, ::Inputs) do
25
- Class.new(::Inputs::BaseInput) do
26
- graphql_name "#{local_demodulized_name}Input"
29
+ unless defined? @graphql_input
30
+ local_demodulized_name = demodulized_name
31
+ @graphql_input = Helpers.get_const_or_create(local_demodulized_name, ::Inputs) do
32
+ Class.new(::Inputs::BaseInput) do
33
+ graphql_name "#{local_demodulized_name}Input"
34
+ end
35
+ end
36
+ @graphql_input.class_eval do
37
+ argument_class Graphiform.configuration[:argument_class] if Graphiform.configuration[:argument_class].present?
27
38
  end
28
39
  end
40
+ @graphql_input
29
41
  end
30
42
 
31
43
  def graphql_filter
@@ -37,6 +49,7 @@ module Graphiform
37
49
  end
38
50
  end
39
51
  @filter.class_eval do
52
+ argument_class Graphiform.configuration[:argument_class] if Graphiform.configuration[:argument_class].present?
40
53
  argument 'OR', [self], required: false
41
54
  argument 'AND', [self], required: false
42
55
  end
@@ -46,21 +59,34 @@ module Graphiform
46
59
  end
47
60
 
48
61
  def graphql_sort
49
- local_demodulized_name = demodulized_name
50
- Helpers.get_const_or_create(local_demodulized_name, ::Inputs::Sorts) do
51
- Class.new(::Inputs::Sorts::BaseSort) do
52
- graphql_name "#{local_demodulized_name}Sort"
62
+ unless defined? @graphql_sort
63
+ local_demodulized_name = demodulized_name
64
+ @graphql_sort = Helpers.get_const_or_create(local_demodulized_name, ::Inputs::Sorts) do
65
+ Class.new(::Inputs::Sorts::BaseSort) do
66
+ graphql_name "#{local_demodulized_name}Sort"
67
+ end
68
+ end
69
+ @graphql_sort.class_eval do
70
+ argument_class Graphiform.configuration[:argument_class] if Graphiform.configuration[:argument_class].present?
53
71
  end
54
72
  end
73
+ @graphql_sort
55
74
  end
56
75
 
57
76
  def graphql_grouping
58
- local_demodulized_name = demodulized_name
59
- Helpers.get_const_or_create(local_demodulized_name, ::Inputs::Groupings) do
60
- Class.new(::Inputs::Groupings::BaseGrouping) do
61
- graphql_name "#{local_demodulized_name}Grouping"
77
+ unless defined? @graphql_grouping
78
+ local_demodulized_name = demodulized_name
79
+ @graphql_grouping = Helpers.get_const_or_create(local_demodulized_name, ::Inputs::Groupings) do
80
+ Class.new(::Inputs::Groupings::BaseGrouping) do
81
+ graphql_name "#{local_demodulized_name}Grouping"
82
+ argument_class Graphiform.configuration[:argument_class] if Graphiform.configuration[:argument_class].present?
83
+ end
84
+ end
85
+ @graphql_grouping.class_eval do
86
+ argument_class Graphiform.configuration[:argument_class] if Graphiform.configuration[:argument_class].present?
62
87
  end
63
88
  end
89
+ @graphql_grouping
64
90
  end
65
91
 
66
92
  def graphql_edge
@@ -10,19 +10,21 @@ module Graphiform
10
10
  def graphql_readable_field(
11
11
  name,
12
12
  as: nil,
13
+ read_prepare: nil,
14
+ null: nil,
13
15
  **options
14
16
  )
15
17
  identifier = as || name
16
18
  column_def = column(identifier)
17
19
  association_def = association(identifier)
18
20
 
19
- graphql_add_column_field(name, column_def, as: as, **options) if column_def.present?
20
- graphql_add_association_field(name, association_def, as: as, **options) if association_def.present?
21
- graphql_add_method_field(name, as: as, **options) unless column_def.present? || association_def.present?
21
+ graphql_add_column_field(name, column_def, read_prepare: read_prepare, null: null, as: as, **options) if column_def.present?
22
+ graphql_add_association_field(name, association_def, read_prepare: read_prepare, null: null, as: as, **options) if association_def.present?
23
+ graphql_add_method_field(name, read_prepare: read_prepare, null: null, as: as, **options) unless column_def.present? || association_def.present?
22
24
 
23
- graphql_add_scopes_to_filter(name, identifier)
24
- graphql_field_to_sort(name, identifier)
25
- graphql_field_to_grouping(name, identifier)
25
+ graphql_add_scopes_to_filter(name, identifier, **options)
26
+ graphql_field_to_sort(name, identifier, **options)
27
+ graphql_field_to_grouping(name, identifier, **options)
26
28
  end
27
29
 
28
30
  def graphql_writable_field(
@@ -34,7 +36,7 @@ module Graphiform
34
36
  description: nil,
35
37
  default_value: ::GraphQL::Schema::Argument::NO_DEFAULT,
36
38
  as: nil,
37
- **
39
+ **args
38
40
  )
39
41
  name = name.to_sym
40
42
  has_nested_attributes_method = instance_methods.include?("#{as || name}_attributes=".to_sym)
@@ -56,9 +58,10 @@ module Graphiform
56
58
  description: description,
57
59
  default_value: default_value,
58
60
  as: as,
59
- method_access: false
61
+ method_access: false,
62
+ **args
60
63
  )
61
- end
64
+ end unless graphql_input.arguments.keys.any? { |key| Helpers.equal_graphql_names?(key, argument_name) }
62
65
  end
63
66
 
64
67
  def graphql_field(
@@ -66,10 +69,13 @@ module Graphiform
66
69
  write_name: nil,
67
70
  readable: true,
68
71
  writable: false,
72
+ read_prepare: nil,
73
+ write_prepare: nil,
74
+ null: nil,
69
75
  **options
70
76
  )
71
- graphql_readable_field(name, **options) if readable
72
- graphql_writable_field(write_name || name, **options) if writable
77
+ graphql_readable_field(name, read_prepare: read_prepare, null: null, **options) if readable
78
+ graphql_writable_field(write_name || name, write_prepare: write_prepare, **options) if writable
73
79
  end
74
80
 
75
81
  def graphql_fields(*names, **options)
@@ -109,7 +115,7 @@ module Graphiform
109
115
  has_many ? [association_def.klass.graphql_input] : association_def.klass.graphql_input
110
116
  end
111
117
 
112
- def graphql_add_scopes_to_filter(name, as)
118
+ def graphql_add_scopes_to_filter(name, as, **options)
113
119
  added_scopes = auto_scopes_by_attribute(as)
114
120
 
115
121
  return if added_scopes.empty?
@@ -132,11 +138,11 @@ module Graphiform
132
138
  enum = graphql_create_enum(name)
133
139
  scope_argument_type = scope_argument_type.is_a?(Array) ? [enum] : enum
134
140
  end
135
- add_scope_def_to_filter(name, added_scope, scope_argument_type)
141
+ add_scope_def_to_filter(name, added_scope, scope_argument_type, **options)
136
142
  end
137
143
  end
138
144
 
139
- def add_scope_def_to_filter(name, scope_def, argument_type)
145
+ def add_scope_def_to_filter(name, scope_def, argument_type, **options)
140
146
  return unless argument_type
141
147
 
142
148
  argument_type = Helpers.graphql_type(argument_type)
@@ -152,12 +158,13 @@ module Graphiform
152
158
  argument_type,
153
159
  required: false,
154
160
  as: scope_name,
155
- method_access: false
161
+ method_access: false,
162
+ **options
156
163
  )
157
- end
164
+ end unless graphql_filter.arguments.keys.any? { |key| Helpers.equal_graphql_names?(key, argument_name) }
158
165
  end
159
166
 
160
- def graphql_field_to_sort(name, as)
167
+ def graphql_field_to_sort(name, as, **options)
161
168
  column_def = column(as || name)
162
169
  association_def = association(as || name)
163
170
 
@@ -174,12 +181,13 @@ module Graphiform
174
181
  type,
175
182
  required: false,
176
183
  as: as,
177
- method_access: false
184
+ method_access: false,
185
+ **options
178
186
  )
179
- end
187
+ end unless local_graphql_sort.arguments.keys.any? { |key| Helpers.equal_graphql_names?(key, name) }
180
188
  end
181
189
 
182
- def graphql_field_to_grouping(name, as)
190
+ def graphql_field_to_grouping(name, as, **options)
183
191
  column_def = column(as || name)
184
192
  association_def = association(as || name)
185
193
 
@@ -196,9 +204,10 @@ module Graphiform
196
204
  type,
197
205
  required: false,
198
206
  as: as,
199
- method_access: false
207
+ method_access: false,
208
+ **options
200
209
  )
201
- end
210
+ end unless local_graphql_grouping.arguments.keys.any? { |key| Helpers.equal_graphql_names?(key, name) }
202
211
  end
203
212
 
204
213
  def graphql_add_field_to_type(
@@ -211,7 +220,7 @@ module Graphiform
211
220
  as: nil,
212
221
  read_prepare: nil,
213
222
  read_resolve: nil,
214
- **
223
+ **options
215
224
  )
216
225
  type = Helpers.graphql_type(type)
217
226
  is_resolver = Helpers.resolver?(type)
@@ -231,7 +240,7 @@ module Graphiform
231
240
  end
232
241
 
233
242
  graphql_type.class_eval do
234
- added_field = field(field_name, **field_options)
243
+ added_field = field(field_name, **field_options, **options)
235
244
 
236
245
  if read_prepare || read_resolve
237
246
  define_method(
@@ -244,7 +253,7 @@ module Graphiform
244
253
  end
245
254
  )
246
255
  end
247
- end
256
+ end unless graphql_type.fields.keys.any? { |key| Helpers.equal_graphql_names?(key, field_name) }
248
257
  end
249
258
 
250
259
  def graphql_add_column_field(field_name, column_def, type: nil, null: nil, as: nil, **options)
@@ -42,6 +42,10 @@ module Graphiform
42
42
  val
43
43
  end
44
44
 
45
+ def self.equal_graphql_names?(key, name)
46
+ key.downcase == name.to_s.camelize.downcase || key.downcase == name.to_s.downcase
47
+ end
48
+
45
49
  def self.full_const_name(name)
46
50
  name = "Object#{name}" if name.starts_with?('::')
47
51
  name = "Object::#{name}" unless name.starts_with?('Object::')
@@ -3,7 +3,6 @@ require 'graphiform/helpers'
3
3
 
4
4
  module Graphiform
5
5
  def self.create_skeleton
6
-
7
6
  # Types
8
7
  Helpers.get_const_or_create('Types') do
9
8
  Module.new
@@ -1,3 +1,3 @@
1
1
  module Graphiform
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
data/lib/graphiform.rb CHANGED
@@ -6,6 +6,7 @@ require 'graphiform/active_record_helpers'
6
6
  require 'graphiform/core'
7
7
  require 'graphiform/fields'
8
8
  require 'graphiform/sort_enum'
9
+ class GraphiformConfigurationError < StandardError; end
9
10
 
10
11
  module Graphiform
11
12
  def self.included(base)
@@ -49,5 +50,10 @@ module Graphiform
49
50
 
50
51
  def self.configure
51
52
  yield(configuration)
53
+ if configuration[:field_class].present? && configuration[:argument_class].blank?
54
+ raise GraphiformConfigurationError, 'If field_class is provided an argument class must also be provided'
55
+ elsif configuration[:field_class].blank? && configuration[:argument_class].present?
56
+ raise GraphiformConfigurationError, 'If argument_class is provided a field_class must also be provided'
57
+ end
52
58
  end
53
59
  end
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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jayce.pulsipher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-19 00:00:00.000000000 Z
11
+ date: 2025-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord