Commit 0e0ccd96 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch...

Merge branch '340466-graphql-api-project-and-group-fields-argument-fullpath-should-be-case-insensitive' into 'master'

Make project and group fields argument fullPath in graphql queries case insensitive

See merge request gitlab-org/gitlab!69924
parents 106c868f 37d2f721
......@@ -5,19 +5,20 @@ module Gitlab
module Loaders
# Suitable for use to find resources that expose `where_full_path_in`,
# such as Project, Group, Namespace
# full path is always converted to lowercase for case-insensitive results
class FullPathModelLoader
attr_reader :model_class, :full_path
def initialize(model_class, full_path)
@model_class = model_class
@full_path = full_path
@full_path = full_path.downcase
end
def find
BatchLoader::GraphQL.for(full_path).batch(key: model_class) do |full_paths, loader, args|
# `with_route` avoids an N+1 calculating full_path
args[:key].where_full_path_in(full_paths).with_route.each do |model_instance|
loader.call(model_instance.full_path, model_instance)
loader.call(model_instance.full_path.downcase, model_instance)
end
end
end
......
......@@ -20,10 +20,15 @@ RSpec.describe Resolvers::GroupResolver do
end
it 'resolves an unknown full_path to nil' do
result = batch_sync { resolve_group('unknown/project') }
result = batch_sync { resolve_group('unknown/group') }
expect(result).to be_nil
end
it 'treats group full path as case insensitive' do
result = batch_sync { resolve_group(group1.full_path.upcase) }
expect(result).to eq group1
end
end
def resolve_group(full_path)
......
......@@ -25,6 +25,11 @@ RSpec.describe Resolvers::ProjectResolver do
expect(result).to be_nil
end
it 'treats project full path as case insensitive' do
result = batch_sync { resolve_project(project1.full_path.upcase) }
expect(result).to eq project1
end
end
it 'does not increase complexity depending on number of load limits' do
......
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