hummingbird-me/kitsu-server

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

Summary

Maintainability
A
55 mins
Test Coverage
A
100%
class Loaders::CommentLikesLoader < GraphQL::FancyLoader
  from CommentLike
  sort :following,
    transform: ->(ast, context) {
      follows = Follow.arel_table
      likes = CommentLike.arel_table

      condition = follows[:followed_id].eq(likes[: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
end