{"id":19731363,"url":"https://github.com/cargosense/absinthe_client","last_synced_at":"2025-12-12T00:27:49.850Z","repository":{"id":60876170,"uuid":"521445355","full_name":"CargoSense/absinthe_client","owner":"CargoSense","description":"A GraphQL client designed for Elixir Absinthe.","archived":false,"fork":false,"pushed_at":"2024-06-20T20:20:49.000Z","size":194,"stargazers_count":70,"open_issues_count":5,"forks_count":7,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-09-17T20:07:21.330Z","etag":null,"topics":["absinthe","absinthe-client","absinthe-graphql","absinthe-phoenix","elixir"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/absinthe_client","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/CargoSense.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2022-08-04T23:38:40.000Z","updated_at":"2024-06-26T20:10:44.000Z","dependencies_parsed_at":"2024-06-13T23:05:08.160Z","dependency_job_id":null,"html_url":"https://github.com/CargoSense/absinthe_client","commit_stats":null,"previous_names":["cargosense/absinthe_socket"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fabsinthe_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fabsinthe_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fabsinthe_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fabsinthe_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CargoSense","download_url":"https://codeload.github.com/CargoSense/absinthe_client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224193916,"owners_count":17271387,"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","absinthe-client","absinthe-graphql","absinthe-phoenix","elixir"],"created_at":"2024-11-12T00:20:34.946Z","updated_at":"2025-12-12T00:27:49.802Z","avatar_url":"https://github.com/CargoSense.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AbsintheClient\n\n[![CI](https://github.com/CargoSense/absinthe_client/actions/workflows/ci.yml/badge.svg)](https://github.com/CargoSense/absinthe_client/actions/workflows/ci.yml)\n[![Docs](https://img.shields.io/badge/hex.pm-docs-8e7ce6.svg)](https://hexdocs.pm/absinthe_client)\n[![Hex pm](http://img.shields.io/hexpm/v/absinthe_client.svg?style=flat\u0026color=brightgreen)](https://hex.pm/packages/absinthe_client)\n\nA GraphQL client designed for Elixir [Absinthe][absinthe].\n\n## Features\n\n- Performs `query` and `mutation` operations via JSON POST requests.\n\n- Performs `subscription` operations over WebSockets ([Absinthe Phoenix][absinthe_phoenix]).\n\n- Automatically re-establishes subscriptions on socket disconnect/reconnect.\n\n- Supports virtually all [`Req.request/1`][request] options, notably:\n\n  - Bearer authentication (via the [`auth`][req_auth] step).\n\n  - Retries on errors (via the [`retry`][req_retry] step).\n\n## Usage\n\nThe fastest way to use AbsintheClient is with [`Mix.install/2`][install] (requires Elixir v1.12+):\n\n```elixir\nMix.install([\n  {:absinthe_client, \"~\u003e 0.1.0\"}\n])\n\nReq.new(base_url: \"https://rickandmortyapi.com\")\n|\u003e AbsintheClient.attach()\n|\u003e Req.post!(graphql: \"query { character(id: 1) { name } }\").body\n#=\u003e %{\"data\" =\u003e \"character\" =\u003e %{\"name\" =\u003e \"Rick Sanchez\"}}}\n```\n\nIf you want to use AbsintheClient in a Mix project, you can add the above dependency to your list of dependencies in `mix.exs`.\n\nAbsintheClient is intended to be used by building a common client\nstruct with a `base_url` and re-using it on each operation:\n\n```elixir\nbase_url = \"https://rickandmortyapi.com\"\nreq = Req.new(base_url: base_url) |\u003e AbsintheClient.attach()\n\nReq.post!(req, graphql: \"query { character(id: 2) { name } }\").body\n#=\u003e %{\"data\" =\u003e \"character\" =\u003e %{\"name\" =\u003e \"Morty Smith\"}}}\n```\n\nRefer to [`AbsintheClient`][client] for more information on available options.\n\n### Subscriptions (WebSockets)\n\nAbsintheClient supports WebSocket operations via a custom Req adapter.\nYou must first start the WebSocket connection, then you make the\nrequest with [`Req.request/2`][request2]:\n\n```elixir\nbase_url = \"https://my-absinthe-server\"\nreq = Req.new(base_url: base_url) |\u003e AbsintheClient.attach()\n\nws = AbsintheClient.WebSocket.connect!(req, url: \"/socket/websocket\")\n\nReq.request!(req, web_socket: ws, graphql: \"subscription ...\").body\n#=\u003e %AbsintheClient.WebSocket.Subscription{}\n```\n\nNote that although AbsintheClient _can_ use the `:web_socket` option\nto execute all GraphQL operation types, in most cases it should\ncontinue to use HTTP for queries and mutations. This is because\nqueries and mutations do not require a stateful or long-lived\nconnection and depending on the number of concurrent requests it may\nbe more efficient to avoid blocking the socket for those operations.\n\nRefer to [`AbsintheClient.attach/2`][attach2] for more information on handling subscriptions.\n\n### Authentication\n\nAbsintheClient supports Bearer authentication for HTTP and WebSocket operations:\n\n```elixir\nbase_url = \"https://my-absinthe-server\"\nauth = {:bearer, \"token\"}\nreq = Req.new(base_url: base_url, auth: auth) |\u003e AbsintheClient.attach()\n\n# ?Authentication=Bearer+token will be sent on the connect request.\nws = AbsintheClient.WebSocket.connect(req, url: \"/socket/websocket\")\n```\n\nIf you use your client to authenticate then you can set `:auth` by\nmerging options:\n\n```elixir\nbase_url = \"https://my-absinthe-server\"\nreq = Req.new(base_url: base_url) |\u003e AbsintheClient.attach()\n\ndoc = \"mutation { login($input) { token } }\"\ngraphql = {doc, %{user: \"root\", password: \"\"}}\ntoken = Req.post!(req, graphql: graphql).body[\"data\"][\"login\"][\"token\"]\nreq = Req.Request.merge_options(req, auth: {:bearer, token})\n```\n\n## Why AbsintheClient?\n\nThere is another popular GraphQL library for Elixir called [Neuron][neuron].\nSo why choose AbsintheClient? In short, you might use AbsintheClient if you\nneed Absinthe Phoenix subscription support, if you want to avoid global\nconfiguration, and if you want to declaratively build your requests. For\ncomparison:\n\n|                    | AbsintheClient                                      | Neuron                                      |\n| ------------------ | --------------------------------------------------- | ------------------------------------------- |\n| **HTTP**           | [Req][req], [Finch][finch]                          | [HTTPoison][httpoison], [hackney][hackney]  |\n| **WebSockets**     | [Slipstream][slipstream], [Mint.WebSocket][mint_ws] | n/a                                         |\n| **Configuration**  | `%Req.Request{}`                                    | Application and Process-based               |\n| **Request style**  | Declarative, builds a struct                        | Imperative, invokes a function              |\n\n\n## Acknowledgements\n\nAbsintheClient is built on top of the [Req][req] requests library for HTTP and the [Slipstream][slipstream] WebSocket library for Phoenix Channels.\n\n## License\n\nMIT license. Copyright (c) 2019 Michael A. Crumm Jr., Ben Wilson\n\n[client]: https://hexdocs.pm/absinthe_client/AbsintheClient.html\n[websocket]: https://hexdocs.pm/absinthe_client/AbsintheClient.WebSocket.html\n[attach2]: https://hexdocs.pm/absinthe_client/AbsintheClient.html#attach/2-subscriptions\n[install]: https://hexdocs.pm/mix/Mix.html#install/2\n[absinthe]: https://github.com/absinthe-graphql/absinthe\n[absinthe_phoenix]: https://hexdocs.pm/absinthe_phoenix\n[req]: https://github.com/wojtekmach/req\n[request]: https://hexdocs.pm/req/Req.html#request/1\n[request2]: https://hexdocs.pm/req/Req.html#request/2\n[req_auth]: https://hexdocs.pm/req/Req.Steps.html#auth/1\n[req_retry]: https://hexdocs.pm/req/Req.Steps.html#retry/1\n[slipstream]: https://github.com/NFIBrokerage/slipstream\n[subscriptions]: https://hexdocs.pm/absinthe/subscriptions.html\n[neuron]: https://hexdocs.pm/neuron\n[finch]: https://github.com/sneako/finch\n[mint_ws]: https://github.com/elixir-mint/mint_web_socket\n[httpoison]: https://github.com/edgurgel/httpoison\n[hackney]: https://github.com/benoitc/hackney\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcargosense%2Fabsinthe_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcargosense%2Fabsinthe_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcargosense%2Fabsinthe_client/lists"}