Module: GraphQL::Groups::Utils
- Defined in:
- lib/graphql/groups/utils.rb
Class Method Summary collapse
-
.duplicate(keys, values) ⇒ Object
This is used by the resul transformer when the user executed a query where some groupings are repeated, so depth of the query doesn’t match the length of the query result keys.
- .wrap(object) ⇒ Object
Class Method Details
.duplicate(keys, values) ⇒ Object
This is used by the resul transformer when the user executed a query where some groupings are repeated, so depth of the query doesn’t match the length of the query result keys. We need to modify the result keys so everything matches again.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graphql/groups/utils.rb', line 20 def duplicate(keys, values) return if keys.length == values.length duplicates = duplicates(keys) return if duplicates.empty? duplicates.each do |_, indices| first_occurrence, *rest = indices value_to_duplicate = values[first_occurrence] rest.each { |index| values.insert(index, value_to_duplicate) } end end |
.wrap(object) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/graphql/groups/utils.rb', line 7 def wrap(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary || [object] else [object] end end |