1.2.0 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform
Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.
BSD-3-Clause - BSD 3-Clause "New" or "Revised" License
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.
Install by adding absinthe_error_payload
to your list of dependencies in mix.exs
:
def deps do
[
{:absinthe_error_payload, "~> 1.0"}
]
end
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 successresult
- 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.
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!
AbsintheErrorPayload is © 2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md
file.
As mentioned 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.
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.