Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
27d9b19b
Commit
27d9b19b
authored
Jan 07, 2020
by
Sean Arnold
Committed by
Mayra Cabrera
Jan 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ExternallyPaginatedArrayConnection for graphql
- included specs - refactor some specs to be more generic
parent
e46ecc8e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
149 additions
and
4 deletions
+149
-4
lib/gitlab/graphql/connections.rb
lib/gitlab/graphql/connections.rb
+4
-0
lib/gitlab/graphql/connections/externally_paginated_array_connection.rb
...phql/connections/externally_paginated_array_connection.rb
+35
-0
lib/gitlab/graphql/externally_paginated_array.rb
lib/gitlab/graphql/externally_paginated_array.rb
+15
-0
spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb
...connections/externally_paginated_array_connection_spec.rb
+87
-0
spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb
...b/graphql/connections/filterable_array_connection_spec.rb
+3
-1
spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
.../lib/gitlab/graphql/connections/keyset/connection_spec.rb
+3
-1
spec/support/shared_examples/graphql/connection_paged_nodes.rb
...support/shared_examples/graphql/connection_paged_nodes.rb
+2
-2
No files found.
lib/gitlab/graphql/connections.rb
View file @
27d9b19b
...
...
@@ -12,6 +12,10 @@ module Gitlab
Gitlab
::
Graphql
::
FilterableArray
,
Gitlab
::
Graphql
::
Connections
::
FilterableArrayConnection
)
GraphQL
::
Relay
::
BaseConnection
.
register_connection_implementation
(
Gitlab
::
Graphql
::
ExternallyPaginatedArray
,
Gitlab
::
Graphql
::
Connections
::
ExternallyPaginatedArrayConnection
)
end
end
end
...
...
lib/gitlab/graphql/connections/externally_paginated_array_connection.rb
0 → 100644
View file @
27d9b19b
# frozen_string_literal: true
# Make a customized connection type
module
Gitlab
module
Graphql
module
Connections
class
ExternallyPaginatedArrayConnection
<
GraphQL
::
Relay
::
ArrayConnection
# As the pagination happens externally
# we just return all the nodes here.
def
sliced_nodes
@nodes
end
def
start_cursor
nodes
.
previous_cursor
end
def
end_cursor
nodes
.
next_cursor
end
def
next_page?
end_cursor
.
present?
end
def
previous_page?
start_cursor
.
present?
end
alias_method
:has_next_page
,
:next_page?
alias_method
:has_previous_page
,
:previous_page?
end
end
end
end
lib/gitlab/graphql/externally_paginated_array.rb
0 → 100644
View file @
27d9b19b
# frozen_string_literal: true
module
Gitlab
module
Graphql
class
ExternallyPaginatedArray
<
Array
attr_reader
:previous_cursor
,
:next_cursor
def
initialize
(
previous_cursor
,
next_cursor
,
*
args
)
super
(
args
)
@previous_cursor
=
previous_cursor
@next_cursor
=
next_cursor
end
end
end
end
spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb
0 → 100644
View file @
27d9b19b
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Graphql
::
Connections
::
ExternallyPaginatedArrayConnection
do
let
(
:prev_cursor
)
{
1
}
let
(
:next_cursor
)
{
6
}
let
(
:values
)
{
[
2
,
3
,
4
,
5
]
}
let
(
:all_nodes
)
{
Gitlab
::
Graphql
::
ExternallyPaginatedArray
.
new
(
prev_cursor
,
next_cursor
,
*
values
)
}
let
(
:arguments
)
{
{}
}
subject
(
:connection
)
do
described_class
.
new
(
all_nodes
,
arguments
)
end
describe
'#sliced_nodes'
do
let
(
:sliced_nodes
)
{
connection
.
sliced_nodes
}
it
'returns all the nodes'
do
expect
(
connection
.
sliced_nodes
).
to
eq
(
values
)
end
end
describe
'#paged_nodes'
do
let
(
:paged_nodes
)
{
connection
.
send
(
:paged_nodes
)
}
it_behaves_like
"connection with paged nodes"
do
let
(
:paged_nodes_size
)
{
values
.
size
}
end
end
describe
'#start_cursor'
do
it
'returns the prev cursor'
do
expect
(
connection
.
start_cursor
).
to
eq
(
prev_cursor
)
end
context
'when there is none'
do
let
(
:prev_cursor
)
{
nil
}
it
'returns nil'
do
expect
(
connection
.
start_cursor
).
to
eq
(
nil
)
end
end
end
describe
'#end_cursor'
do
it
'returns the next cursor'
do
expect
(
connection
.
end_cursor
).
to
eq
(
next_cursor
)
end
context
'when there is none'
do
let
(
:next_cursor
)
{
nil
}
it
'returns nil'
do
expect
(
connection
.
end_cursor
).
to
eq
(
nil
)
end
end
end
describe
'#has_next_page'
do
it
'returns true when there is a end cursor'
do
expect
(
connection
.
has_next_page
).
to
eq
(
true
)
end
context
'there is no end cursor'
do
let
(
:next_cursor
)
{
nil
}
it
'returns false'
do
expect
(
connection
.
has_next_page
).
to
eq
(
false
)
end
end
end
describe
'#has_previous_page'
do
it
'returns true when there is a start cursor'
do
expect
(
connection
.
has_previous_page
).
to
eq
(
true
)
end
context
'there is no start cursor'
do
let
(
:prev_cursor
)
{
nil
}
it
'returns false'
do
expect
(
connection
.
has_previous_page
).
to
eq
(
false
)
end
end
end
end
spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb
View file @
27d9b19b
...
...
@@ -14,7 +14,9 @@ describe Gitlab::Graphql::Connections::FilterableArrayConnection do
describe
'#paged_nodes'
do
let
(
:paged_nodes
)
{
subject
.
paged_nodes
}
it_behaves_like
"connection with paged nodes"
it_behaves_like
"connection with paged nodes"
do
let
(
:paged_nodes_size
)
{
3
}
end
context
'when callback filters some nodes'
do
let
(
:callback
)
{
proc
{
|
nodes
|
nodes
[
1
..-
1
]
}
}
...
...
spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb
View file @
27d9b19b
...
...
@@ -232,7 +232,9 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
let_it_be
(
:all_nodes
)
{
create_list
(
:project
,
5
)
}
let
(
:paged_nodes
)
{
subject
.
paged_nodes
}
it_behaves_like
"connection with paged nodes"
it_behaves_like
"connection with paged nodes"
do
let
(
:paged_nodes_size
)
{
3
}
end
context
'when both are passed'
do
let
(
:arguments
)
{
{
first:
2
,
last:
2
}
}
...
...
spec/support/shared_examples/graphql/connection_paged_nodes.rb
View file @
27d9b19b
...
...
@@ -2,7 +2,7 @@
RSpec
.
shared_examples
'connection with paged nodes'
do
it
'returns the collection limited to max page size'
do
expect
(
paged_nodes
.
size
).
to
eq
(
3
)
expect
(
paged_nodes
.
size
).
to
eq
(
paged_nodes_size
)
end
it
'is a loaded memoized array'
do
...
...
@@ -22,7 +22,7 @@ RSpec.shared_examples 'connection with paged nodes' do
let
(
:arguments
)
{
{
last:
2
}
}
it
'returns only the last elements'
do
expect
(
paged_nodes
).
to
contain_exactly
(
all_nodes
[
3
],
all_nodes
[
4
]
)
expect
(
paged_nodes
).
to
contain_exactly
(
*
all_nodes
.
last
(
2
)
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment