graphql-fancy_loader 0.1.2 → 0.1.3
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/.github/workflows/release.yml +2 -0
- data/Gemfile.lock +1 -5
- data/lib/graphql/fancy_connection.rb +78 -76
- data/lib/graphql/fancy_loader/version.rb +1 -1
- data/lib/graphql/fancy_loader.rb +11 -9
- data/lib/graphql/sort_direction.rb +5 -3
- 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: 355c1f577b63f6a1ba087b659a6a03c1b840e792d937aab00fa35203512d80a3
|
4
|
+
data.tar.gz: bda38b22ee80c9245546fea76a164e3e0267c3052b36a9fea5de057e1841885d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20dc1a4bceb155740f6276939406ba250044f3aa80bedd9498d75f2e78c90dd441d933281a7edf38efab2c0bd288b720ba3433602272f89e5fe85be422dcfc9c
|
7
|
+
data.tar.gz: c644d3f3fa1e9d09da107a3803721744ddb7a3e50eefb4c619d8aa807437c9dd8e164fd27cd0a54451eaeb23d4c62b7d024a62f7253b4cb54b5a823580795c3e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphql-fancy_loader (0.1.
|
4
|
+
graphql-fancy_loader (0.1.3)
|
5
5
|
activesupport (>= 5.0, < 7.0)
|
6
6
|
graphql (>= 1.3, < 2)
|
7
7
|
graphql-batch (>= 0.4.3, < 1)
|
@@ -116,10 +116,6 @@ GEM
|
|
116
116
|
nokogiri (1.12.5)
|
117
117
|
mini_portile2 (~> 2.6.1)
|
118
118
|
racc (~> 1.4)
|
119
|
-
nokogiri (1.12.5-x86_64-darwin)
|
120
|
-
racc (~> 1.4)
|
121
|
-
nokogiri (1.12.5-x86_64-linux)
|
122
|
-
racc (~> 1.4)
|
123
119
|
pg (1.2.3)
|
124
120
|
promise.rb (0.7.4)
|
125
121
|
pry (0.13.1)
|
@@ -1,103 +1,105 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module GraphQL
|
2
|
+
class FancyConnection < GraphQL::Pagination::RelationConnection
|
3
|
+
def initialize(loader, args, key, **super_args)
|
4
|
+
@loader = loader
|
5
|
+
@args = args
|
6
|
+
@key = key
|
7
|
+
@then = nil
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
super(nil, **super_args)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
# @return [Promise<Array<ApplicationRecord>>]
|
13
|
+
def nodes
|
14
|
+
if @then
|
15
|
+
base_nodes.then(@then)
|
16
|
+
else
|
17
|
+
base_nodes
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def edges
|
22
|
+
@edges ||= nodes.then do |nodes|
|
23
|
+
nodes.map { |n| @edge_class.new(n, self) }
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
# @return [Promise<Integer>]
|
28
|
+
def total_count
|
29
|
+
base_nodes.then do |results|
|
30
|
+
if results.first
|
31
|
+
results.first.attributes['total_count']
|
32
|
+
else
|
33
|
+
0
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
# @return [Promise<Boolean>]
|
39
|
+
def has_next_page # rubocop:disable Naming/PredicateName
|
40
|
+
base_nodes.then do |results|
|
41
|
+
if results.last
|
42
|
+
results.last.attributes['row_number'] < results.last.attributes['total_count']
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
# @return [Promise<Boolean>]
|
50
|
+
def has_previous_page # rubocop:disable Naming/PredicateName
|
51
|
+
base_nodes.then do |results|
|
52
|
+
if results.first
|
53
|
+
results.first.attributes['row_number'] > 1
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
|
-
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def start_cursor
|
61
|
+
base_nodes.then do |results|
|
62
|
+
cursor_for(results.first)
|
63
|
+
end
|
62
64
|
end
|
63
|
-
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
def end_cursor
|
67
|
+
base_nodes.then do |results|
|
68
|
+
cursor_for(results.last)
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def cursor_for(item)
|
73
|
+
item && encode(item.attributes['row_number'].to_s)
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
def then(&block)
|
77
|
+
@then = block
|
78
|
+
self
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
+
private
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
def base_nodes
|
84
|
+
@base_nodes ||= @loader.for(**loader_args).load(@key)
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
def after_offset
|
88
|
+
@after_offset ||= after && decode(after).to_i
|
89
|
+
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
def before_offset
|
92
|
+
@before_offset ||= before && decode(before).to_i
|
93
|
+
end
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
95
|
+
def loader_args
|
96
|
+
@args.merge(
|
97
|
+
before: before_offset,
|
98
|
+
after: after_offset,
|
99
|
+
first: first,
|
100
|
+
last: last,
|
101
|
+
context: context
|
102
|
+
)
|
103
|
+
end
|
102
104
|
end
|
103
105
|
end
|
data/lib/graphql/fancy_loader.rb
CHANGED
@@ -11,16 +11,7 @@ require 'active_support/concern'
|
|
11
11
|
require 'active_support/configurable'
|
12
12
|
require 'active_support/core_ext/class/attribute'
|
13
13
|
|
14
|
-
require 'graphql/sort_direction'
|
15
|
-
require 'graphql/fancy_connection'
|
16
|
-
# FancyLoader
|
17
14
|
require 'graphql/fancy_loader/dsl'
|
18
|
-
require 'graphql/fancy_loader/pagination_filter'
|
19
|
-
require 'graphql/fancy_loader/query_generator'
|
20
|
-
require 'graphql/fancy_loader/rank_query_generator'
|
21
|
-
require 'graphql/fancy_loader/type_generator'
|
22
|
-
# Middleware
|
23
|
-
require 'graphql/fancy_loader/pundit_middleware'
|
24
15
|
|
25
16
|
module GraphQL
|
26
17
|
class FancyLoader < GraphQL::Batch::Loader
|
@@ -101,3 +92,14 @@ module GraphQL
|
|
101
92
|
end
|
102
93
|
end
|
103
94
|
end
|
95
|
+
|
96
|
+
require 'graphql/sort_direction'
|
97
|
+
require 'graphql/fancy_connection'
|
98
|
+
# FancyLoader
|
99
|
+
require 'graphql/fancy_loader/pagination_filter'
|
100
|
+
require 'graphql/fancy_loader/query_generator'
|
101
|
+
require 'graphql/fancy_loader/rank_query_generator'
|
102
|
+
require 'graphql/fancy_loader/type_generator'
|
103
|
+
require 'graphql/fancy_loader/version'
|
104
|
+
# Middleware
|
105
|
+
require 'graphql/fancy_loader/pundit_middleware'
|