Skip to content

Commit

Permalink
add order_by to events query
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlindsey committed Nov 21, 2020
1 parent ca6795e commit 50dbb26
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# frozen_string_literal: true

module Types
class QueryType < Types::BaseObject
field :events, [EventType], null: false,
description: 'Query for all events'
def events
Event.all
field :events, [EventType], null: false, description: 'Query for all events' do
argument :order_by, String, required: false
argument :order_direction, String, required: false
end
def events(order_by: nil, order_direction: 'asc')
if order_by
Event.all.order(order_by + ' ' + order_direction)
else
Event.all
end
end
end
end

0 comments on commit 50dbb26

Please sign in to comment.