Module: GraphQL::Models::Helpers

Defined in:
lib/graphql/models/helpers.rb

Class Method Summary collapse

Class Method Details

.load_association_with(association, result) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/models/helpers.rb', line 17

def self.load_association_with(association, result)
  reflection = association.reflection
  association.loaded!

  if reflection.macro == :has_many
    association.target.slice!(0..-1)
    association.target.concat(result)
    result.each do |m|
      association.set_inverse_instance(m)
    end
  else
    association.target = result
    association.set_inverse_instance(result) if result
  end
end

.orders_to_sql(orders) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/graphql/models/helpers.rb', line 4

def self.orders_to_sql(orders)
  expressions = orders.map do |expr|
    case expr
    when Arel::Nodes::SqlLiteral
      expr.to_s
    else
      expr.to_sql
    end
  end

  expressions.join(', ')
end