Class: Binda::Api::Resolvers::ComponentsResolver

Inherits:
Object
  • Object
show all
Defined in:
app/graphql/binda/api/resolvers/components_resolver.rb

Instance Method Summary collapse

Instance Method Details

#call(obj, args, ctx = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/graphql/binda/api/resolvers/components_resolver.rb', line 2

def call(obj, args, ctx = {})
  query_params = args.to_h.symbolize_keys
  query_params.reject!{|k,v| [:first, :last, :after, :before].include? k }
  structure_slug = query_params.delete(:structure_slug)
  
  components = Binda::Component.where query_params
  if structure_slug
    components = components.includes(:structure).where(binda_structures: { slug: structure_slug })
  end

  components.order('binda_components.position ASC')
end