diff options
Diffstat (limited to 'spec/support/helpers/graphql_helpers.rb')
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 1f0c9b658dc..8b7d1c753d5 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -515,8 +515,13 @@ module GraphqlHelpers # Allows for array indexing, like this # ['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]) } + if memo.is_a?(Array) && key.is_a?(Integer) + memo[key] + elsif memo.is_a?(Array) + memo.compact.flat_map do |e| + x = e[key] + x.nil? ? [x] : Array.wrap(x) + end else memo&.dig(key) end |