graphiti 1.2.42 → 1.2.43
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/graphiti/adapters/abstract.rb +3 -2
- data/lib/graphiti/adapters/active_record.rb +5 -2
- data/lib/graphiti/adapters/null.rb +1 -1
- data/lib/graphiti/delegates/pagination.rb +20 -8
- data/lib/graphiti/query.rb +4 -4
- data/lib/graphiti/scoping/filter.rb +12 -8
- data/lib/graphiti/scoping/paginate.rb +20 -2
- 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: 6020ab7e3340dafb7ddad630e79456d6e50b581aaa3cd455069ad5a25860fbb5
|
4
|
+
data.tar.gz: da8286216aab03780ec61427289aa6fecfb82c6dc2ff374de5cbb4bd223ddbcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6dc240dbad87f9900412ac9afdfa32a20963e79827fcdb4bba94c2f7cac159057e80410f797da42b243dbca14d3753a60a6bfb7df404b16b01d8bad2c3c1d6
|
7
|
+
data.tar.gz: f12629255a14d042b311101110a47fbfe4a099a618e40c2af020f33b08d50bf00741d7f78c81cea0031748828774871d0d954be79a7f6c681a33bae33729f166
|
@@ -244,14 +244,15 @@ module Graphiti
|
|
244
244
|
# @param scope The scope object we are chaining
|
245
245
|
# @param [Integer] current_page The current page number
|
246
246
|
# @param [Integer] per_page The number of results per page
|
247
|
+
# @param [Integer] offset The offset to start from
|
247
248
|
# @return the scope
|
248
249
|
#
|
249
250
|
# @example ActiveRecord default
|
250
251
|
# # via kaminari gem
|
251
|
-
# def paginate(scope, current_page, per_page)
|
252
|
+
# def paginate(scope, current_page, per_page, offset)
|
252
253
|
# scope.page(current_page).per(per_page)
|
253
254
|
# end
|
254
|
-
def paginate(scope, current_page, per_page)
|
255
|
+
def paginate(scope, current_page, per_page, offset)
|
255
256
|
raise "you must override #paginate in an adapter subclass"
|
256
257
|
end
|
257
258
|
|
@@ -184,8 +184,11 @@ module Graphiti
|
|
184
184
|
end
|
185
185
|
|
186
186
|
# (see Adapters::Abstract#paginate)
|
187
|
-
def paginate(scope, current_page, per_page)
|
188
|
-
scope.page(current_page)
|
187
|
+
def paginate(scope, current_page, per_page, offset)
|
188
|
+
scope = scope.page(current_page) if current_page
|
189
|
+
scope = scope.per(per_page) if per_page
|
190
|
+
scope = scope.padding(offset) if offset
|
191
|
+
scope
|
189
192
|
end
|
190
193
|
|
191
194
|
# (see Adapters::Abstract#count)
|
@@ -30,13 +30,14 @@ module Graphiti
|
|
30
30
|
|
31
31
|
uri = URI(@proxy.resource.endpoint[:url].to_s)
|
32
32
|
|
33
|
+
page_params = {
|
34
|
+
number: page,
|
35
|
+
size: page_size
|
36
|
+
}
|
37
|
+
page_params[:offset] = offset if offset
|
38
|
+
|
33
39
|
# Overwrite the pagination query params with the desired page
|
34
|
-
uri.query = pagination_params.merge(
|
35
|
-
page: {
|
36
|
-
number: page,
|
37
|
-
size: page_size
|
38
|
-
}
|
39
|
-
}).to_query
|
40
|
+
uri.query = pagination_params.merge(page: page_params).to_query
|
40
41
|
uri.to_s
|
41
42
|
end
|
42
43
|
|
@@ -46,8 +47,11 @@ module Graphiti
|
|
46
47
|
elsif page_size == 0 || item_count == 0
|
47
48
|
return nil
|
48
49
|
end
|
49
|
-
|
50
|
-
|
50
|
+
|
51
|
+
count = item_count
|
52
|
+
count = item_count - offset if offset
|
53
|
+
@last_page = (count / page_size)
|
54
|
+
@last_page += 1 if count % page_size > 0
|
51
55
|
@last_page
|
52
56
|
end
|
53
57
|
|
@@ -82,6 +86,14 @@ module Graphiti
|
|
82
86
|
@current_page ||= (page_param[:number] || 1).to_i
|
83
87
|
end
|
84
88
|
|
89
|
+
def offset
|
90
|
+
@offset ||= begin
|
91
|
+
if (value = page_param[:offset])
|
92
|
+
value.to_i
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
85
97
|
def page_size
|
86
98
|
@page_size ||= (page_param[:size] ||
|
87
99
|
@proxy.resource.default_page_size ||
|
data/lib/graphiti/query.rb
CHANGED
@@ -32,10 +32,10 @@ module Graphiti
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def pagination_links?
|
35
|
-
if
|
36
|
-
[true, "true"].include?(@params[:pagination_links])
|
37
|
-
elsif action == :find
|
35
|
+
if action == :find
|
38
36
|
false
|
37
|
+
elsif Graphiti.config.pagination_links_on_demand
|
38
|
+
[true, "true"].include?(@params[:pagination_links])
|
39
39
|
else
|
40
40
|
Graphiti.config.pagination_links
|
41
41
|
end
|
@@ -195,7 +195,7 @@ module Graphiti
|
|
195
195
|
end
|
196
196
|
elsif nested?(name)
|
197
197
|
hash[name.to_s.split(".").last.to_sym] = value
|
198
|
-
elsif top_level? && [:number, :size].include?(name.to_sym)
|
198
|
+
elsif top_level? && [:number, :size, :offset].include?(name.to_sym)
|
199
199
|
hash[name.to_sym] = value.to_i
|
200
200
|
end
|
201
201
|
end
|
@@ -171,14 +171,18 @@ module Graphiti
|
|
171
171
|
type = Graphiti::Types[filter[:type]]
|
172
172
|
array_or_string = [:string, :array].include?(type[:canonical_name])
|
173
173
|
if (arr = value.scan(/\[.*?\]/)).present? && array_or_string
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
174
|
+
begin
|
175
|
+
value = arr.map { |json|
|
176
|
+
begin
|
177
|
+
JSON.parse(json)
|
178
|
+
rescue
|
179
|
+
raise Errors::InvalidJSONArray.new(resource, value)
|
180
|
+
end
|
181
|
+
}
|
182
|
+
value = value[0] if value.length == 1
|
183
|
+
rescue Errors::InvalidJSONArray => e
|
184
|
+
raise(e) if type[:canonical_name] == :array
|
185
|
+
end
|
182
186
|
else
|
183
187
|
value = parse_string_arrays(value, !!filter[:single])
|
184
188
|
end
|
@@ -33,12 +33,24 @@ module Graphiti
|
|
33
33
|
|
34
34
|
# Apply default pagination proc via the Resource adapter
|
35
35
|
def apply_standard_scope
|
36
|
-
resource.adapter.paginate
|
36
|
+
arity = resource.adapter.method(:paginate)
|
37
|
+
|
38
|
+
if arity == 4 # backwards-compat
|
39
|
+
resource.adapter.paginate(@scope, number, size)
|
40
|
+
else
|
41
|
+
resource.adapter.paginate(@scope, number, size, offset)
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
# Apply the custom pagination proc
|
40
46
|
def apply_custom_scope
|
41
|
-
resource.instance_exec
|
47
|
+
resource.instance_exec \
|
48
|
+
@scope,
|
49
|
+
number,
|
50
|
+
size,
|
51
|
+
resource.context,
|
52
|
+
offset,
|
53
|
+
&custom_scope
|
42
54
|
end
|
43
55
|
|
44
56
|
private
|
@@ -51,6 +63,12 @@ module Graphiti
|
|
51
63
|
@page_param ||= (query_hash[:page] || {})
|
52
64
|
end
|
53
65
|
|
66
|
+
def offset
|
67
|
+
if (value = page_param[:offset])
|
68
|
+
value.to_i
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
54
72
|
def number
|
55
73
|
(page_param[:number] || 1).to_i
|
56
74
|
end
|
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.43
|
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-
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|