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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2877f7a77b6c2c63a91fe28cf21b64e99ebd92d6ec8e68c13acf3ed18911edb
4
- data.tar.gz: 97781e7d915f98154c4f3252a7b244afbffd2d5a7920ff4c77d54b6e4409976f
3
+ metadata.gz: bbe2582301bf466529f9b30a2afde7e13df59702a15a0119c2a9dbb87753d631
4
+ data.tar.gz: 8054919523ba2b197092b30c32bda946310e07bca0133aad0a91b27391fe53bb
5
5
  SHA512:
6
- metadata.gz: 92120bf166668fd9e76cc0c42f0fc350ac7be0eacc9653f14f22b4a6c792910f9d3fbaf15ae0cfdbb596b6732c1dddbdaba24188e53d9a41cbae6cd2250b3659
7
- data.tar.gz: 2ec3a9597f0059ec4c988534c355171489c958a43a1287f617d5056e33847bc9af67ea2572a93d3dd3d6b531443770218e543e3e2acc9131305d07217010f562
6
+ metadata.gz: 7996cc965c630d3625416f06f03c4188c0a853b66c32414eb8885a4d2728eee17de57fb4608a6b9d8359ac614220654709d9862eeccc66ebc3d63f01928e1e38
7
+ data.tar.gz: 1183dd46cafa0683e4caa6d99584f0681d75c5d7e07f74a263fc2fcd894c924f08d40f7e85c6555f6dbd71fc7e0abfaebe9ede2ebefe18daecf9fbb9f4d497c1
@@ -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
- define_method(:resolve) do |**_attrs|
254
- scoped_self.scope(context).all
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
@@ -3,6 +3,6 @@
3
3
 
4
4
  module HQ
5
5
  module GraphQL
6
- VERSION = "2.0.4"
6
+ VERSION = "2.0.5"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Jones