Skip to content

Commit

Permalink
Adds volume to manga type for GraphQL (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
mizaki authored Nov 12, 2023
1 parent 32fd13a commit 840f8df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/graphql/loaders/volumes_loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class Loaders::VolumesLoader < GraphQL::FancyLoader
from Volume

sort :created_at
sort :updated_at
sort :number
end
12 changes: 12 additions & 0 deletions app/graphql/types/manga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ class Types::Manga < Types::BaseObject
null: true,
description: 'The number of volumes in this manga.'

field :volumes, Types::Volume.connection_type, null: true do
description 'The volumes in the manga.'
argument :sort, Loaders::VolumesLoader.sort_argument, required: false
end

def volumes(sort: [{ on: :number, direction: :asc }])
Loaders::VolumesLoader.connection_for({
find_by: :manga_id,
sort:
}, object.id)
end

field :chapters, Types::Chapter.connection_type, null: true do
description 'The chapters in the manga.'
argument :sort, Loaders::ChaptersLoader.sort_argument, required: false
Expand Down
5 changes: 5 additions & 0 deletions app/policies/volume_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class VolumePolicy < ApplicationPolicy
administrated_by :database_mod
end

0 comments on commit 840f8df

Please sign in to comment.