Commit 2cab4268 authored by Alex Kalderimis's avatar Alex Kalderimis

Do not omit nil results using graphql_dig_at

parent 5e02ef43
......@@ -71,6 +71,6 @@ RSpec.describe Types::BaseEdge do
.to contain_exactly(member_project.name, maintainer_project.name, public_project.name)
expect(graphql_dig_at(result, 'data', 'projects', 'edges', 'proofOfAdminRights'))
.to contain_exactly('ok')
.to contain_exactly(nil, 'ok', nil)
end
end
......@@ -68,7 +68,7 @@ RSpec.describe 'package details' do
subject
expect(graphql_data_at(:package, :versions, :nodes, :version)).to be_present
expect(graphql_data_at(:package, :versions, :nodes, :versions, :nodes)).to be_empty
expect(graphql_data_at(:package, :versions, :nodes, :versions, :nodes)).to eq [nil, nil]
end
end
end
......
......@@ -515,7 +515,10 @@ module GraphqlHelpers
# ['project', 'boards', 'edges', 0, 'node', 'lists']
keys.reduce(data) do |memo, key|
if memo.is_a?(Array)
key.is_a?(Integer) ? memo[key] : memo.flat_map { |e| Array.wrap(e[key]) }
key.is_a?(Integer) ? memo[key] : memo.compact.flat_map do |e|
x = e[key]
x.nil? ? [x] : Array.wrap(x)
end
else
memo&.dig(key)
end
......
......@@ -55,7 +55,7 @@ RSpec.shared_examples 'group and project packages query' do
end
it 'deals with metadata' do
expect(target_shas).to contain_exactly(composer_metadatum.target_sha)
expect(target_shas.compact).to contain_exactly(composer_metadatum.target_sha)
end
it 'returns the count of the packages' do
......
......@@ -43,6 +43,21 @@ RSpec.describe GraphqlHelpers do
expect(graphql_dig_at(data, :foo, :nodes, :bar, :nodes, :id)).to eq([1, 2, 3, 4])
end
it 'does not omit nils at the leaves' do
data = {
'foo' => {
'nodes' => [
{ 'bar' => { 'nodes' => [{ 'id' => nil }, { 'id' => 2 }] } },
{ 'bar' => { 'nodes' => [{ 'id' => 3 }, { 'id' => nil }] } },
{ 'bar' => nil }
]
},
'irrelevant' => 'the field is a red-herring'
}
expect(graphql_dig_at(data, :foo, :nodes, :bar, :nodes, :id)).to eq([nil, 2, 3, nil])
end
end
describe 'var' 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