From 51a81160af19f030cd89fc8f2c632564436b14b0 Mon Sep 17 00:00:00 2001 From: Nick Vernij Date: Sat, 15 Sep 2018 15:27:28 +0200 Subject: [PATCH] Improve documentation + release 0.2.0 --- CHANGELOG.md | 9 ++++++++- README.md | 9 +++++++++ lib/error_payload.ex | 6 ++++++ lib/success_payload.ex | 6 ++++++ mix.exs | 2 +- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd922ee..c814f4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,9 @@ # Changelog -## 0.1.1 \ No newline at end of file +## 0.2.0 + +**Added:** +* Ecto integration, which generates error messages from failed changesets +* Errors array is no longer nullable, and now always returns an array +* Errors are now an object instead of a string +* Successful field is no longer nullable +* Configurable error objects in the errors array using application env \ No newline at end of file diff --git a/README.md b/README.md index f632575..6a24acb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,15 @@ Freight is a library for [Absinthe GraphQL](http://absinthe-graphql.org/) that h It is heavily inspired by [Kronky](https://github.com/Ethelo/kronky), I decided to build my own library because I did not like how much it is focussed on ecto changesets, and missed customisability that was required for a project I work on. +## Configuration + +You can set a custom error object that will be returned in the errors array in your payloads. This object must be defined in the schemna you're calling `define_payload` from. + +```elixir +config :freight, + error_object: :user_error +``` + ## Usage Below is a documented example of how to define Freight payloads in your schema diff --git a/lib/error_payload.ex b/lib/error_payload.ex index c399990..b059efc 100644 --- a/lib/error_payload.ex +++ b/lib/error_payload.ex @@ -1,6 +1,12 @@ defmodule Freight.Payload.ErrorPayload do alias Freight.Integrations + @moduledoc """ + Error payloads are payloads that are created when an :error tuple has been returned. + + Their `successful` property is always set to `false`. + """ + @doc """ Manually generates a map representing a generic unsuccessful object. All customized result fields will not be defined, and thus returned as nil diff --git a/lib/success_payload.ex b/lib/success_payload.ex index 20d3dca..49c00c3 100644 --- a/lib/success_payload.ex +++ b/lib/success_payload.ex @@ -1,4 +1,10 @@ defmodule Freight.Payload.SuccessPayload do + @moduledoc """ + Success payloads are payloads that are created when an :ok tuple has been returned. + + Their `successful` property is always set to `true`. + """ + @base_success_payload %{ successful: true, errors: [] diff --git a/mix.exs b/mix.exs index 610b660..f2cb0e7 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Freight.MixProject do def project do [ app: :freight, - version: "0.1.0", + version: "0.2.0", elixir: "~> 1.6", start_permanent: Mix.env() == :prod, deps: deps(),