Skip to content

Bridges the gap between Ecto and Absinthe for mutation payload

License

BSD-3-Clause, MIT licenses found

Licenses found

BSD-3-Clause
LICENSE.md
MIT
KRONKY_LICENSE.md
Notifications You must be signed in to change notification settings

herimedia/absinthe_error_payload

 
 

Repository files navigation



Bridges the gap between Ecto and Absinthe GraphQL
by listing validation messages in a mutation payload.

The primary philosophy is that messages generated by invalid and/or unexpected user input are DATA, and should be returned as such. On the other hand, errors made in using an API - like querying a field that doesn’t exist -, are actually ERRORS and should be returned as errors.

GraphQL fits perfectly here. Error are handled explicitly in the query and actual errors are treated as internal error on client side library.

Installation

Install by adding absinthe_error_payload to your list of dependencies in mix.exs:

def deps do
  [
    {:absinthe_error_payload, "~> 1.0"}
  ]
end

Usage

The best place to find usage examples is by looking at the test cases at the AbsintheErrorPayload GitHub or the docs for AbsintheErrorPayload.Payload

Here’s a quick summary of what AbsintheErrorPayload includes

AbsintheErrorPayload.ValidationMessage structs/objects are created with all the information you’d normally be able to access through Ecto.Changeset.traverse_errors/2.

AbsintheErrorPayload includes a schema definition to add ValidationMessages to your schema.

AbsintheErrorPayload.Payload is middleware that takes your resolver output (either an updated object or a changeset with errors) and converts it into a AbsintheErrorPayload Mutation Response (aka Payload).

Payloads have three fields

  • successful - Indicates if the mutation completed successfully or not. Boolean.
  • messages - a list of validation errors. Always empty on success
  • result - the data object that was created/updated/deleted on success. Always nil when unsuccessful.

Finally AbsintheErrorPayload.TestHelper has some helper methods that make it easier to write ExUnit tests against your schema.

Hey, this looks like Kronky!

This library has been forked from Kronky, renamed to AbsintheErrorPayload and published on hexpm. Kronky was not being updated and while it still worked for older versions, a more maintained release was requested by many users.

Thank you Ethelo for the awesome library!

License

AbsintheErrorPayload is © 2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

As mentionned above, AbsintheErrorPayload is based on Kronky which is licensed under the MIT license. See the KRONKY_LICENSE.md file.

The flask logo is based on this lovely icon by Danil Polshin, from The Noun Project. Used under a Creative Commons BY 3.0 license.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We’re a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

About

Bridges the gap between Ecto and Absinthe for mutation payload

Resources

License

BSD-3-Clause, MIT licenses found

Licenses found

BSD-3-Clause
LICENSE.md
MIT
KRONKY_LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 97.3%
  • Makefile 1.5%
  • Shell 1.2%