Last active
November 15, 2017 18:16
-
-
Save ssomnoremac/288b5e6e82791e16c95a548fe8134699 to your computer and use it in GitHub Desktop.
Proposal Module definition of Mutation/Command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In each Command module | |
defmodule Hyr.Shifts.Opening.Commands.CancelOpening do | |
use Hyr.Commanded | |
input_object :cancel_opening_input_object do | |
field :opening_id, non_null(:id) | |
field :employer_id, non_null(:id) | |
end | |
end | |
# Schema usage | |
defmodule Hyr.Schema | |
use Hyr.Mutation | |
alias Hyr.Shifts.Opening.Commands.{ | |
CancelOpening | |
} | |
# ... | |
mutation do | |
@desc "Cancel an Opening" | |
command_mutation :cancel_opening, CancelOpening | |
output: :opening | |
permission: "MANAGE_OPENINGS" | |
# @desc "Cancel an opening" | |
# payload field :cancel_opening do | |
# input do | |
# field :opening_id, non_null(:id) | |
# field :employer_id, non_null(:id) | |
# end | |
# output do | |
# field :result, :opening | |
# end | |
# middleware Middleware.Authorize, "MANAGE_OPENINGS" | |
# resolve fn input_data, _ -> | |
# case Router.dispatch(CancelOpening.new(input_data), consistency: :strong) do | |
# :ok -> | |
# {:ok, %{result: Hyr.Repo.get_by(Opening, id: input_data.opening_id)}} | |
# {:error, reason} -> {:error, %{message: to_string(reason)}} | |
# end | |
# end | |
# end | |
# ... other mutations | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment