Commit 784b29bd authored by Alex Kalderimis's avatar Alex Kalderimis

Ensure we haven't missed any calls_gitaly annotations

This is an expensive step, unfortunately, but it is necessary to verify
that we annotated our fields correctly. The brute force
one-field-at-a-time approach is required due to our extensive caching
and memoization.
parent 8dfcb66d
...@@ -18,22 +18,92 @@ describe 'getting merge request listings nested in a project' do ...@@ -18,22 +18,92 @@ describe 'getting merge request listings nested in a project' do
let(:search_params) { nil } let(:search_params) { nil }
let(:query) do def query_merge_requests(fields)
graphql_query_for( graphql_query_for(
'project', :project,
{ 'fullPath' => project.full_path }, { full_path: project.full_path },
query_graphql_field('mergeRequests', search_params, [ query_graphql_field(:merge_requests, search_params, [
query_graphql_field('nodes', nil, all_graphql_fields_for('MergeRequest', max_depth: 1)) query_graphql_field(:nodes, nil, fields)
]) ])
) )
end end
let(:query) do
query_merge_requests(all_graphql_fields_for('MergeRequest', max_depth: 1))
end
it_behaves_like 'a working graphql query' do it_behaves_like 'a working graphql query' do
before do before do
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
end end
end end
# The following tests are needed to guarantee that we have correctly annotated
# all the gitaly calls. Selecting combinations of fields may mask this due to
# memoization.
context 'requesting a single field' do
let(:fresh_mr) { create(:merge_request, :unique_branches, source_project: project) }
let(:search_params) { { iids: [fresh_mr.iid.to_s] } }
before do
project.repository.expire_branches_cache
end
context 'selecting any single scalar field' do
where(:field) do
scalar_fields_of('MergeRequest').map { |name| [name] }
end
with_them do
it_behaves_like 'a working graphql query' do
let(:query) do
query_merge_requests([:iid, field].uniq)
end
before do
post_graphql(query, current_user: current_user)
end
it 'selects the correct MR' do
expect(results).to contain_exactly(a_hash_including('iid' => fresh_mr.iid.to_s))
end
end
end
end
context 'selecting any single nested field' do
where(:field, :subfield, :is_connection) do
nested_fields_of('MergeRequest').flat_map do |name, field|
type = field_type(field)
is_connection = type.name.ends_with?('Connection')
type = field_type(type.fields['nodes']) if is_connection
type.fields
.select { |_, field| !nested_fields?(field) && !required_arguments?(field) }
.map(&:first)
.map { |subfield| [name, subfield, is_connection] }
end
end
with_them do
it_behaves_like 'a working graphql query' do
let(:query) do
fld = is_connection ? query_graphql_field(:nodes, nil, [subfield]) : subfield
query_merge_requests([:iid, query_graphql_field(field, nil, [fld])])
end
before do
post_graphql(query, current_user: current_user)
end
it 'selects the correct MR' do
expect(results).to contain_exactly(a_hash_including('iid' => fresh_mr.iid.to_s))
end
end
end
end
end
shared_examples 'searching with parameters' do shared_examples 'searching with parameters' do
let(:expected) do let(:expected) do
mrs.map { |mr| a_hash_including('iid' => mr.iid.to_s, 'title' => mr.title) } mrs.map { |mr| a_hash_including('iid' => mr.iid.to_s, 'title' => mr.title) }
......
...@@ -304,6 +304,22 @@ module GraphqlHelpers ...@@ -304,6 +304,22 @@ module GraphqlHelpers
graphql_data.fetch(GraphqlHelpers.fieldnamerize(mutation_name)) graphql_data.fetch(GraphqlHelpers.fieldnamerize(mutation_name))
end end
def scalar_fields_of(type_name)
GitlabSchema.types[type_name].fields.map do |name, field|
next if nested_fields?(field) || required_arguments?(field)
name
end.compact
end
def nested_fields_of(type_name)
GitlabSchema.types[type_name].fields.map do |name, field|
next if !nested_fields?(field) || required_arguments?(field)
[name, field]
end.compact
end
def nested_fields?(field) def nested_fields?(field)
!scalar?(field) && !enum?(field) !scalar?(field) && !enum?(field)
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