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
required: true,
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
end
end
......
......@@ -11708,6 +11708,8 @@ Returns [`[String!]`](#string).
| 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. |
##### `Repository.tree`
......
......@@ -12,24 +12,37 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do
resolve(
described_class,
obj: project.repository,
args: { search_pattern: pattern },
args: { search_pattern: pattern, offset: offset, limit: 1 },
ctx: { current_user: project.creator }
)
end
context 'with empty search pattern' do
let(:pattern) { '' }
context 'with zero offset' do
let(:offset) { 0 }
it 'returns nil' do
expect(resolve_branch_names).to eq(nil)
context 'with empty search pattern' do
let(:pattern) { '' }
it 'returns nil' do
expect(resolve_branch_names).to eq(nil)
end
end
context 'with a valid search pattern' do
let(:pattern) { 'snippet/*' }
it 'returns matching branches' do
expect(resolve_branch_names).to contain_exactly('snippet/rename-and-edit-file')
end
end
end
context 'with a valid search pattern' do
let(:pattern) { 'mas*' }
context 'with offset' do
let(:pattern) { 'snippet/*' }
let(:offset) { 1 }
it 'returns matching branches' do
expect(resolve_branch_names).to match_array(['master'])
it 'skips first match' do
expect(resolve_branch_names).to contain_exactly('snippet/edit-file')
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