graphiform 0.3.4 → 0.4.1
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/lib/graphiform/core.rb +42 -16
- data/lib/graphiform/fields.rb +31 -20
- data/lib/graphiform/skeleton.rb +0 -1
- data/lib/graphiform/version.rb +1 -1
- data/lib/graphiform.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fe59e03d0206ec1a77e8c8528e5950fbc31129bba16f8a3a7fe8019cf7f6961
|
4
|
+
data.tar.gz: cb4292984369688038ba1b6b4c60900c5bca472be376106442e2425f5b035e44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ec2b1bc0fc661c2f1353b62ccf8d689c8919722a4364a5239d01e7fa35760ee17a11eb9f9a2cdda197a50cf1be3fb58559ac7d684f8a5f0d1a07bd76a3b1646
|
7
|
+
data.tar.gz: 057d78c54bbe196ba1e6fb37dfbc43c2334d58683def817f2352e61361943b5843aaed46f40e2f774f28d34c33b8db56ca8786ae78550304bf5883c6c78a055e
|
data/lib/graphiform/core.rb
CHANGED
@@ -11,21 +11,33 @@ module Graphiform
|
|
11
11
|
|
12
12
|
module ClassMethods
|
13
13
|
def graphql_type
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
data/lib/graphiform/fields.rb
CHANGED
@@ -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,7 +58,8 @@ 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
64
|
end unless graphql_input.arguments.keys.any? { |key| Helpers.equal_graphql_names?(key, argument_name) }
|
62
65
|
end
|
@@ -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
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
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,7 +204,8 @@ 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
210
|
end unless local_graphql_grouping.arguments.keys.any? { |key| Helpers.equal_graphql_names?(key, name) }
|
202
211
|
end
|
@@ -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(
|
@@ -339,6 +348,8 @@ module Graphiform
|
|
339
348
|
def graphql_add_method_field(field_name, type: nil, null: true, **options)
|
340
349
|
return Helpers.logger.warn "Graphiform: Missing `type` for field `#{field_name}` in model `#{name}`" if type.nil?
|
341
350
|
|
351
|
+
null = true if null.nil?
|
352
|
+
|
342
353
|
graphql_add_field_to_type(field_name, type, null, **options)
|
343
354
|
end
|
344
355
|
end
|
data/lib/graphiform/skeleton.rb
CHANGED
data/lib/graphiform/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.1
|
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-
|
11
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|