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: 5fb50f9e3030be285c1be81b0f0e302919a49c2f
4
- data.tar.gz: fd869d0de9f2f47085c12e94c093a0ca791ee004
3
+ metadata.gz: ee15c8ecfc7211458db3f5c9ea677f58e0a836a0
4
+ data.tar.gz: 408c83f5849052f11bf89fa8eb16e7228dd7dcd8
5
5
  SHA512:
6
- metadata.gz: 68734a2849039b20d4fcfe57855217247aebbf47c3252a22b96993e26880f0f4b739f41c75c203ce32fcf4e5e15d7b0c0a2b3f2f447ae838a21f6abfaf6617f2
7
- data.tar.gz: c76dd82ddc3eef84a26fd1ab949b9e4483d9d2c81ea6c41e1c08497fc900c0b476b55b2d157b8091aab1906f438317822c1f4718f56b1eec00f11d54e62f8e5f
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
- items.first(limit)
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
- @initial_offset ||= if before
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 ||= if first
51
- [first, max_page_size].compact.min
52
- else
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
- last
59
+ if previous_offset < 0
60
+ previous_offset + (last ? last : 0)
61
+ else
62
+ last
63
+ end
57
64
  end
58
- [last_limit, max_page_size].compact.min
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
- !!(first && sliced_nodes.limit(first + 1).count > first)
10
+ exceeds_limit?(first)
11
11
  end
12
12
 
13
13
  # Used by `pageInfo`
14
14
  def has_previous_page
15
- !!(last && sliced_nodes.limit(last + 1).count > last)
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 ||= if first
64
- [first, max_page_size].compact.min
65
- else
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
- last
71
+ if previous_offset < 0
72
+ previous_offset + (last ? last : 0)
73
+ else
74
+ last
75
+ end
70
76
  end
71
- [last_limit, max_page_size].compact.min
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
 
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Relay
3
- VERSION = '0.9.0'
3
+ VERSION = '0.9.1'
4
4
  end
5
5
  end
@@ -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.0
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-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql