hummingbird-me/kitsu-server

View on GitHub
app/graphql/mutations/anime/create.rb

Summary

Maintainability
A
0 mins
Test Coverage
D
66%
class Mutations::Anime::Create < Mutations::Base
  prepend RescueValidationErrors

  argument :input,
    Types::Input::Anime::Create,
    required: true,
    description: 'Create an Anime.',
    as: :anime

  field :anime, Types::Anime, null: true
  field :errors, [Types::Interface::Error], null: true

  def load_anime(value)
    ::Anime.new(value.to_model)
  end

  def authorized?(anime:)
    super(anime, :create?)
  end

  def resolve(anime:)
    anime.save!

    { anime: anime }
  end
end