Skip to content

Commit

Permalink
add lectureSearch resolver to GraphQL (#740)
Browse files Browse the repository at this point in the history
* add `lectureSearch` resolver to graphql
* add empty line 3:)
  • Loading branch information
volkovmqx committed Jan 28, 2024
1 parent a2a0ef6 commit 8ba383b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/graphql/resolvers/search_lectures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Resolvers::SearchLectures < GraphQL::Schema::Resolver
type [Types::LectureType], null: false

argument :query, String, required: true
argument :page, Integer, required: false

def resolve(query:, page: 1)
results = Frontend::Event.query(query).page(page)
@events = results.records.includes(recordings: :conference)
end
end
2 changes: 2 additions & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def lecture_by_slug(slug:)
Frontend::Event.find_by(slug: slug)
end

field :lecture_search, resolver: Resolvers::SearchLectures

field :lectures_related_to, LectureType.connection_type, null: true do
description 'A list of related lectures, ordered by decreasing relevance.'
argument :guid, ID, required: true
Expand Down
54 changes: 54 additions & 0 deletions test/integration/graphql/lecture_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,58 @@ class LectureGraphQLApiTest < ActionDispatch::IntegrationTest

end

unless ENV['SKIP_ELASTICSEARCH']
test 'search for lectures' do
query_string = <<-GRAPHQL
query($query: String!) {
lectureSearch(query: $query) {
title
images {
thumbUrl
posterUrl
}
}
}
GRAPHQL
result = MediaBackendSchema.execute(query_string, variables: { query: "not-existing" })
assert_empty result['data']['lectureSearch']
end

test 'search for lectures return multiple results' do
Event.__elasticsearch__.create_index! force: true
create_list(:event, 26, title: 'fake-event')
Event.import
Event.__elasticsearch__.refresh_index!

query_string = <<-GRAPHQL
query($query: String!) {
lectureSearch(query: $query) {
title
images {
thumbUrl
posterUrl
}
}
}
GRAPHQL
result = MediaBackendSchema.execute(query_string, variables: { query: "fake-event" })
assert_nil result['errors']
assert_equal 25, result['data']['lectureSearch'].count
query_string = <<-GRAPHQL
query($query: String!, $page: Int!) {
lectureSearch(query: $query, page: $page) {
title
images {
thumbUrl
posterUrl
}
}
}
GRAPHQL
result = MediaBackendSchema.execute(query_string, variables: { query: "fake-event", page: 2 })
assert_nil result['errors']
assert_equal 1, result['data']['lectureSearch'].count
end
end

end

0 comments on commit 8ba383b

Please sign in to comment.