graphiform 0.1.3 → 0.1.4
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 +52 -25
- data/lib/graphiform/fields.rb +1 -1
- 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: 5ad540c4e174f075ab85b85f40e4dd63ebb4568ff0617b3c5dd6785410f55c63
|
4
|
+
data.tar.gz: a6b5a49c31a806ff942a87fef6ef4d1554f2cb9fc9867ad442f99501fc736025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb21cd22cdcecb06d9ff58c32ba0697cecf604bc8a0eb162fe846d0cd37dec604c082bd3d39bc744f8f418372629b7883d71da2e8cf5fc35bfe68e8a26b2639
|
7
|
+
data.tar.gz: d2abcff1ee1e4dd8e2b7703b5d73864082ce554895e0b6d34fc118afb2b11d942789de11af26410b6c82230dcfd71a1a96d22f7503dd3f3d7b46dc5a209bd324
|
data/lib/graphiform/core.rb
CHANGED
@@ -76,8 +76,38 @@ module Graphiform
|
|
76
76
|
unless defined? @base_resolver
|
77
77
|
@base_resolver = Helpers.get_const_or_create(demodulized_name, ::Resolvers) do
|
78
78
|
Class.new(::Resolvers::BaseResolver) do
|
79
|
-
|
80
|
-
|
79
|
+
attr_reader :value
|
80
|
+
|
81
|
+
class << self
|
82
|
+
attr_accessor :addon_resolve_blocks
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.addon_resolve(&block)
|
86
|
+
@addon_resolve_blocks ||= []
|
87
|
+
@addon_resolve_blocks << block
|
88
|
+
end
|
89
|
+
|
90
|
+
def resolve(**args)
|
91
|
+
@value = base_resolve(**args)
|
92
|
+
|
93
|
+
if self.class.addon_resolve_blocks.present? && !self.class.addon_resolve_blocks.empty?
|
94
|
+
self.class.addon_resolve_blocks.each do |addon_resolve_block|
|
95
|
+
@value = instance_exec(**args, &addon_resolve_block)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
@value
|
100
|
+
end
|
101
|
+
|
102
|
+
def apply_built_ins(where: nil, sort: nil, **)
|
103
|
+
@value = @value.apply_filters(where.to_h) if where.present? && @value.respond_to?(:apply_filters)
|
104
|
+
@value = @value.apply_sorts(sort.to_h) if sort.present? && @value.respond_to?(:apply_sorts)
|
105
|
+
|
106
|
+
@value
|
107
|
+
end
|
108
|
+
|
109
|
+
# Default resolver - meant to be overridden
|
110
|
+
def base_resolve(**)
|
81
111
|
object
|
82
112
|
end
|
83
113
|
end
|
@@ -86,7 +116,14 @@ module Graphiform
|
|
86
116
|
local_graphql_filter = graphql_filter
|
87
117
|
local_graphql_sort = graphql_sort
|
88
118
|
|
119
|
+
model = self
|
89
120
|
@base_resolver.class_eval do
|
121
|
+
unless respond_to?(:model)
|
122
|
+
define_method :model do
|
123
|
+
model
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
90
127
|
argument :where, local_graphql_filter, required: false
|
91
128
|
argument :sort, local_graphql_sort, required: false unless local_graphql_sort.arguments.empty?
|
92
129
|
end
|
@@ -97,16 +134,14 @@ module Graphiform
|
|
97
134
|
|
98
135
|
def graphql_query
|
99
136
|
Helpers.get_const_or_create(demodulized_name, ::Resolvers::Queries) do
|
100
|
-
model = self
|
101
137
|
local_graphql_type = graphql_type
|
102
138
|
Class.new(graphql_base_resolver) do
|
103
139
|
type local_graphql_type, null: false
|
104
140
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
val.first
|
141
|
+
def base_resolve(**args)
|
142
|
+
@value = model.all
|
143
|
+
apply_built_ins(**args)
|
144
|
+
@value.first
|
110
145
|
end
|
111
146
|
end
|
112
147
|
end
|
@@ -114,37 +149,29 @@ module Graphiform
|
|
114
149
|
|
115
150
|
def graphql_connection_query
|
116
151
|
Helpers.get_const_or_create(demodulized_name, ::Resolvers::ConnectionQueries) do
|
117
|
-
model = self
|
118
152
|
connection_type = graphql_connection
|
119
153
|
Class.new(graphql_base_resolver) do
|
120
154
|
type connection_type, null: false
|
121
155
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
val = val.apply_sorts(sort.to_h) if sort.present? && val.respond_to?(:apply_sorts)
|
126
|
-
|
127
|
-
val
|
156
|
+
def base_resolve(**args)
|
157
|
+
@value = model.all
|
158
|
+
apply_built_ins(**args)
|
128
159
|
end
|
129
160
|
end
|
130
161
|
end
|
131
162
|
end
|
132
163
|
|
133
|
-
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, **)
|
134
165
|
Class.new(graphql_base_resolver) do
|
135
166
|
type resolver_type, null: false
|
136
167
|
|
137
|
-
define_method :
|
138
|
-
|
139
|
-
|
140
|
-
val = super(**args)
|
141
|
-
|
142
|
-
val = val.public_send(method_name) if val.respond_to? method_name
|
143
|
-
val = instance_exec(val, context, &read_prepare) if read_prepare
|
168
|
+
define_method :base_resolve do |**args|
|
169
|
+
@value = object
|
144
170
|
|
145
|
-
|
171
|
+
@value = @value.public_send(method_name) if @value.respond_to?(method_name)
|
172
|
+
@value = instance_exec(@value, context, &read_prepare) if read_prepare
|
146
173
|
|
147
|
-
|
174
|
+
apply_built_ins(**args)
|
148
175
|
end
|
149
176
|
end
|
150
177
|
end
|
data/lib/graphiform/fields.rb
CHANGED
@@ -261,7 +261,7 @@ module Graphiform
|
|
261
261
|
graphql_add_field_to_type(field_name, type, null, read_prepare: read_prepare, **options)
|
262
262
|
end
|
263
263
|
|
264
|
-
def graphql_add_method_field(field_name, type
|
264
|
+
def graphql_add_method_field(field_name, type: nil, null: true, **options)
|
265
265
|
return Helpers.logger.warn "Graphiform: Missing `type` for field `#{field_name}` in model `#{name}`" if type.nil?
|
266
266
|
|
267
267
|
graphql_add_field_to_type(field_name, type, null, **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.4
|
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-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|