graphiform 0.2.1 → 0.2.6
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.rb +1 -0
- data/lib/graphiform/core.rb +5 -4
- data/lib/graphiform/fields.rb +46 -9
- data/lib/graphiform/skeleton.rb +0 -7
- data/lib/graphiform/sort_enum.rb +8 -0
- data/lib/graphiform/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7499ef9e7181b749ac563666f65231e933d047bbdcc39dbe6f708bdb14e8eab9
|
4
|
+
data.tar.gz: 3fc690f7cb20996f420516cceb158ff9aa103b2b7ed1e7bae6ceead0864f4409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7037e930060d081d86091b0c023fb3b3813b6a487bbe19785ebde5f6824eae27210839eb4174e5ea47f3499464aa346609ffc76838ab5c814063b754fa44393b
|
7
|
+
data.tar.gz: b41292d3ab6b29c3ab9a2eaa8e02c1743f14095ccc88396e3e6602fb1d8e6964b8576885cb95d0006c88509a7befd54450415ce407e0ed31b4bc9f4eeaa38406
|
data/lib/graphiform.rb
CHANGED
data/lib/graphiform/core.rb
CHANGED
@@ -136,7 +136,7 @@ module Graphiform
|
|
136
136
|
Helpers.get_const_or_create(demodulized_name, ::Resolvers::Queries) do
|
137
137
|
local_graphql_type = graphql_type
|
138
138
|
Class.new(graphql_base_resolver) do
|
139
|
-
type local_graphql_type, null:
|
139
|
+
type local_graphql_type, null: true
|
140
140
|
|
141
141
|
def base_resolve(**args)
|
142
142
|
@value = model.all
|
@@ -161,14 +161,15 @@ module Graphiform
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
def graphql_create_resolver(method_name, resolver_type = graphql_type, read_prepare: nil, **)
|
164
|
+
def graphql_create_resolver(method_name, resolver_type = graphql_type, read_prepare: nil, read_resolve: nil, null: true, **)
|
165
165
|
Class.new(graphql_base_resolver) do
|
166
|
-
type resolver_type, null:
|
166
|
+
type resolver_type, null: null
|
167
167
|
|
168
168
|
define_method :base_resolve do |**args|
|
169
169
|
@value = object
|
170
170
|
|
171
|
-
@value = @value
|
171
|
+
@value = instance_exec(@value, context, &read_resolve) if read_resolve
|
172
|
+
@value = @value.public_send(method_name) if !read_resolve && @value.respond_to?(method_name)
|
172
173
|
@value = instance_exec(@value, context, &read_prepare) if read_prepare
|
173
174
|
|
174
175
|
apply_built_ins(**args)
|
data/lib/graphiform/fields.rb
CHANGED
@@ -41,7 +41,7 @@ module Graphiform
|
|
41
41
|
argument_type = graphql_resolve_argument_type(as || name, type)
|
42
42
|
as = has_nested_attributes_method ? "#{as}_attributes".to_sym : as.to_sym if as
|
43
43
|
|
44
|
-
return Helpers.logger.warn "Graphiform: Missing `type` for argument
|
44
|
+
return Helpers.logger.warn "Graphiform: Missing `type` for argument `#{name}` in model `#{self.name}`" if argument_type.nil?
|
45
45
|
|
46
46
|
prepare = write_prepare || prepare
|
47
47
|
|
@@ -157,7 +157,7 @@ module Graphiform
|
|
157
157
|
column_def = column(as || name)
|
158
158
|
association_def = association(as || name)
|
159
159
|
|
160
|
-
type = ::
|
160
|
+
type = ::Graphiform::SortEnum if column_def.present?
|
161
161
|
type = association_def.klass.graphql_sort if Helpers.association_arguments_valid?(association_def, :graphql_sort)
|
162
162
|
|
163
163
|
return if type.blank?
|
@@ -184,6 +184,7 @@ module Graphiform
|
|
184
184
|
method: nil,
|
185
185
|
as: nil,
|
186
186
|
read_prepare: nil,
|
187
|
+
read_resolve: nil,
|
187
188
|
**
|
188
189
|
)
|
189
190
|
type = Helpers.graphql_type(type)
|
@@ -206,10 +207,15 @@ module Graphiform
|
|
206
207
|
graphql_type.class_eval do
|
207
208
|
added_field = field(field_name, **field_options)
|
208
209
|
|
209
|
-
if read_prepare
|
210
|
+
if read_prepare || read_resolve
|
210
211
|
define_method(
|
211
212
|
added_field.method_sym,
|
212
|
-
|
213
|
+
lambda do
|
214
|
+
value = read_resolve ? instance_exec(object, context, &read_resolve) : object.public_send(added_field.method_sym)
|
215
|
+
value = instance_exec(value, context, &read_prepare) if read_prepare
|
216
|
+
|
217
|
+
value
|
218
|
+
end
|
213
219
|
)
|
214
220
|
end
|
215
221
|
end
|
@@ -227,7 +233,16 @@ module Graphiform
|
|
227
233
|
graphql_add_field_to_type(field_name, type, null, as: as, **options)
|
228
234
|
end
|
229
235
|
|
230
|
-
def graphql_add_association_field(
|
236
|
+
def graphql_add_association_field(
|
237
|
+
field_name,
|
238
|
+
association_def,
|
239
|
+
type: nil,
|
240
|
+
null: nil,
|
241
|
+
include_connection: true,
|
242
|
+
read_prepare: nil,
|
243
|
+
read_resolve: nil,
|
244
|
+
**options
|
245
|
+
)
|
231
246
|
unless association_def.klass.respond_to?(:graphql_type)
|
232
247
|
return Helpers.logger.warn(
|
233
248
|
"Graphiform: `#{name}` trying to add association `#{field_name}` - `#{association_def.klass.name}` does not include Graphiform"
|
@@ -246,20 +261,42 @@ module Graphiform
|
|
246
261
|
if include_connection && has_many
|
247
262
|
graphql_add_field_to_type(
|
248
263
|
"#{field_name}_connection",
|
249
|
-
klass.graphql_create_resolver(
|
264
|
+
klass.graphql_create_resolver(
|
265
|
+
association_def.name,
|
266
|
+
klass.graphql_connection,
|
267
|
+
read_prepare: read_prepare,
|
268
|
+
read_resolve: read_resolve,
|
269
|
+
null: false
|
270
|
+
),
|
250
271
|
false,
|
251
272
|
**options
|
252
273
|
)
|
253
274
|
end
|
254
275
|
|
255
276
|
if type.nil?
|
256
|
-
type =
|
257
|
-
|
277
|
+
type = (
|
278
|
+
if has_many
|
279
|
+
klass.graphql_create_resolver(
|
280
|
+
association_def.name,
|
281
|
+
[klass.graphql_type],
|
282
|
+
read_prepare: read_prepare,
|
283
|
+
read_resolve: read_resolve,
|
284
|
+
null: false
|
285
|
+
)
|
286
|
+
else
|
287
|
+
klass.graphql_type
|
288
|
+
end
|
289
|
+
)
|
290
|
+
|
291
|
+
if has_many
|
292
|
+
read_prepare = nil
|
293
|
+
read_resolve = nil
|
294
|
+
end
|
258
295
|
end
|
259
296
|
|
260
297
|
null = association_def.macro != :has_many if null.nil?
|
261
298
|
|
262
|
-
graphql_add_field_to_type(field_name, type, null, read_prepare: read_prepare, **options)
|
299
|
+
graphql_add_field_to_type(field_name, type, null, read_prepare: read_prepare, read_resolve: read_resolve, **options)
|
263
300
|
end
|
264
301
|
|
265
302
|
def graphql_add_method_field(field_name, type: nil, null: true, **options)
|
data/lib/graphiform/skeleton.rb
CHANGED
@@ -80,12 +80,5 @@ module Graphiform
|
|
80
80
|
Helpers.get_const_or_create('BaseEnum', ::Enums) do
|
81
81
|
Class.new(::GraphQL::Schema::Enum)
|
82
82
|
end
|
83
|
-
|
84
|
-
Helpers.get_const_or_create('Sort', ::Enums) do
|
85
|
-
Class.new(::Enums::BaseEnum) do
|
86
|
-
value 'ASC', 'Sort results in ascending order'
|
87
|
-
value 'DESC', 'Sort results in descending order'
|
88
|
-
end
|
89
|
-
end
|
90
83
|
end
|
91
84
|
end
|
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.6
|
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-11-03 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.3
|
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.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: appraisal
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/graphiform/fields.rb
|
125
125
|
- lib/graphiform/helpers.rb
|
126
126
|
- lib/graphiform/skeleton.rb
|
127
|
+
- lib/graphiform/sort_enum.rb
|
127
128
|
- lib/graphiform/version.rb
|
128
129
|
- lib/tasks/graphiform_tasks.rake
|
129
130
|
homepage: https://github.com/3-form/graphiform
|