graphiti 1.2.35 → 1.2.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphiti/hash_renderer.rb +51 -19
- data/lib/graphiti/schema.rb +18 -1
- data/lib/graphiti/schema_diff.rb +38 -0
- data/lib/graphiti/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: 2b7630aef39d3ce4584f53710a5cbe8617addc0a0ea042077c41562accb1c5cf
|
4
|
+
data.tar.gz: aad06cd10d1f2604432303990cf92d7b885333d15ccd733a5d0bbab062346872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063c97d7d4c719c1cbff7a8028b54a0d862e763bda69a8bae12cbe4a2d5201183b6d516936e9339faf3d35307a1375cf28859253e5fd3c6d1b5824b306fe0d2a
|
7
|
+
data.tar.gz: 07dc6893d86bbdfbe676b15707edae40601159d1bb7239b58004280e3c9e5d29c313a9bcc525a2fe7e9582f6191972b8095c0d4a5873a72f15cb5589c9879841
|
@@ -74,19 +74,22 @@ module Graphiti
|
|
74
74
|
name_chain << k unless name_chain.last == k
|
75
75
|
|
76
76
|
unless remote_resource? && serializers.nil?
|
77
|
-
|
78
|
-
serializers.map
|
77
|
+
payload = if serializers.is_a?(Array)
|
78
|
+
data = serializers.map { |rr|
|
79
79
|
rr.to_hash(fields: fields, include: nested_include, graphql: graphql, name_chain: name_chain)
|
80
|
-
|
80
|
+
}
|
81
|
+
graphql ? {nodes: data} : data
|
81
82
|
elsif serializers.nil?
|
82
83
|
if @resource.class.respond_to?(:sideload)
|
83
84
|
if @resource.class.sideload(k).type.to_s.include?("_many")
|
84
|
-
[]
|
85
|
+
graphql ? {nodes: []} : []
|
85
86
|
end
|
86
87
|
end
|
87
88
|
else
|
88
89
|
serializers.to_hash(fields: fields, include: nested_include, graphql: graphql, name_chain: name_chain)
|
89
90
|
end
|
91
|
+
|
92
|
+
attrs[name.to_sym] = payload
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
@@ -133,29 +136,58 @@ module Graphiti
|
|
133
136
|
serializers = options[:data]
|
134
137
|
opts = options.slice(:fields, :include)
|
135
138
|
opts[:graphql] = @graphql
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
+
top_level_key = get_top_level_key(@resource, serializers.is_a?(Array))
|
140
|
+
|
141
|
+
hash = {top_level_key => {}}
|
142
|
+
nodes = get_nodes(serializers, opts)
|
143
|
+
add_nodes(hash, top_level_key, options, nodes, @graphql)
|
144
|
+
add_stats(hash, top_level_key, options, @graphql)
|
145
|
+
hash
|
139
146
|
end
|
140
147
|
|
141
148
|
private
|
142
149
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
def get_top_level_key(resource, is_many)
|
151
|
+
key = :data
|
152
|
+
|
153
|
+
if @graphql
|
154
|
+
key = @resource.graphql_entrypoint
|
155
|
+
key = key.to_s.singularize.to_sym unless is_many
|
156
|
+
end
|
157
|
+
|
158
|
+
key
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_nodes(serializers, opts)
|
162
|
+
if serializers.is_a?(Array)
|
163
|
+
serializers.map do |s|
|
164
|
+
s.to_hash(**opts)
|
151
165
|
end
|
166
|
+
else
|
167
|
+
serializers.to_hash(**opts)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def add_nodes(hash, top_level_key, opts, nodes, graphql)
|
172
|
+
payload = nodes
|
173
|
+
if graphql && nodes.is_a?(Array)
|
174
|
+
payload = {nodes: nodes}
|
175
|
+
end
|
152
176
|
|
153
|
-
|
154
|
-
|
155
|
-
|
177
|
+
# Don't render nodes if we only requested stats
|
178
|
+
unless graphql && opts[:fields].values == [[:stats]]
|
179
|
+
hash[top_level_key] = payload
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def add_stats(hash, top_level_key, options, graphql)
|
184
|
+
if options[:meta] && !options[:meta].empty?
|
185
|
+
if @graphql
|
186
|
+
if (stats = options[:meta][:stats])
|
187
|
+
hash[top_level_key][:stats] = stats
|
156
188
|
end
|
157
189
|
else
|
158
|
-
|
190
|
+
hash.merge!(options.slice(:meta))
|
159
191
|
end
|
160
192
|
end
|
161
193
|
end
|
data/lib/graphiti/schema.rb
CHANGED
@@ -96,9 +96,14 @@ module Graphiti
|
|
96
96
|
extra_attributes: extra_attributes(r),
|
97
97
|
sorts: sorts(r),
|
98
98
|
filters: filters(r),
|
99
|
-
relationships: relationships(r)
|
99
|
+
relationships: relationships(r),
|
100
|
+
stats: stats(r)
|
100
101
|
}
|
101
102
|
|
103
|
+
if r.grouped_filters.any?
|
104
|
+
config[:filter_group] = r.grouped_filters
|
105
|
+
end
|
106
|
+
|
102
107
|
if r.default_sort
|
103
108
|
default_sort = r.default_sort.map { |s|
|
104
109
|
{s.keys.first.to_s => s.values.first.to_s}
|
@@ -165,6 +170,14 @@ module Graphiti
|
|
165
170
|
end
|
166
171
|
end
|
167
172
|
|
173
|
+
def stats(resource)
|
174
|
+
{}.tap do |stats|
|
175
|
+
resource.stats.each_pair do |name, config|
|
176
|
+
stats[name] = config.calculations.keys
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
168
181
|
def sorts(resource)
|
169
182
|
{}.tap do |s|
|
170
183
|
resource.sorts.each_pair do |name, sort|
|
@@ -212,6 +225,10 @@ module Graphiti
|
|
212
225
|
end
|
213
226
|
end
|
214
227
|
|
228
|
+
def filter_group(resource)
|
229
|
+
resource.config[:grouped_filters]
|
230
|
+
end
|
231
|
+
|
215
232
|
def relationships(resource)
|
216
233
|
{}.tap do |r|
|
217
234
|
resource.sideloads.each_pair do |name, config|
|
data/lib/graphiti/schema_diff.rb
CHANGED
@@ -30,6 +30,8 @@ module Graphiti
|
|
30
30
|
compare_extra_attributes(r, new_resource)
|
31
31
|
compare_sorts(r, new_resource)
|
32
32
|
compare_filters(r, new_resource)
|
33
|
+
compare_filter_group(r, new_resource)
|
34
|
+
compare_stats(r, new_resource)
|
33
35
|
compare_relationships(r, new_resource)
|
34
36
|
end
|
35
37
|
end
|
@@ -204,6 +206,42 @@ module Graphiti
|
|
204
206
|
end
|
205
207
|
end
|
206
208
|
|
209
|
+
def compare_filter_group(old_resource, new_resource)
|
210
|
+
if new_resource[:filter_group]
|
211
|
+
if old_resource[:filter_group]
|
212
|
+
new_names = new_resource[:filter_group][:names]
|
213
|
+
old_names = old_resource[:filter_group][:names]
|
214
|
+
diff = new_names - old_names
|
215
|
+
if !diff.empty? && new_resource[:filter_group][:required] == :all
|
216
|
+
@errors << "#{old_resource[:name]}: all required filter group #{old_names.inspect} added #{"member".pluralize(diff.length)} #{diff.inspect}."
|
217
|
+
end
|
218
|
+
|
219
|
+
old_required = old_resource[:filter_group][:required]
|
220
|
+
new_required = new_resource[:filter_group][:required]
|
221
|
+
if old_required == :any && new_required == :all
|
222
|
+
@errors << "#{old_resource[:name]}: filter group #{old_names.inspect} moved from required: :any to required: :all"
|
223
|
+
end
|
224
|
+
else
|
225
|
+
@errors << "#{old_resource[:name]}: filter group #{new_resource[:filter_group][:names].inspect} was added."
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def compare_stats(old_resource, new_resource)
|
231
|
+
old_resource[:stats].each_pair do |name, old_calculations|
|
232
|
+
new_calculations = new_resource[:stats][name]
|
233
|
+
if new_calculations
|
234
|
+
old_calculations.each do |calc|
|
235
|
+
unless new_calculations.include?(calc)
|
236
|
+
@errors << "#{old_resource[:name]}: calculation #{calc.inspect} was removed from stat #{name.inspect}."
|
237
|
+
end
|
238
|
+
end
|
239
|
+
else
|
240
|
+
@errors << "#{old_resource[:name]}: stat #{name.inspect} was removed."
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
207
245
|
def compare_endpoints
|
208
246
|
@old[:endpoints].each_pair do |path, old_endpoint|
|
209
247
|
unless (new_endpoint = @new[:endpoints][path])
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|