{"id":27770829,"url":"https://github.com/rudebono/absinthe_one_of","last_synced_at":"2025-06-19T12:35:38.677Z","repository":{"id":239779052,"uuid":"800368772","full_name":"rudebono/absinthe_one_of","owner":"rudebono","description":"Support an Input Union Type System Directive in Absinthe.","archived":false,"fork":false,"pushed_at":"2024-05-15T13:52:19.000Z","size":23,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T06:34:17.873Z","etag":null,"topics":["absinthe","elixir","phoenix"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/absinthe_one_of","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/rudebono.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-14T07:46:49.000Z","updated_at":"2025-04-06T17:44:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"d27894f5-ff3d-4031-a3cc-4f5491e18b38","html_url":"https://github.com/rudebono/absinthe_one_of","commit_stats":null,"previous_names":["rudebono/absinthe_one_of"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rudebono/absinthe_one_of","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudebono%2Fabsinthe_one_of","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudebono%2Fabsinthe_one_of/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudebono%2Fabsinthe_one_of/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudebono%2Fabsinthe_one_of/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rudebono","download_url":"https://codeload.github.com/rudebono/absinthe_one_of/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudebono%2Fabsinthe_one_of/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260752191,"owners_count":23057313,"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","phoenix"],"created_at":"2025-04-29T21:17:53.873Z","updated_at":"2025-06-19T12:35:33.664Z","avatar_url":"https://github.com/rudebono.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/rudebono/absinthe_one_of/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/rudebono/absinthe_one_of/actions/workflows/ci.yaml)\n\n# Absinthe one_of\n\nSupport an Input Union Type System Directive in Absinthe.\n\n## Inspiration\n\nThis package was inspired by an article written by [Maarten Van Vliet](https://github.com/maartenvanvliet).\n\nYou can read the original article [Creating an Input Union Type System Directive in Absinthe](https://maartenvanvliet.nl/2022/04/28/absinthe_input_union/).\n\n## Key Improvements\n\n- **Nested Objects**: Allows for `one_of` validation within nested object structures.\n- **Nested List Objects**: Supports `one_of` validation within nested lists of objects.\n\n## Installation\n\nAdd `:absinthe_one_of` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps() do\n  [\n    {:absinthe_one_of, \"~\u003e 1.1\"}\n  ]\nend\n```\n\n## Usage\n\n### Step 1: Define Schema\n\nCreate a schema module and define your types, including the `@prototype_schema AbsintheOneOf.Directive`:\n\n```elixir\ndefmodule YourWebApp.Schema do\n  use Absinthe.Schema\n\n  @prototype_schema AbsintheOneOf.Directive\n\n  query do\n    ...\n  end\n\n  mutation do\n    ...\n  end\n\n  subscription do\n    ...\n  end\n\n  ...\n\n  input_object(:one_of_input) do\n    directive(:one_of)\n    field(:a, :a_input)\n    field(:b, :b_input)\n  end\n\n  input_object(:a_input) do\n    ...\n  end\n\n  input_object(:b_input) do\n    ...\n  end\nend\n```\n\n### Step 2: Setup Absinthe Pipeline\n\nConfigure the Absinthe pipeline to include the `absinthe_one_of` phase:\n\n```elixir\ndefmodule YourWebApp.Endpoint do\n  use YourWebApp, :router\n\n  ...\n\n  def pipeline(config, pipeline_opts) do\n    config.schema_mod\n    |\u003e Absinthe.Pipeline.for_document(pipeline_opts)\n    |\u003e Absinthe.Pipeline.insert_after(\n      Absinthe.Phase.Document.Validation.OnlyOneSubscription,\n      AbsintheOneOf.Phase\n    )\n  end\nend\n```\n\n### Step 3: Testing\n\nTo write tests for your implementation, you can refer to the example tests provided in `test/absinthe_one_of_test.exs`. These tests demonstrate how to validate the functionality of the one_of directive and ensure that only one field is non-null among several options.\n\n## License\n\nThis project is licensed under the MIT License - see the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudebono%2Fabsinthe_one_of","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frudebono%2Fabsinthe_one_of","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudebono%2Fabsinthe_one_of/lists"}