graphiform 0.2.0 → 0.2.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/fields.rb +42 -39
- data/lib/graphiform/version.rb +1 -1
- 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: 526c94bd74004084cc768835a9053591a755f8eccfdebefae6ed4bd44a972399
|
4
|
+
data.tar.gz: 913464048608818458ede08de55cfdda5c8cc3cd4855ee98bbb44763d1c1423b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e8eb91cf3db0dd05c907b9e2d5cd31d5a262a939c491ae6d7b791b9ac4bee9853c80475d031ee2fdfb38e944ea35fa0d80c2af6bf15061045a9b0c3b674bbec
|
7
|
+
data.tar.gz: 9fc6e350f1b2603a3e8205e5ce4d762f7107959040ac9cee557e912c52891cca1e315ffe0a86847538ab14aaa659f9842bcaabde018915ed970240aab619125d
|
data/lib/graphiform/fields.rb
CHANGED
@@ -9,17 +9,18 @@ module Graphiform
|
|
9
9
|
module ClassMethods
|
10
10
|
def graphql_readable_field(
|
11
11
|
name,
|
12
|
+
as: nil,
|
12
13
|
**options
|
13
14
|
)
|
14
|
-
column_def = column(name)
|
15
|
-
association_def = association(name)
|
15
|
+
column_def = column(as || name)
|
16
|
+
association_def = association(as || name)
|
16
17
|
|
17
|
-
graphql_add_column_field(name, column_def, **options) if column_def.present?
|
18
|
-
graphql_add_association_field(name, association_def, **options) if association_def.present?
|
19
|
-
graphql_add_method_field(name, **options) unless column_def.present? || association_def.present?
|
18
|
+
graphql_add_column_field(name, column_def, as: as, **options) if column_def.present?
|
19
|
+
graphql_add_association_field(name, association_def, as: as, **options) if association_def.present?
|
20
|
+
graphql_add_method_field(name, as: as, **options) unless column_def.present? || association_def.present?
|
20
21
|
|
21
|
-
graphql_add_scopes_to_filter(name)
|
22
|
-
graphql_field_to_sort(name)
|
22
|
+
graphql_add_scopes_to_filter(name, as || name)
|
23
|
+
graphql_field_to_sort(name, as || name)
|
23
24
|
end
|
24
25
|
|
25
26
|
def graphql_writable_field(
|
@@ -31,25 +32,30 @@ module Graphiform
|
|
31
32
|
description: nil,
|
32
33
|
default_value: ::GraphQL::Schema::Argument::NO_DEFAULT,
|
33
34
|
as: nil,
|
34
|
-
**
|
35
|
+
**
|
35
36
|
)
|
36
37
|
name = name.to_sym
|
37
|
-
|
38
|
-
|
38
|
+
has_nested_attributes_method = instance_methods.include?("#{as || name}_attributes=".to_sym)
|
39
|
+
|
40
|
+
argument_name = has_nested_attributes_method ? "#{name}_attributes".to_sym : name
|
41
|
+
argument_type = graphql_resolve_argument_type(as || name, type)
|
42
|
+
as = has_nested_attributes_method ? "#{as}_attributes".to_sym : as.to_sym if as
|
39
43
|
|
40
44
|
return Helpers.logger.warn "Graphiform: Missing `type` for argument #{name}" if argument_type.nil?
|
41
45
|
|
42
46
|
prepare = write_prepare || prepare
|
43
47
|
|
44
48
|
graphql_input.class_eval do
|
45
|
-
argument
|
49
|
+
argument(
|
46
50
|
argument_name,
|
47
51
|
argument_type,
|
48
52
|
required: required,
|
49
53
|
prepare: prepare,
|
50
54
|
description: description,
|
51
55
|
default_value: default_value,
|
52
|
-
as: as
|
56
|
+
as: as,
|
57
|
+
method_access: false
|
58
|
+
)
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
@@ -84,14 +90,6 @@ module Graphiform
|
|
84
90
|
|
85
91
|
private
|
86
92
|
|
87
|
-
def graphql_resolve_argument_name(name)
|
88
|
-
attributes_name = "#{name}_attributes"
|
89
|
-
|
90
|
-
return attributes_name.to_sym if instance_methods.include?("#{attributes_name}=".to_sym)
|
91
|
-
|
92
|
-
name
|
93
|
-
end
|
94
|
-
|
95
93
|
def graphql_resolve_argument_type(name, type)
|
96
94
|
type = graphql_create_enum(name) if type.blank? && enum_attribute?(name)
|
97
95
|
|
@@ -109,12 +107,12 @@ module Graphiform
|
|
109
107
|
has_many ? [association_def.klass.graphql_input] : association_def.klass.graphql_input
|
110
108
|
end
|
111
109
|
|
112
|
-
def graphql_add_scopes_to_filter(name)
|
113
|
-
added_scopes = auto_scopes_by_attribute(
|
110
|
+
def graphql_add_scopes_to_filter(name, as)
|
111
|
+
added_scopes = auto_scopes_by_attribute(as)
|
114
112
|
|
115
113
|
return if added_scopes.empty?
|
116
114
|
|
117
|
-
association_def = association(
|
115
|
+
association_def = association(as)
|
118
116
|
|
119
117
|
if association_def.present?
|
120
118
|
return unless Helpers.association_arguments_valid?(association_def, :graphql_filter)
|
@@ -130,15 +128,15 @@ module Graphiform
|
|
130
128
|
enum = graphql_create_enum(name)
|
131
129
|
scope_argument_type = scope_argument_type.is_a?(Array) ? [enum] : enum
|
132
130
|
end
|
133
|
-
add_scope_def_to_filter(added_scope, scope_argument_type)
|
131
|
+
add_scope_def_to_filter(name, added_scope, scope_argument_type)
|
134
132
|
end
|
135
133
|
end
|
136
134
|
|
137
|
-
def add_scope_def_to_filter(scope_def, argument_type)
|
135
|
+
def add_scope_def_to_filter(name, scope_def, argument_type)
|
138
136
|
return unless argument_type
|
139
137
|
|
140
138
|
argument_type = Helpers.graphql_type(argument_type)
|
141
|
-
argument_attribute =
|
139
|
+
argument_attribute = name
|
142
140
|
argument_prefix = scope_def.prefix
|
143
141
|
argument_suffix = scope_def.suffix == '_is' ? '' : scope_def.suffix
|
144
142
|
argument_name = "#{argument_prefix}#{argument_attribute}#{argument_suffix}".underscore
|
@@ -149,14 +147,15 @@ module Graphiform
|
|
149
147
|
argument_name,
|
150
148
|
argument_type,
|
151
149
|
required: false,
|
152
|
-
as: scope_name
|
150
|
+
as: scope_name,
|
151
|
+
method_access: false
|
153
152
|
)
|
154
153
|
end
|
155
154
|
end
|
156
155
|
|
157
|
-
def graphql_field_to_sort(name)
|
158
|
-
column_def = column(name)
|
159
|
-
association_def = association(name)
|
156
|
+
def graphql_field_to_sort(name, as)
|
157
|
+
column_def = column(as || name)
|
158
|
+
association_def = association(as || name)
|
160
159
|
|
161
160
|
type = ::Enums::Sort if column_def.present?
|
162
161
|
type = association_def.klass.graphql_sort if Helpers.association_arguments_valid?(association_def, :graphql_sort)
|
@@ -169,7 +168,9 @@ module Graphiform
|
|
169
168
|
argument(
|
170
169
|
name,
|
171
170
|
type,
|
172
|
-
required: false
|
171
|
+
required: false,
|
172
|
+
as: as,
|
173
|
+
method_access: false
|
173
174
|
)
|
174
175
|
end
|
175
176
|
end
|
@@ -181,18 +182,20 @@ module Graphiform
|
|
181
182
|
description: nil,
|
182
183
|
deprecation_reason: nil,
|
183
184
|
method: nil,
|
185
|
+
as: nil,
|
184
186
|
read_prepare: nil,
|
185
|
-
**
|
187
|
+
**
|
186
188
|
)
|
189
|
+
type = Helpers.graphql_type(type)
|
190
|
+
is_resolver = Helpers.resolver?(type)
|
191
|
+
|
187
192
|
field_name = field_name.to_sym
|
188
193
|
field_options = {
|
189
194
|
description: description,
|
190
195
|
deprecation_reason: deprecation_reason,
|
191
|
-
method: method,
|
196
|
+
method: is_resolver ? nil : method || as,
|
192
197
|
}
|
193
198
|
|
194
|
-
type = Helpers.graphql_type(type)
|
195
|
-
|
196
199
|
if Helpers.resolver?(type)
|
197
200
|
field_options[:resolver] = type
|
198
201
|
else
|
@@ -212,16 +215,16 @@ module Graphiform
|
|
212
215
|
end
|
213
216
|
end
|
214
217
|
|
215
|
-
def graphql_add_column_field(field_name, column_def, type: nil, null: nil, **options)
|
216
|
-
is_enum = type.blank? && enum_attribute?(field_name)
|
218
|
+
def graphql_add_column_field(field_name, column_def, type: nil, null: nil, as: nil, **options)
|
219
|
+
is_enum = type.blank? && enum_attribute?(as || field_name)
|
217
220
|
if is_enum
|
218
|
-
enum = graphql_create_enum(field_name)
|
221
|
+
enum = graphql_create_enum(as || field_name)
|
219
222
|
type = enum
|
220
223
|
end
|
221
224
|
type ||= column_def.type
|
222
225
|
null = column_def.null if null.nil?
|
223
226
|
|
224
|
-
graphql_add_field_to_type(field_name, type, null, **options)
|
227
|
+
graphql_add_field_to_type(field_name, type, null, as: as, **options)
|
225
228
|
end
|
226
229
|
|
227
230
|
def graphql_add_association_field(field_name, association_def, type: nil, null: nil, include_connection: true, read_prepare: nil, **options)
|
data/lib/graphiform/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.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: 2020-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|