-
Notifications
You must be signed in to change notification settings - Fork 142
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 new mutations and refactor old ones #1465
base: the-future
Are you sure you want to change the base?
Add new mutations and refactor old ones #1465
Conversation
Remove anime and manga mutations since they're gonna be replaced by WikiSubmissions.
Create Embed type + its children types
Add attachments & embeds
|
||
def ready?(id:, **) | ||
authenticate! | ||
@post = Post.find_by(id:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unexpected token tRPAREN
@@ -0,0 +1,4 @@ | |||
class Loaders::AttachmentsLoader < GraphQL::FancyLoader | |||
from Upload | |||
sort :upload_order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
@@ -0,0 +1,4 @@ | |||
class Loaders::AttachmentsLoader < GraphQL::FancyLoader | |||
from Upload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
@@ -0,0 +1,4 @@ | |||
class Loaders::AttachmentsLoader < GraphQL::FancyLoader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Missing frozen string literal comment.
field :like, | ||
mutation: Mutations::Comment::Like, | ||
description: 'Like a Comment.' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
field :like, | ||
mutation: Mutations::Post::Like, | ||
description: 'Like a Post.' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
field :follow, | ||
mutation: Mutations::Post::Follow, | ||
description: 'Follow a Post.' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
field :delete, | ||
mutation: Mutations::Post::Delete, | ||
description: 'Delete a Post.' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
|
||
{ post: post } | ||
def resolve(**) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Expected 1 empty line between method definitions; found 3. (https://rubystyle.guide#empty-lines-between-methods)
end | ||
|
||
def resolve(post:) | ||
post.save! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
}] | ||
# Authorize it with the policy | ||
authorize!(@post, :create?) | ||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
elsif !input[:target_group_id].nil? | ||
return errors << Types::Errors::NotFound.build(path: %w[input | ||
target_group_id]) if Group.find_by(id: input[:target_group_id]).nil? | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Redundant else-clause.
target_user_id]) if User.find_by(id: input[:target_user_id]).nil? | ||
elsif !input[:target_group_id].nil? | ||
return errors << Types::Errors::NotFound.build(path: %w[input | ||
target_group_id]) if Group.find_by(id: input[:target_group_id]).nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Align the elements of an array literal if they span more than one line. (https://rubystyle.guide#no-double-indent)
return errors << Types::Errors::NotFound.build(path: %w[input | ||
target_user_id]) if User.find_by(id: input[:target_user_id]).nil? | ||
elsif !input[:target_group_id].nil? | ||
return errors << Types::Errors::NotFound.build(path: %w[input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
# And finally check if the post has a target and if they're valid | ||
if !input[:target_user_id].nil? | ||
return errors << Types::Errors::NotFound.build(path: %w[input | ||
target_user_id]) if User.find_by(id: input[:target_user_id]).nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Align the elements of an array literal if they span more than one line. (https://rubystyle.guide#no-double-indent)
when 'Chapter' then @unit = Chapter.find_by(id: input[:spoiled_unit_id], media_id: input[:media_id]) | ||
else @unit = nil | ||
end | ||
return errors << Types::Errors::NotFound.build(path: %w[input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
app/graphql/mutations/post/create.rb
Outdated
unless input[:spoiled_unit_id].nil? ^ input[:spoiled_unit_type].nil? | ||
case input[:spoiled_unit_type] | ||
when 'Episode' then @unit = Episode.find_by(id: input[:spoiled_unit_id], media_id: input[:media_id]) | ||
when 'Chapter' then @unit = Chapter.find_by(id: input[:spoiled_unit_id], media_id: input[:media_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Indent when as deep as case. (https://rubystyle.guide#indent-when-to-case)
[Correctable] Line is too long. [108/100] (https://rubystyle.guide#max-line-length)
# Check if the spoiled unit is valid | ||
unless input[:spoiled_unit_id].nil? ^ input[:spoiled_unit_type].nil? | ||
case input[:spoiled_unit_type] | ||
when 'Episode' then @unit = Episode.find_by(id: input[:spoiled_unit_id], media_id: input[:media_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Indent when as deep as case. (https://rubystyle.guide#indent-when-to-case)
[Correctable] Line is too long. [108/100] (https://rubystyle.guide#max-line-length)
end | ||
|
||
# Check if the spoiled unit is valid | ||
unless input[:spoiled_unit_id].nil? ^ input[:spoiled_unit_type].nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Do not use unless with else. Rewrite these with the positive case first. (https://rubystyle.guide#no-else-with-unless)
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
media_id media_type]) if (@media.nil? && !input[:media_id].nil?) | ||
else | ||
return errors << Types::Errors::Validation.build(path: %w[input media_id media_type], | ||
message: 'You have to provide both mediaId and mediaType.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Trailing whitespace detected. (https://rubystyle.guide#no-trailing-whitespace)
I don't think there's any out-of-the-box Rails validators which can do that, but a custom validation could do it pretty easily, like: validate :unit_in_media
def unit_in_media
return if unit.blank?
unless unit.media_type == media_type && unit.media_id == media_id
errors.add(:unit, "must be from the tagged media")
end
end |
This way we prevent matching data of other medias
…tsu-server into refactor-mutations
|
||
field :height, Integer, | ||
null: true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Final newline missing. (https://rubystyle.guide#newline-eof)
null: true | ||
|
||
field :height, Integer, | ||
null: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use one level of indentation for arguments following the first line of a multi-line method call. (https://rubystyle.guide#no-double-indent)
field :width, Integer, | ||
null: true | ||
|
||
field :height, Integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
null: false | ||
|
||
field :width, Integer, | ||
null: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use one level of indentation for arguments following the first line of a multi-line method call. (https://rubystyle.guide#no-double-indent)
field :type, String, | ||
null: false | ||
|
||
field :width, Integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
end | ||
|
||
# Find the post | ||
@post = Post.find_by(id:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unexpected token tRPAREN
field :url, String, | ||
null: true, | ||
description: 'The url of the embedded website.' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Final newline missing. (https://rubystyle.guide#newline-eof)
|
||
field :url, String, | ||
null: true, | ||
description: 'The url of the embedded website.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
description: 'The name of the embedded website.' | ||
|
||
field :url, String, | ||
null: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use one level of indentation for arguments following the first line of a multi-line method call. (https://rubystyle.guide#no-double-indent)
null: false, | ||
description: 'The name of the embedded website.' | ||
|
||
field :url, String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Correctable] Tab detected in indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Use 2 (not 1) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
[Correctable] Inconsistent indentation detected. (https://rubystyle.guide#spaces-indentation, https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions)
What
Refactor old Mutations on top of FancyMutation.
Add new mutations to GraphQL:
Add new Types:
Add
AttachmentsLoader
Removed old Manga & Anime mutations in favor of WikiSubmissions
Why
Checklist