Skip to content

Commit

Permalink
Bump to version 2.0.0 and improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielpra1 committed Jul 31, 2019
1 parent 8a5ddf1 commit df0baec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ It also provides a simple middleware for translating changeset errors into reada

Documentation can be found at [https://hexdocs.pm/crudry](https://hexdocs.pm/crudry).

The changelog can be found at the [Releases page](https://github.com/gabrielpra1/crudry/releases).

## Installation

The package can be installed by adding `crudry` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:crudry, "~> 1.5.0"},
{:crudry, "~> 2.0.0"},
]
end
```

----

## Usage

### Context Generation
Expand All @@ -37,6 +41,7 @@ end

To see the functions that are generated and custom options, refer to the [Crudry.Context docs](https://hexdocs.pm/crudry/Crudry.Context.html#module-usage).


### Resolver Generation

With the context all set up, the resolver is ready to be generated:
Expand All @@ -56,20 +61,20 @@ To see the functions that are generated and custom options, refer to the [Crudry

Absinthe Middleware to translate errors and changeset errors into human readable messages. It support nested changeset errors and internationalization, using [Gettext](https://github.com/elixir-lang/gettext).

The `create`, `update` and `delete` functions in the resolver all return `Ecto.Changeset` as errors, so it's useful to translate them into human readable messages.
To handle errors for a field, add it after the resolve, using [`middleware/2`](https://hexdocs.pm/absinthe/Absinthe.Middleware.html#module-the-middleware-2-macro):

Crudry provides an `Absinthe.Middleware` to help with that, handling nested changeset errors. Just add it as a middleware to your mutations:
```elixir
alias Crudry.Middlewares.TranslateErrors

```elxixir
field :create_user, :user do
arg :params, non_null(:user_params)

resolve &UsersResolver.create_user/2
middleware Crudry.Middlewares.TranslateErrors
middleware TranslateErrors
end
```

Or define it for all queries and mutations, using [middleware/3](https://hexdocs.pm/absinthe/Absinthe.Middleware.html#module-object-wide-authentication):
To handle errors for all fields, use [middleware/3](https://hexdocs.pm/absinthe/Absinthe.Middleware.html#module-object-wide-authentication):

```elixir
alias Crudry.Middlewares.TranslateErrors
Expand Down Expand Up @@ -97,11 +102,15 @@ end

Refer to the [TranslateErrors docs](https://hexdocs.pm/crudry/Crudry.Middlewares.TranslateErrors.html) for more information.

----

## Related Projects

* [Rajska](https://github.com/rschef/rajska) is an elixir authorization library for Absinthe.
* [Uploadex](https://github.com/gabrielpra1/uploadex) is an elixir library for handling uploads using Ecto and Arc

----

## License

MIT License.
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Crudry.MixProject do
def project do
[
app: :crudry,
version: "1.5.0",
version: "2.0.0",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
compilers: [:gettext] ++ Mix.compilers,
Expand Down

0 comments on commit df0baec

Please sign in to comment.