ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - jungsoft/crudry: Elixir library for DRYing CRUD in Phoenix Contexts and Absinthe Resolvers.
Elixir library for DRYing CRUD in Phoenix Contexts and Absinthe Resolvers. - jungsoft/crudry
Visit Site

GitHub - jungsoft/crudry: Elixir library for DRYing CRUD in Phoenix Contexts and Absinthe Resolvers.

GitHub - jungsoft/crudry: Elixir library for DRYing CRUD in Phoenix Contexts and Absinthe Resolvers.

Crudry

Coverage Status

Crudry is an elixir library for DRYing CRUD of Phoenix Contexts and Absinthe Resolvers.

It also provides a simple middleware for translating changeset errors into readable messages.

Documentation can be found at https://hexdocs.pm/crudry.

The changelog can be found at the Releases page.

Installation

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

def deps do
  [
    {:crudry, "~> 2.4.0"},
  ]
end

Usage

Context Generation

To generate CRUD functions for a given schema in your context, simply do:

defmodule MyApp.MyContext do
  alias MyApp.Repo

  require Crudry.Context
  Crudry.Context.generate_functions MyApp.MySchema
end

To see the functions that are generated and custom options, refer to the Crudry.Context docs.

Resolver Generation

With the context all set up, the resolver is ready to be generated:

defmodule MyApp.MyResolver do
  alias MyApp.Repo

  require Crudry.Resolver
  Crudry.Resolver.generate_functions MyApp.MyContext, MyApp.MySchema
end

To see the functions that are generated and custom options, refer to the Crudry.Resolver docs.

Translate Errors middleware

Absinthe Middleware to translate errors and changeset errors into human readable messages. It support nested changeset errors and internationalization, using Gettext.

To handle errors for a field, add it after the resolve, using middleware/2:

alias Crudry.Middlewares.TranslateErrors

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

  resolve &UsersResolver.create_user/2
  middleware TranslateErrors
end

To handle errors for all fields, use middleware/3:

alias Crudry.Middlewares.TranslateErrors

def middleware(middleware, _field, _object) do
  middleware ++ [TranslateErrors]
end

Crudry.Translator is used by default to translate error messages to the default locale en. You can also use your own Gettext module by adding it to your Absinthe's schema context/1 function:

def context(context) do
  Map.put(context, :translator, MyAppWeb.Gettext)
end

Or just override the default locale in your Context Plug:

def call(conn, _) do
  Absinthe.Plug.put_options(conn, context: %{locale: "pt_BR"})
end

Refer to the TranslateErrors docs for more information.

Related Projects

  • Rajska is an elixir authorization library for Absinthe.
  • Uploadex is an elixir library for handling uploads using Ecto and Arc

License

MIT License.

See LICENSE for more information.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory