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

add lectureSearch query to GraphQL #740

Merged
merged 2 commits into from
Jan 28, 2024
Merged
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
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
Loading