Module: GraphQLActiveRecordAutoSelect

Extended by:
GraphQLActiveRecordAutoSelect
Included in:
GraphQLActiveRecordAutoSelect
Defined in:
lib/graphql_activerecord_autoselect.rb,
lib/graphql_activerecord_autoselect/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#call(model:, lookahead:, dependents:) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/graphql_activerecord_autoselect.rb', line 33

def call(model:, lookahead:, dependents:)
  primary_key = model.primary_key
  columns     = model.column_names
  fields      = get_fields(lookahead)

  Array.new.tap do |selection|
    selection.concat filter_by_columns(fields, columns)
    selection.concat include_identifier_columns(primary_key, columns)
    selection.concat include_dependents(fields, dependents)
    selection.compact!
    selection.uniq!
  end
end