Define a Mutation Command
masterTo create a new business logic operation, subclass Mutations::Command. You define your input schema using required and optional blocks, and implement the core logic in the execute method. The execute method is only called if all input validations pass.
class UserSignup < Mutations::Command
# Required inputs
required do
string :email, matches: EMAIL_REGEX
string :name
end
# Optional inputs
optional do
boolean :newsletter_subscribe
end
# Business logic
def execute
user = User.create!(inputs)
NewsletterSubscriptions.create(email: email, user_id: user.id) if newsletter_subscribe
UserMailer.async(:deliver_welcome, user.id)
user
end
end