hummingbird-me/kitsu-server

View on GitHub
app/graphql/loaders/comments_loader.rb

Summary

Maintainability
A
55 mins
Test Coverage
F
50%
class Loaders::CommentsLoader < GraphQL::FancyLoader
  from Comment
  sort :following,
    transform: ->(ast, context) {
      follows = Follow.arel_table
      comment = Comment.arel_table

      condition = follows[:followed_id].eq(comment[:user_id]).and(
        follows[:follower_id].eq(context[:user]&.id)
      )

      ast.join(follows, Arel::Nodes::OuterJoin).on(condition)
    },
    on: -> { Follow.arel_table[:id] }
  sort :created_at
  sort :likes_count
end