hq-graphql 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hq/graphql/resource.rb +14 -3
- data/lib/hq/graphql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbe2582301bf466529f9b30a2afde7e13df59702a15a0119c2a9dbb87753d631
|
4
|
+
data.tar.gz: 8054919523ba2b197092b30c32bda946310e07bca0133aad0a91b27391fe53bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7996cc965c630d3625416f06f03c4188c0a853b66c32414eb8885a4d2728eee17de57fb4608a6b9d8359ac614220654709d9862eeccc66ebc3d63f01928e1e38
|
7
|
+
data.tar.gz: 1183dd46cafa0683e4caa6d99584f0681d75c5d7e07f74a263fc2fcd894c924f08d40f7e85c6555f6dbd71fc7e0abfaebe9ede2ebefe18daecf9fbb9f4d497c1
|
data/lib/hq/graphql/resource.rb
CHANGED
@@ -231,7 +231,7 @@ module HQ
|
|
231
231
|
}
|
232
232
|
end
|
233
233
|
|
234
|
-
def root_query(find_one: true, find_all: true)
|
234
|
+
def root_query(find_one: true, find_all: true, pagination: false, per_page_max: 250)
|
235
235
|
field_name = graphql_name.underscore
|
236
236
|
scoped_self = self
|
237
237
|
|
@@ -250,8 +250,19 @@ module HQ
|
|
250
250
|
|
251
251
|
if find_all
|
252
252
|
def_root field_name.pluralize, is_array: true, null: false do
|
253
|
-
|
254
|
-
|
253
|
+
argument :page, Integer, required: false
|
254
|
+
argument :per_page, Integer, required: false
|
255
|
+
|
256
|
+
define_method(:resolve) do |page: nil, per_page: nil, **_attrs|
|
257
|
+
scope = scoped_self.scope(context).all
|
258
|
+
|
259
|
+
if pagination || page || per_page
|
260
|
+
page ||= 0
|
261
|
+
limit = [per_page_max, *per_page].min
|
262
|
+
scope = scope.limit(limit).offset(page * limit)
|
263
|
+
end
|
264
|
+
|
265
|
+
scope
|
255
266
|
end
|
256
267
|
end
|
257
268
|
end
|
data/lib/hq/graphql/version.rb
CHANGED