Commit 047daed0 authored by Matija Čupić's avatar Matija Čupić

Add offset and limit parameters to names resolver

Adds offset and limit parameters to branch names resolver to facilitate
efficient use.

Changelog: changed
parent 23750887
...@@ -10,7 +10,24 @@ module Resolvers ...@@ -10,7 +10,24 @@ module Resolvers
required: true, required: true,
description: 'The pattern to search for branch names by.' description: 'The pattern to search for branch names by.'
def resolve(search_pattern:) argument :offset, GraphQL::INT_TYPE,
required: true,
description: 'The number of branch names to skip.'
argument :limit, GraphQL::INT_TYPE,
required: true,
description: 'The number of branch names to return.'
def resolve(search_pattern:, offset:, limit:)
names = branch_names(search_pattern)
return unless names
names.lazy.drop(offset).take(limit) # rubocop:disable CodeReuse/ActiveRecord
end
private
def branch_names(search_pattern)
Repositories::BranchNamesFinder.new(object, search: search_pattern).execute Repositories::BranchNamesFinder.new(object, search: search_pattern).execute
end end
end end
......
...@@ -11708,6 +11708,8 @@ Returns [`[String!]`](#string). ...@@ -11708,6 +11708,8 @@ Returns [`[String!]`](#string).
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="repositorybranchnameslimit"></a>`limit` | [`Int!`](#int) | The number of branch names to return. |
| <a id="repositorybranchnamesoffset"></a>`offset` | [`Int!`](#int) | The number of branch names to skip. |
| <a id="repositorybranchnamessearchpattern"></a>`searchPattern` | [`String!`](#string) | The pattern to search for branch names by. | | <a id="repositorybranchnamessearchpattern"></a>`searchPattern` | [`String!`](#string) | The pattern to search for branch names by. |
##### `Repository.tree` ##### `Repository.tree`
......
...@@ -12,11 +12,14 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do ...@@ -12,11 +12,14 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do
resolve( resolve(
described_class, described_class,
obj: project.repository, obj: project.repository,
args: { search_pattern: pattern }, args: { search_pattern: pattern, offset: offset, limit: 1 },
ctx: { current_user: project.creator } ctx: { current_user: project.creator }
) )
end end
context 'with zero offset' do
let(:offset) { 0 }
context 'with empty search pattern' do context 'with empty search pattern' do
let(:pattern) { '' } let(:pattern) { '' }
...@@ -26,10 +29,20 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do ...@@ -26,10 +29,20 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do
end end
context 'with a valid search pattern' do context 'with a valid search pattern' do
let(:pattern) { 'mas*' } let(:pattern) { 'snippet/*' }
it 'returns matching branches' do it 'returns matching branches' do
expect(resolve_branch_names).to match_array(['master']) expect(resolve_branch_names).to contain_exactly('snippet/rename-and-edit-file')
end
end
end
context 'with offset' do
let(:pattern) { 'snippet/*' }
let(:offset) { 1 }
it 'skips first match' do
expect(resolve_branch_names).to contain_exactly('snippet/edit-file')
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment