graphql-relay 0.9.0 → 0.9.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee15c8ecfc7211458db3f5c9ea677f58e0a836a0
|
4
|
+
data.tar.gz: 408c83f5849052f11bf89fa8eb16e7228dd7dcd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc02c0272c909596c5c05816f2881b2e619d01a35a08e4efaa8f75b685fe225d9581f573c96d8fc2f7365679801770999b7e8607c861b2a776144e99c1a0bd1
|
7
|
+
data.tar.gz: 314b20cbbc0ce9fb73b5ffcdc63a6a0662cdfac9d057f6393bb98dc7135290d100a4a66fd7a14817709b38b3a9d65f30577ce6e090ac537a4b7822f08f02e9e9
|
@@ -12,7 +12,12 @@ module GraphQL
|
|
12
12
|
def paged_nodes
|
13
13
|
@paged_nodes = begin
|
14
14
|
items = sliced_nodes
|
15
|
-
|
15
|
+
|
16
|
+
if limit
|
17
|
+
items.first(limit)
|
18
|
+
else
|
19
|
+
items
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
@@ -37,25 +42,27 @@ module GraphQL
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def previous_offset
|
40
|
-
@
|
41
|
-
index_from_cursor(before) - last - 1
|
42
|
-
elsif after
|
45
|
+
@previous_offset ||= if after
|
43
46
|
index_from_cursor(after)
|
47
|
+
elsif before
|
48
|
+
index_from_cursor(before) - (last ? last : 0) - 1
|
44
49
|
else
|
45
50
|
0
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
54
|
def limit
|
50
|
-
@limit ||=
|
51
|
-
|
52
|
-
|
53
|
-
last_limit = if previous_offset <= 0
|
54
|
-
previous_offset + last
|
55
|
+
@limit ||= begin
|
56
|
+
limit_from_arguments = if first
|
57
|
+
first
|
55
58
|
else
|
56
|
-
|
59
|
+
if previous_offset < 0
|
60
|
+
previous_offset + (last ? last : 0)
|
61
|
+
else
|
62
|
+
last
|
63
|
+
end
|
57
64
|
end
|
58
|
-
[
|
65
|
+
[limit_from_arguments, max_page_size].compact.min
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|
@@ -7,12 +7,12 @@ module GraphQL
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_next_page
|
10
|
-
|
10
|
+
exceeds_limit?(first)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Used by `pageInfo`
|
14
14
|
def has_previous_page
|
15
|
-
|
15
|
+
exceeds_limit?(last)
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -53,28 +53,40 @@ module GraphQL
|
|
53
53
|
@previous_offset ||= if after
|
54
54
|
offset_from_cursor(after)
|
55
55
|
elsif before
|
56
|
-
offset_from_cursor(before) - last - 1
|
56
|
+
offset_from_cursor(before) - (last ? last : 0) - 1
|
57
57
|
else
|
58
58
|
0
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# Limit to apply to this query:
|
63
|
+
# - find a value from the query
|
64
|
+
# - don't exceed max_page_size
|
65
|
+
# - otherwise, don't limit
|
62
66
|
def limit
|
63
|
-
@limit ||=
|
64
|
-
|
65
|
-
|
66
|
-
last_limit = if previous_offset <= 0
|
67
|
-
previous_offset + last
|
67
|
+
@limit ||= begin
|
68
|
+
limit_from_arguments = if first
|
69
|
+
first
|
68
70
|
else
|
69
|
-
|
71
|
+
if previous_offset < 0
|
72
|
+
previous_offset + (last ? last : 0)
|
73
|
+
else
|
74
|
+
last
|
75
|
+
end
|
70
76
|
end
|
71
|
-
[
|
77
|
+
[limit_from_arguments, max_page_size].compact.min
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
75
81
|
def paged_nodes_array
|
76
82
|
@paged_nodes_array ||= paged_nodes.to_a
|
77
83
|
end
|
84
|
+
|
85
|
+
# Returns true if the limit is specified
|
86
|
+
# and there are more items that follow
|
87
|
+
def exceeds_limit?(limit_value)
|
88
|
+
!!(limit_value && sliced_nodes.limit(limit_value + 1).count > limit_value)
|
89
|
+
end
|
78
90
|
end
|
79
91
|
|
80
92
|
|
@@ -77,5 +77,12 @@ describe GraphQL::Relay::ArrayConnection do
|
|
77
77
|
names = get_names(result)
|
78
78
|
assert_equal(1, names.length)
|
79
79
|
end
|
80
|
+
|
81
|
+
it 'works without first/last/after/before' do
|
82
|
+
result = query(query_string)
|
83
|
+
|
84
|
+
assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"])
|
85
|
+
assert_equal(5, result["data"]["rebels"]["ships"]["edges"].length)
|
86
|
+
end
|
80
87
|
end
|
81
88
|
end
|
@@ -27,6 +27,9 @@ describe GraphQL::Relay::RelationConnection do
|
|
27
27
|
node {
|
28
28
|
name
|
29
29
|
}
|
30
|
+
},
|
31
|
+
pageInfo {
|
32
|
+
hasNextPage
|
30
33
|
}
|
31
34
|
}
|
32
35
|
|}
|
@@ -84,6 +87,12 @@ describe GraphQL::Relay::RelationConnection do
|
|
84
87
|
assert_equal(["Death Star"], get_names(result))
|
85
88
|
end
|
86
89
|
|
90
|
+
it 'works without first/last/after/before' do
|
91
|
+
result = query(query_string)
|
92
|
+
|
93
|
+
assert_equal(3, result["data"]["empire"]["bases"]["edges"].length)
|
94
|
+
end
|
95
|
+
|
87
96
|
it "applies the maximum limit for relation connection types" do
|
88
97
|
limit_query_string = %|
|
89
98
|
query getShips($first: Int){
|
@@ -120,6 +129,9 @@ describe GraphQL::Relay::RelationConnection do
|
|
120
129
|
|
121
130
|
result = query(limit_query_string, "first" => 3)
|
122
131
|
assert_equal(2, result["data"]["empire"]["basesWithMaxLimitArray"]["edges"].size)
|
132
|
+
|
133
|
+
result = query(limit_query_string)
|
134
|
+
assert_equal(2, result["data"]["empire"]["basesWithMaxLimitArray"]["edges"].size, "it works without arguments")
|
123
135
|
end
|
124
136
|
end
|
125
137
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-relay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|