freight v0.2.0 Freight.Payload
Link to this section Summary
Functions
Builds the default error object, and puts this in the config of freight
Absinthe middleware function that creates a payload
Defines a payload object type with a given name and fields
Link to this section Functions
Builds the default error object, and puts this in the config of freight.
NOTE: calling this overwrites your config
Default error object
object :payload_error do
field(:message, type: :string)
end
Absinthe middleware function that creates a payload
Usage
Below shows the usage in an absinthe scheme
@desc "Delete a comment"
field :delete_comment, :comment_delete_payload do
arg(:id, non_null(:id))
resolve(&CommentsResolver.delete_comment/3)
middleware(&build_payload/2)
end
Defines a payload object type with a given name and fields
Error object
By default an error object will be generated in build_error_object_default/0.
If you’d like to use a custom error object, configure this in your config.exs:
config :freight,
# where :user_error is the name of the type you'd like to use as an error object
error_object: :user_error
Keyword list and map errors are automatically mapped to your error.
Cangeset and string errors are mapped to the message
property.
Usage
define_payload(:user_payload, user: :user, comment: :comment)
creates the equilevant of
object :user_payload do
field(:successful,
type: non_null(:boolean),
description: "Indicates whether the mutation completed successfully or not."
)
field(:errors,
type: list_of(:payload_error),
description: "A list of errors, raised when executing this migrations."
)
field(:user, type: :user)
field(:comment, type: :comment)
end