Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muster zur Performancesteigerung der GraphQL Anfragen (SaaS) #381

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions app/graphql/resolvers/event_records_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@

class Resolvers::EventRecordsSearch
include SearchObject.module(:graphql)
extras [:lookahead]

scope { EventRecord.upcoming(context[:current_user]) }
scope {
lookahead = context[:current_arguments][:lookahead]
event_records = EventRecord.upcoming(context[:current_user])
event_records = event_records.includes(:addresses) if lookahead.selects?(:addresses)
event_records = event_records.includes(:categories) if lookahead.selects?(:categories)
event_records = event_records.includes(:dates) if lookahead.selects?(:list_date) || lookahead.selects?(:dates)
donni106 marked this conversation as resolved.
Show resolved Hide resolved

event_records
}

type types[Types::QueryTypes::EventRecordType]

Expand Down Expand Up @@ -88,35 +97,35 @@ def apply_location(scope, value)
end

def apply_order_with_created_at_desc(scope)
scope.order("created_at DESC")
scope.order("event_records.created_at DESC")
end

def apply_order_with_created_at_asc(scope)
scope.order("created_at ASC")
scope.order("event_records.created_at ASC")
end

def apply_order_with_updated_at_desc(scope)
scope.order("updated_at DESC")
scope.order("event_records.updated_at DESC")
end

def apply_order_with_updated_at_asc(scope)
scope.order("updated_at ASC")
scope.order("event_records.updated_at ASC")
end

def apply_order_with_id_desc(scope)
scope.order("id DESC")
scope.order("event_records.id DESC")
end

def apply_order_with_id_asc(scope)
scope.order("id ASC")
scope.order("event_records.id ASC")
end

def apply_order_with_title_desc(scope)
scope.order("title DESC")
scope.order("event_records.title DESC")
end

def apply_order_with_title_asc(scope)
scope.order("title ASC")
scope.order("event_records.title ASC")
end

def apply_order_with_list_date_desc(scope)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QueryType < Types::BaseObject
argument :id, ID, required: true
end

field :event_records, function: Resolvers::EventRecordsSearch
field :event_records, [QueryTypes::EventRecordType], resolver: Resolvers::EventRecordsSearch, extras: [:lookahead]
field :event_record, QueryTypes::EventRecordType, null: false do
argument :id, ID, required: true
end
Expand Down