graphiform 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiform/core.rb +2 -1
- data/lib/graphiform/fields.rb +22 -7
- data/lib/graphiform/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6bde49d1fc203265aee73785f6ff23308b5d2098259dd7bbc762dc0a8c16322
|
4
|
+
data.tar.gz: 061af2e25afdf9dad9fdedab5847212e3b7005c36290dfcbccdc73b085dd1588
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df7c307f8fbaa68fa1a33ee60d9c364603dbd911cb3726fc20073cf1bb9decaf1809387f5048fa080cd4abb6908f51fd744c769cbbb5f8c1e88db7fe631a7a7
|
7
|
+
data.tar.gz: df1bc69c8e412ae66be318d65c5574fef2cf1d5d2371a98ddd1293a6ceea9e7b4ac6e3bcd794b1660e8c7a6e7fbe26aa97737b723e5f4d3d5b22ad256e42e8ee
|
data/lib/graphiform/core.rb
CHANGED
@@ -130,7 +130,7 @@ module Graphiform
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
def graphql_create_resolver(method_name, resolver_type = graphql_type)
|
133
|
+
def graphql_create_resolver(method_name, resolver_type = graphql_type, read_prepare: nil, **_options)
|
134
134
|
Class.new(graphql_base_resolver) do
|
135
135
|
type resolver_type, null: false
|
136
136
|
|
@@ -140,6 +140,7 @@ module Graphiform
|
|
140
140
|
val = super(**args)
|
141
141
|
|
142
142
|
val = val.public_send(method_name) if val.respond_to? method_name
|
143
|
+
val = instance_exec(val, context, &read_prepare) if read_prepare
|
143
144
|
|
144
145
|
return val.apply_filters(where_hash) if val.respond_to? :apply_filters
|
145
146
|
|
data/lib/graphiform/fields.rb
CHANGED
@@ -93,6 +93,8 @@ module Graphiform
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def graphql_resolve_argument_type(name, type)
|
96
|
+
type = graphql_create_enum(name) if type.blank? && enum_attribute?(name)
|
97
|
+
|
96
98
|
return Helpers.graphql_type(type) if type.present?
|
97
99
|
|
98
100
|
column_def = column(name)
|
@@ -203,19 +205,28 @@ module Graphiform
|
|
203
205
|
graphql_type.class_eval do
|
204
206
|
added_field = field(field_name, **field_options)
|
205
207
|
|
206
|
-
|
208
|
+
if read_prepare
|
209
|
+
define_method(
|
210
|
+
added_field.method_sym,
|
211
|
+
-> { instance_exec(object.public_send(added_field.method_sym), context, &read_prepare) }
|
212
|
+
)
|
213
|
+
end
|
207
214
|
end
|
208
215
|
end
|
209
216
|
|
210
217
|
def graphql_add_column_field(field_name, column_def, type: nil, null: nil, **options)
|
211
|
-
|
218
|
+
is_enum = type.blank? && enum_attribute?(field_name)
|
219
|
+
if is_enum
|
220
|
+
enum = graphql_create_enum(field_name)
|
221
|
+
type = enum
|
222
|
+
end
|
212
223
|
type ||= column_def.type
|
213
224
|
null = column_def.null if null.nil?
|
214
225
|
|
215
226
|
graphql_add_field_to_type(field_name, type, null, **options)
|
216
227
|
end
|
217
228
|
|
218
|
-
def graphql_add_association_field(field_name, association_def, type: nil, null: nil, **options)
|
229
|
+
def graphql_add_association_field(field_name, association_def, type: nil, null: nil, include_connection: true, read_prepare: nil, **options)
|
219
230
|
unless association_def.klass.respond_to?(:graphql_type)
|
220
231
|
return Helpers.logger.warn(
|
221
232
|
"Graphiform: `#{name}` trying to add association `#{field_name}` - `#{association_def.klass.name}` does not include Graphiform"
|
@@ -231,19 +242,23 @@ module Graphiform
|
|
231
242
|
has_many = association_def.macro == :has_many
|
232
243
|
klass = association_def.klass
|
233
244
|
|
234
|
-
if has_many
|
245
|
+
if include_connection && has_many
|
235
246
|
graphql_add_field_to_type(
|
236
247
|
"#{field_name}_connection",
|
237
|
-
klass.graphql_create_resolver(association_def.name, graphql_connection),
|
248
|
+
klass.graphql_create_resolver(association_def.name, klass.graphql_connection, read_prepare: read_prepare),
|
238
249
|
false,
|
239
250
|
**options
|
240
251
|
)
|
241
252
|
end
|
242
253
|
|
243
|
-
|
254
|
+
if type.nil?
|
255
|
+
type = has_many ? klass.graphql_create_resolver(association_def.name, [klass.graphql_type], read_prepare: read_prepare) : klass.graphql_type
|
256
|
+
read_prepare = nil if has_many
|
257
|
+
end
|
258
|
+
|
244
259
|
null = association_def.macro != :has_many if null.nil?
|
245
260
|
|
246
|
-
graphql_add_field_to_type(field_name, type, null, **options)
|
261
|
+
graphql_add_field_to_type(field_name, type, null, read_prepare: read_prepare, **options)
|
247
262
|
end
|
248
263
|
|
249
264
|
def graphql_add_method_field(field_name, type:, null: true, **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.1.
|
4
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2020-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.
|
47
|
+
version: 0.2.2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2.
|
54
|
+
version: 0.2.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: appraisal
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|