Module: Graphiti::ActiveGraph::ResourceInstanceMethods

Defined in:
lib/graphiti/active_graph/resource.rb

Instance Method Summary collapse

Instance Method Details

#relation_resource?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/graphiti/active_graph/resource.rb', line 29

def relation_resource?
  self.class.relation_resource?
end

#resolve(scope) ⇒ Object



37
38
39
# File 'lib/graphiti/active_graph/resource.rb', line 37

def resolve(scope)
  adapter.resolve(scope, relation_resource?)
end

#sideload_name_arr(query) ⇒ Object



33
34
35
# File 'lib/graphiti/active_graph/resource.rb', line 33

def sideload_name_arr(query)
  query.sideloads.keys.map(&:to_sym)
end

#typecast(name, value, flag) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/graphiti/active_graph/resource.rb', line 41

def typecast(name, value, flag)
  att = get_attr!(name, flag, request: true)

  # in case of attribute is not declared on resource
  # do not throw error, return original value without typecast
  return value unless att

  type_name = att[:type]
  if flag == :filterable
    type_name = filters[name][:type]
  end
  type = Graphiti::Types[type_name]
  return if value.nil? && type[:kind] != "array"
  begin
    flag = :read if flag == :readable
    flag = :write if flag == :writable
    flag = :params if [:sortable, :filterable].include?(flag)
    type[flag][value]
  rescue => e
    raise Errors::TypecastFailed.new(self, name, value, e, type_name)
  end
end