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
444562e1
Commit
444562e1
authored
Nov 26, 2020
by
Alex Kalderimis
Committed by
Bob Van Landuyt
Nov 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BaseResolver#offset_pagination helper
This simplifies use of offset-pagination
parent
7f659a4e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
5 deletions
+31
-5
app/graphql/resolvers/base_resolver.rb
app/graphql/resolvers/base_resolver.rb
+4
-0
app/graphql/resolvers/board_list_issues_resolver.rb
app/graphql/resolvers/board_list_issues_resolver.rb
+1
-1
app/graphql/resolvers/board_lists_resolver.rb
app/graphql/resolvers/board_lists_resolver.rb
+1
-1
app/graphql/resolvers/issues_resolver.rb
app/graphql/resolvers/issues_resolver.rb
+1
-1
doc/development/graphql_guide/pagination.md
doc/development/graphql_guide/pagination.md
+15
-1
ee/app/graphql/resolvers/iterations_resolver.rb
ee/app/graphql/resolvers/iterations_resolver.rb
+1
-1
spec/graphql/resolvers/base_resolver_spec.rb
spec/graphql/resolvers/base_resolver_spec.rb
+8
-0
No files found.
app/graphql/resolvers/base_resolver.rb
View file @
444562e1
...
...
@@ -109,6 +109,10 @@ module Resolvers
[
args
[
:iid
],
args
[
:iids
]].
any?
?
0
:
0.01
end
def
offset_pagination
(
relation
)
::
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
relation
)
end
override
:object
def
object
super
.
tap
do
|
obj
|
...
...
app/graphql/resolvers/board_list_issues_resolver.rb
View file @
444562e1
...
...
@@ -16,7 +16,7 @@ module Resolvers
filter_params
=
issue_filters
(
args
[
:filters
]).
merge
(
board_id:
list
.
board
.
id
,
id:
list
.
id
)
service
=
::
Boards
::
Issues
::
ListService
.
new
(
list
.
board
.
resource_parent
,
context
[
:current_user
],
filter_params
)
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
service
.
execute
)
offset_pagination
(
service
.
execute
)
end
# https://gitlab.com/gitlab-org/gitlab/-/issues/235681
...
...
app/graphql/resolvers/board_lists_resolver.rb
View file @
444562e1
...
...
@@ -27,7 +27,7 @@ module Resolvers
List
.
preload_preferences_for_user
(
lists
,
context
[
:current_user
])
end
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
lists
)
offset_pagination
(
lists
)
end
private
...
...
app/graphql/resolvers/issues_resolver.rb
View file @
444562e1
...
...
@@ -24,7 +24,7 @@ module Resolvers
if
non_stable_cursor_sort?
(
args
[
:sort
])
# Certain complex sorts are not supported by the stable cursor pagination yet.
# In these cases, we use offset pagination, so we return the correct connection.
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
issues
)
offset_pagination
(
issues
)
else
issues
end
...
...
doc/development/graphql_guide/pagination.md
View file @
444562e1
...
...
@@ -86,6 +86,20 @@ However, there are some cases where we have to use the offset
pagination connection,
`OffsetActiveRecordRelationConnection`
, such as when
sorting by label priority in issues, due to the complexity of the sort.
If you return a relation from a resolver that is not suitable for keyset
pagination (due to the sort order for example), then you can use the
`BaseResolver#offset_pagination`
method to wrap the relation in the correct
connection type. For example:
```
ruby
def
resolve
(
**
args
)
result
=
Finder
.
new
(
object
,
current_user
,
args
).
execute
result
=
offset_pagination
(
result
)
if
needs_offset?
(
args
[
:sort
])
result
end
```
### Keyset pagination
The keyset pagination implementation is a subclass of
`GraphQL::Pagination::ActiveRecordRelationConnection`
,
...
...
@@ -225,7 +239,7 @@ instead of an `ActiveRecord::Relation`:
if
non_stable_cursor_sort?
(
args
[
:sort
])
# Certain complex sorts are not supported by the stable cursor pagination yet.
# In these cases, we use offset pagination, so we return the correct connection.
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
issues
)
offset_pagination
(
issues
)
else
issues
end
...
...
ee/app/graphql/resolvers/iterations_resolver.rb
View file @
444562e1
...
...
@@ -40,7 +40,7 @@ module Resolvers
# Necessary for scopedPath computation in IterationPresenter
context
[
:parent_object
]
=
parent
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
.
new
(
iterations
)
offset_pagination
(
iterations
)
end
private
...
...
spec/graphql/resolvers/base_resolver_spec.rb
View file @
444562e1
...
...
@@ -273,4 +273,12 @@ RSpec.describe Resolvers::BaseResolver do
end
end
end
describe
'#offset_pagination'
do
let
(
:instance
)
{
resolver_instance
(
resolver
)
}
it
'is sugar for OffsetActiveRecordRelationConnection.new'
do
expect
(
instance
.
offset_pagination
(
User
.
none
)).
to
be_a
(
::
Gitlab
::
Graphql
::
Pagination
::
OffsetActiveRecordRelationConnection
)
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