{"id":13833590,"url":"https://github.com/Nickforall/Freight","last_synced_at":"2025-07-09T23:31:06.993Z","repository":{"id":55892174,"uuid":"148128225","full_name":"Nickforall/Freight","owner":"Nickforall","description":"🚚💨 Dynamically create Absinthe GraphQL payload objects for mutations","archived":false,"fork":false,"pushed_at":"2020-12-09T04:19:04.000Z","size":87,"stargazers_count":15,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-16T12:53:11.714Z","etag":null,"topics":["absinthe","elixir","graphql"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nickforall.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-10T09:05:32.000Z","updated_at":"2022-08-05T03:57:53.000Z","dependencies_parsed_at":"2022-08-15T08:50:19.749Z","dependency_job_id":null,"html_url":"https://github.com/Nickforall/Freight","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickforall%2FFreight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickforall%2FFreight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickforall%2FFreight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nickforall%2FFreight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nickforall","download_url":"https://codeload.github.com/Nickforall/Freight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225601465,"owners_count":17494818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["absinthe","elixir","graphql"],"created_at":"2024-08-04T12:00:51.492Z","updated_at":"2024-11-20T17:31:33.028Z","avatar_url":"https://github.com/Nickforall.png","language":"Elixir","funding_links":[],"categories":["Running the update"],"sub_categories":["By Popularity"],"readme":"# Freight\n\n![https://api.travis-ci.com/Nickforall/Freight.svg?branch=master](https://api.travis-ci.com/Nickforall/Freight.svg?branch=master)\n\nFreight is a library for [Absinthe GraphQL](http://absinthe-graphql.org/) that helps you build mutation payload results. Inspired by the GraphQL APIs of [GitHub](https://developer.github.com/v4/breaking_changes/) and [Shopify](https://gist.github.com/swalkinshaw/3a33e2d292b60e68fcebe12b62bbb3e2), who also aim to keep syntactical GraphQL errors, like missing fields and malformed queries, seperate from validation and other business logic errors.\n\nIt 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.\n\n## Configuration\n\nYou can set a custom error object that will be returned in the errors array in your payloads. This object must be defined in the schema you're calling `define_payload` from.\n\n```elixir\nconfig :freight,\n  error_object: :user_error\n  # whenever a field is snake-cased (like an ecto field for example), setting this to `true` will camelize it like Absinthe would\n  lower_camelize_field_name: true\n```\n\n## Usage\n\nBelow is a documented example of how to define Freight payloads in your schema\n\n```elixir\ndefmodule FreightDemo.Schema.Example do\n  use Absinthe.Schema.Notation\n\n  import Freight.Payload\n\n  object :user do\n    field(:name, :string)\n  end\n\n  object :comment do\n    field(:body, :string)\n    field(:author, :user)\n  end\n\n  define_payload(:create_comment_payload, author: :user, comment: :comment)\n\n  field :create_comment, type: :create_comment_payload do\n    arg(:body, non_null(:string))\n\n    resolve(\u0026FreightDemo.Resolver.create_comment/3)\n    middleware(\u0026build_payload/2)\n  end\nend\n```\n\nReturning errors works just like in Absinthe\n\n```elixir\ndefmodule FreightDemo.Resolver do\n  def create_comment(_parent, %{body: body}, _context) do\n    # your logic\n\n    {:ok, author: %{}, comment: %{}}\n  end\n\n  # OR\n\n  def create_comment(_parent, %{body: body}, _context) do\n    # your logic\n\n    {:error, \"Something went horribly wrong!\"}\n  end\nend\n```\n\nMore extensive documentation on defining errors can be found in the [documentation](https://hexdocs.pm/freight)\n\n## Installation\n\nAdd the following to your `mix.exs file`\n\n```elixir\ndef deps do\n  [\n    {:freight, \"~\u003e 0.4.0\"}\n  ]\nend\n```\n\nDocumentation can be found at [https://hexdocs.pm/freight](https://hexdocs.pm/freight).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNickforall%2FFreight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNickforall%2FFreight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNickforall%2FFreight/lists"}