Class: GraphQL::Functions::Array

Inherits:
Base
  • Object
show all
Defined in:
lib/graphql/functions/array.rb

Instance Method Summary collapse

Methods inherited from Base

create, model

Instance Method Details

#call(*attrs) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphql/functions/array.rb', line 12

def call(*attrs)
  _, args, = attrs
  ids_filter = { id: args[:ids] } if args[:ids]
  order_by = args[:order_by].try(:to_sym)
  order = args[:desc] ? { order_by => :desc } : order_by
  relation = @model_class
    .all
    .where(ids_filter)
    .offset(args[:offset])
    .limit(args[:limit])
    .order(order)

  (query(relation, *attrs) if respond_to?(:query)) || relation
end

#typeObject



27
28
29
# File 'lib/graphql/functions/array.rb', line 27

def type
  @type ||= self.class.types[!type_class]
end

#type_classObject



31
32
33
# File 'lib/graphql/functions/array.rb', line 31

def type_class
  "Types::#{@model_class}Type".constantize
end