Skip to content

Commit

Permalink
CV2-5730: return dummy relevant articles (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy authored Nov 23, 2024
1 parent 464eb3e commit b22f022
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 578 deletions.
17 changes: 17 additions & 0 deletions app/graph/types/project_media_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,21 @@ def articles_count
count += 1 if object.fact_check
count
end

field :relevant_articles, ::ArticleUnion.connection_type, null: true

def relevant_articles
# TODO: replace a dummy articles with right ones
team_id = object.team_id
FactCheck.includes(:claim_description).where('claim_descriptions.team_id' => team_id)
.where.not('fact_checks.id' => object.fact_check_id)
.limit(10)
end

field :relevant_articles_count, GraphQL::Types::Int, null: true

def relevant_articles_count
# TODO: get right count
10
end
end
66 changes: 0 additions & 66 deletions app/graph/types/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,72 +369,6 @@ def articles_count(**args)
count
end

field :relevant_articles, ::ArticleUnion.connection_type, null: true do
argument :article_type, GraphQL::Types::String, required: true, camelize: false

# Sort and pagination
argument :offset, GraphQL::Types::Int, required: false, default_value: 0
argument :sort, GraphQL::Types::String, required: false, default_value: 'title'
argument :sort_type, GraphQL::Types::String, required: false, camelize: false, default_value: 'ASC'

# Filters
argument :user_ids, [GraphQL::Types::Int, null: true], required: false, camelize: false
argument :tags, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :language, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :updated_at, GraphQL::Types::String, required: false, camelize: false # JSON
argument :text, GraphQL::Types::String, required: false, camelize: false # Search by text
argument :standalone, GraphQL::Types::Boolean, required: false, camelize: false # Not applied to any item (fact-checks only)
argument :publisher_ids, [GraphQL::Types::Int, null: true], required: false, camelize: false
argument :report_status, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :rating, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :imported, GraphQL::Types::Boolean, required: false, camelize: false # Only for fact-checks
argument :target_id, GraphQL::Types::Int, required: false, camelize: false # Exclude articles already applied to the `ProjectMedia` with this ID
argument :trashed, GraphQL::Types::Boolean, required: false, camelize: false, default_value: false
end

def relevant_articles(**args)
sort = args[:sort].to_s
order = [:title, :language, :updated_at, :id].include?(sort.downcase.to_sym) ? sort.downcase.to_sym : :title
order_type = args[:sort_type].to_s.downcase.to_sym == :desc ? :desc : :asc
articles = Explainer.none
if args[:article_type] == 'explainer'
articles = object.filtered_explainers(args)
elsif args[:article_type] == 'fact-check'
articles = object.filtered_fact_checks(args)
end
articles.offset(args[:offset].to_i).order(order => order_type)
end

field :relevant_articles_count, GraphQL::Types::Int, null: true do
argument :article_type, GraphQL::Types::String, required: false, camelize: false

# Filters
argument :user_ids, [GraphQL::Types::Int, null: true], required: false, camelize: false
argument :tags, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :language, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :updated_at, GraphQL::Types::String, required: false, camelize: false # JSON
argument :text, GraphQL::Types::String, required: false, camelize: false # Search by text
argument :standalone, GraphQL::Types::Boolean, required: false, camelize: false # Not applied to any item (fact-checks only)
argument :publisher_ids, [GraphQL::Types::Int, null: true], required: false, camelize: false
argument :report_status, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :rating, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :imported, GraphQL::Types::Boolean, required: false, camelize: false # Only for fact-checks
argument :target_id, GraphQL::Types::Int, required: false, camelize: false # Exclude articles already applied to the `ProjectMedia` with this ID
argument :trashed, GraphQL::Types::Boolean, required: false, camelize: false, default_value: false
end

def relevant_articles_count(**args)
count = nil
if args[:article_type] == 'explainer'
count = object.filtered_explainers(args).count
elsif args[:article_type] == 'fact-check'
count = object.filtered_fact_checks(args).count
elsif args[:article_type].blank?
count = object.filtered_explainers(args).count + object.filtered_fact_checks(args).count
end
count
end

field :api_key, ApiKeyType, null: true do
argument :dbid, GraphQL::Types::Int, required: true
end
Expand Down
60 changes: 22 additions & 38 deletions lib/relay.idl
Original file line number Diff line number Diff line change
Expand Up @@ -11666,6 +11666,28 @@ type ProjectMedia implements Node {
published: String
pusher_channel: String
quote: String
relevant_articles(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Returns the elements in the list that come before the specified cursor.
"""
before: String

"""
Returns the first _n_ elements from the list.
"""
first: Int

"""
Returns the last _n_ elements from the list.
"""
last: Int
): ArticleUnionConnection
relevant_articles_count: Int
report_status: String
report_type: String
requests(
Expand Down Expand Up @@ -13320,44 +13342,6 @@ type Team implements Node {
public_team: PublicTeam
public_team_id: String
pusher_channel: String
relevant_articles(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
article_type: String!

"""
Returns the elements in the list that come before the specified cursor.
"""
before: String

"""
Returns the first _n_ elements from the list.
"""
first: Int
imported: Boolean
language: [String]

"""
Returns the last _n_ elements from the list.
"""
last: Int
offset: Int = 0
publisher_ids: [Int]
rating: [String]
report_status: [String]
sort: String = "title"
sort_type: String = "ASC"
standalone: Boolean
tags: [String]
target_id: Int
text: String
trashed: Boolean = false
updated_at: String
user_ids: [Int]
): ArticleUnionConnection
relevant_articles_count(article_type: String, imported: Boolean, language: [String], publisher_ids: [Int], rating: [String], report_status: [String], standalone: Boolean, tags: [String], target_id: Int, text: String, trashed: Boolean = false, updated_at: String, user_ids: [Int]): Int
rules_json_schema: String
rules_search_fields_json_schema: JsonStringType
saved_searches(
Expand Down
Loading

0 comments on commit b22f022

Please sign in to comment.