-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CV2-4475: Add Explainer data model and graphql api (#1860)
* CV2-4475: add explainer data model * CV2-4497: add graphql api * CV2-4475: apply PR comments and add more validation * CV2-4475: add missing tests * CV2-4475: fix test coverage * CV2-4475: apply PR comments * CV2-4475: update graphql schema * CV2-4475: apply PR comments
- Loading branch information
Showing
20 changed files
with
2,131 additions
and
608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module ExplainerMutations | ||
MUTATION_TARGET = 'explainer'.freeze | ||
PARENTS = ['team'].freeze | ||
|
||
module SharedCreateAndUpdateFields | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
argument :title, GraphQL::Types::String, required: true | ||
argument :description, GraphQL::Types::String, required: false | ||
argument :url, GraphQL::Types::String, required: false | ||
argument :language, GraphQL::Types::String, required: false | ||
end | ||
end | ||
|
||
class Create < Mutations::CreateMutation | ||
include SharedCreateAndUpdateFields | ||
end | ||
|
||
class Update < Mutations::UpdateMutation | ||
include SharedCreateAndUpdateFields | ||
end | ||
|
||
class Destroy < Mutations::DestroyMutation; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ArticleUnion < BaseUnion | ||
description 'A union type of all article types we can handle' | ||
possible_types( | ||
ExplainerType, | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ExplainerType < DefaultObject | ||
description "Explainer type" | ||
|
||
implements GraphQL::Types::Relay::Node | ||
|
||
field :dbid, GraphQL::Types::Int, null: true | ||
field :title, GraphQL::Types::String, null: true | ||
field :description, GraphQL::Types::String, null: true | ||
field :url, GraphQL::Types::String, null: true | ||
field :language, GraphQL::Types::String, null: true | ||
field :user_id, GraphQL::Types::Int, null: true | ||
field :team_id, GraphQL::Types::Int, null: true | ||
field :user, UserType, null: true | ||
field :team, PublicTeamType, null: true | ||
|
||
field :tags, TagType.connection_type, null: true | ||
|
||
def tags | ||
Tag.where(annotation_type: 'tag', annotated_type: object.class.name, annotated_id: object.id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Explainer < ApplicationRecord | ||
include Article | ||
|
||
belongs_to :team | ||
|
||
has_annotations | ||
|
||
before_validation :set_team | ||
validates_format_of :url, with: URI.regexp, allow_blank: true, allow_nil: true | ||
validates_presence_of :team | ||
validate :language_in_allowed_values, unless: proc { |e| e.language.blank? } | ||
|
||
def notify_bots | ||
# Nothing to do for Explainer | ||
end | ||
|
||
def send_to_alegre | ||
# Nothing to do for Explainer | ||
end | ||
|
||
private | ||
|
||
def set_team | ||
self.team ||= Team.current | ||
end | ||
|
||
def language_in_allowed_values | ||
allowed_languages = self.team.get_languages || ['en'] | ||
allowed_languages << 'und' | ||
errors.add(:language, I18n.t(:"errors.messages.invalid_article_language_value")) unless allowed_languages.include?(self.language) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateExplainers < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :explainers do |t| | ||
t.string :title | ||
t.text :description | ||
t.string :url | ||
t.string :language | ||
t.references :user, foreign_key: true, null: false | ||
t.references :team, foreign_key: true, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.