graphql-pagination 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/graphql-pagination.gemspec +34 -0
- data/lib/graphql-pagination.rb +1 -0
- data/lib/graphql_pagination.rb +12 -0
- data/lib/graphql_pagination/collection_metadata_type.rb +8 -0
- data/lib/graphql_pagination/collection_type.rb +24 -0
- data/lib/graphql_pagination/version.rb +3 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76c66de0736b4e48b3e0663e492753f1357bf8be61808b217fd630bea22009b1
|
4
|
+
data.tar.gz: f8f12c2b80a9f467511aa5d7fd34e34a46ff7fb3163de22f2b6ba409921f1ace
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95cad2fa47598627792741d8172eaa1e0bfabbfc4ca4354d656d416449a79c054b8ec3c8cf27db9e02f63ff72a8c13ed2ffd377191f5b3e0ad9c43e30ff47f6d
|
7
|
+
data.tar.gz: 2ca30fea914bc2a633733f252407d8bc6bf560fc8b7009db30cdab953b43ce366686327353fb8a0cf719ff97299bead0e0c6039e1a1964ad54f3120e4895a0b6
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
graphql-pagination
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
graphql-pagination (0.1.0)
|
5
|
+
graphql
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.2.3)
|
11
|
+
activesupport (= 5.2.3)
|
12
|
+
activerecord (5.2.3)
|
13
|
+
activemodel (= 5.2.3)
|
14
|
+
activesupport (= 5.2.3)
|
15
|
+
arel (>= 9.0)
|
16
|
+
activesupport (5.2.3)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
arel (9.0.0)
|
22
|
+
coderay (1.1.2)
|
23
|
+
concurrent-ruby (1.1.5)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
graphql (1.9.4)
|
26
|
+
i18n (1.6.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
kaminari-activerecord (1.1.1)
|
29
|
+
activerecord
|
30
|
+
kaminari-core (= 1.1.1)
|
31
|
+
kaminari-core (1.1.1)
|
32
|
+
method_source (0.9.2)
|
33
|
+
minitest (5.11.3)
|
34
|
+
pry (0.12.2)
|
35
|
+
coderay (~> 1.1.0)
|
36
|
+
method_source (~> 0.9.0)
|
37
|
+
rake (12.3.2)
|
38
|
+
rspec (3.8.0)
|
39
|
+
rspec-core (~> 3.8.0)
|
40
|
+
rspec-expectations (~> 3.8.0)
|
41
|
+
rspec-mocks (~> 3.8.0)
|
42
|
+
rspec-core (3.8.0)
|
43
|
+
rspec-support (~> 3.8.0)
|
44
|
+
rspec-expectations (3.8.3)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-mocks (3.8.0)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-support (3.8.0)
|
51
|
+
thread_safe (0.3.6)
|
52
|
+
tzinfo (1.2.5)
|
53
|
+
thread_safe (~> 0.1)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
bundler
|
60
|
+
graphql-pagination!
|
61
|
+
kaminari-activerecord
|
62
|
+
kaminari-core
|
63
|
+
pry
|
64
|
+
rake
|
65
|
+
rspec
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.0.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 RenoFi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# graphql-pagination
|
2
|
+
|
3
|
+
Implements page-based pagination returning collection and pagination metadata. It works with `kaminari` or other pagination tools implementing similar methods.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add `graphql-pagination` to your Gemfile, you can use `kaminari-activerecord` or `kaminari-monogid` to not implement page scope methods. Kaminari is not loaded by the gem, so you need to decide anmd load it on your own.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'graphql-pagination'
|
11
|
+
gem 'kaminari-activerecord'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage example
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
field :fruits, Types::FruitType.collection_type, null: true do
|
18
|
+
argument :page, Integer, required: false
|
19
|
+
argument :limit, Integer, required: false
|
20
|
+
end
|
21
|
+
|
22
|
+
def fruit(page: nil, limit: nil)
|
23
|
+
::Fruit.page(page).per(limit)
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Value returned by query resolver must be a kaminari object or implements its page scope methods (`current_page`, `limit_value`, `total_count`, `total_pages`).
|
28
|
+
|
29
|
+
|
30
|
+
## GraphQL query
|
31
|
+
|
32
|
+
```
|
33
|
+
{
|
34
|
+
fruits(page: 2, limit: 2) {
|
35
|
+
collection {
|
36
|
+
id
|
37
|
+
name
|
38
|
+
}
|
39
|
+
metadata {
|
40
|
+
totalPages
|
41
|
+
totalCount
|
42
|
+
currentPage
|
43
|
+
limitValue
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
```json
|
50
|
+
{
|
51
|
+
"data": {
|
52
|
+
"checklists": {
|
53
|
+
"collection": [
|
54
|
+
{
|
55
|
+
"id": "93938bb3-7a6c-4d35-9961-cbb2d4c9e9ac",
|
56
|
+
"name": "Apple"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"id": "b1ee93b2-579a-4107-8454-119bba5afb63",
|
60
|
+
"name": "Mango"
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"metadata": {
|
64
|
+
"totalPages": 25,
|
65
|
+
"totalCount": 50,
|
66
|
+
"currentPage": 2,
|
67
|
+
"limitValue": 2
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/renofi/graphql-pagination. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
81
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "graphql_pagination/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "graphql-pagination"
|
7
|
+
spec.version = GraphqlPagination::VERSION
|
8
|
+
spec.authors = ["Krzysztof Knapik", "RenoFi Engineering Team"]
|
9
|
+
spec.email = ["knapo@knapo.net", "engineering@renofi.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Page-based kaminari pagination for graphql.}
|
12
|
+
spec.description = %q{Implements page-based pagination for graphql returning collection and pagination metadata.}
|
13
|
+
spec.homepage = "https://github.com/RenoFi/graphql-pagination"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = "https://github.com/RenoFi/graphql-pagination"
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/RenoFi/graphql-pagination"
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "graphql"
|
27
|
+
|
28
|
+
spec.add_development_dependency "kaminari-core"
|
29
|
+
spec.add_development_dependency "kaminari-activerecord"
|
30
|
+
spec.add_development_dependency "bundler"
|
31
|
+
spec.add_development_dependency "rake"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "pry"
|
34
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'graphql_pagination'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "graphql_pagination/version"
|
2
|
+
require "graphql"
|
3
|
+
require "graphql/schema/object"
|
4
|
+
|
5
|
+
module GraphqlPagination
|
6
|
+
end
|
7
|
+
|
8
|
+
require "graphql_pagination/version"
|
9
|
+
require "graphql_pagination/collection_type"
|
10
|
+
require "graphql_pagination/collection_metadata_type"
|
11
|
+
|
12
|
+
GraphQL::Schema::Object.extend GraphqlPagination::CollectionType
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module GraphqlPagination
|
2
|
+
class CollectionMetadataType < GraphQL::Schema::Object
|
3
|
+
field :current_page, Integer, null: false
|
4
|
+
field :limit_value, Integer, null: false
|
5
|
+
field :total_count, Integer, null: false
|
6
|
+
field :total_pages, Integer, null: false
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GraphqlPagination
|
2
|
+
module CollectionType
|
3
|
+
def collection_type
|
4
|
+
@collection_type ||= begin
|
5
|
+
type_name = "#{graphql_name}Collection"
|
6
|
+
source_type = self
|
7
|
+
|
8
|
+
Class.new(GraphQL::Schema::Object) do
|
9
|
+
graphql_name type_name
|
10
|
+
field :collection, [source_type], null: false
|
11
|
+
field :metadata, GraphqlPagination::CollectionMetadataType, null: false
|
12
|
+
|
13
|
+
def collection
|
14
|
+
object
|
15
|
+
end
|
16
|
+
|
17
|
+
def metadata
|
18
|
+
object
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphql-pagination
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztof Knapik
|
8
|
+
- RenoFi Engineering Team
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: graphql
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: kaminari-core
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: kaminari-activerecord
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: pry
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: Implements page-based pagination for graphql returning collection and
|
113
|
+
pagination metadata.
|
114
|
+
email:
|
115
|
+
- knapo@knapo.net
|
116
|
+
- engineering@renofi.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".ruby-gemset"
|
124
|
+
- ".ruby-version"
|
125
|
+
- ".travis.yml"
|
126
|
+
- Gemfile
|
127
|
+
- Gemfile.lock
|
128
|
+
- LICENSE
|
129
|
+
- README.md
|
130
|
+
- Rakefile
|
131
|
+
- bin/console
|
132
|
+
- bin/setup
|
133
|
+
- graphql-pagination.gemspec
|
134
|
+
- lib/graphql-pagination.rb
|
135
|
+
- lib/graphql_pagination.rb
|
136
|
+
- lib/graphql_pagination/collection_metadata_type.rb
|
137
|
+
- lib/graphql_pagination/collection_type.rb
|
138
|
+
- lib/graphql_pagination/version.rb
|
139
|
+
homepage: https://github.com/RenoFi/graphql-pagination
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata:
|
143
|
+
homepage_uri: https://github.com/RenoFi/graphql-pagination
|
144
|
+
source_code_uri: https://github.com/RenoFi/graphql-pagination
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubygems_version: 3.0.3
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Page-based kaminari pagination for graphql.
|
164
|
+
test_files: []
|