{"id":19866129,"url":"https://github.com/tlux/graphql_ws_client","last_synced_at":"2025-05-02T05:32:19.234Z","repository":{"id":163146658,"uuid":"635398383","full_name":"tlux/graphql_ws_client","owner":"tlux","description":"An Elixir client for connecting with GraphQL over Websockets following the graphql-ws conventions","archived":false,"fork":false,"pushed_at":"2025-04-03T14:50:34.000Z","size":280,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T23:08:34.812Z","etag":null,"topics":["graphql","graphql-ws","websocket"],"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/tlux.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-05-02T15:56:45.000Z","updated_at":"2025-01-28T09:40:24.000Z","dependencies_parsed_at":"2024-03-31T02:35:19.462Z","dependency_job_id":null,"html_url":"https://github.com/tlux/graphql_ws_client","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fgraphql_ws_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fgraphql_ws_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fgraphql_ws_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fgraphql_ws_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tlux","download_url":"https://codeload.github.com/tlux/graphql_ws_client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251993002,"owners_count":21677022,"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":["graphql","graphql-ws","websocket"],"created_at":"2024-11-12T15:25:04.367Z","updated_at":"2025-05-02T05:32:14.225Z","avatar_url":"https://github.com/tlux.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Websocket Client\n\n[![Build](https://github.com/tlux/graphql_ws_client/actions/workflows/elixir.yml/badge.svg)](https://github.com/tlux/graphql_ws_client/actions/workflows/elixir.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tlux/graphql_ws_client/badge.svg?branch=main)](https://coveralls.io/github/tlux/graphql_ws_client?branch=main)\n[![Module Version](https://img.shields.io/hexpm/v/graphql_ws_client.svg)](https://hex.pm/packages/graphql_ws_client)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/graphql_ws_client/)\n[![License](https://img.shields.io/hexpm/l/graphql_ws_client.svg)](https://github.com/tlux/graphql_ws_client/blob/main/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/tlux/graphql_ws_client.svg)](https://github.com/tlux/graphql_ws_client/commits/main)\n\nAn extensible client for connecting with GraphQL over Websockets following the\n[graphql-ws](https://github.com/enisdenjo/graphql-ws) conventions.\n\n## Installation\n\nThe package can be installed by adding `graphql_ws_client` to your list of\ndependencies in `mix.exs`.\n\n```elixir\ndef deps do\n  [\n    {:graphql_ws_client, \"~\u003e 2.0\"},\n  ]\nend\n```\n\nIf you are using the default configuration, `GraphQLWSClient.Drivers.Gun` is\nused as driver and you will need the `gun` and `jason` packages as well.\n\n```elixir\ndef deps do\n  [\n    # ...\n    {:gun, \"~\u003e 2.1\"},\n    {:jason, \"~\u003e 1.4\"},\n  ]\nend\n```\n\nTake a\nlook in the driver documentation to find out how to customize driver options.\n\nAlternatively, you can write your own driver based on the\n`GraphQLWSClient.Driver` behaviour.\n\n## Usage\n\nConnect to a socket:\n\n```elixir\n{:ok, socket} = GraphQLWSClient.start_link(url: \"ws://localhost:4000/socket\")\n```\n\nSend a query or mutation and return the result immediately:\n\n```elixir\n{:ok, result} = GraphQLWSClient.query(socket, \"query GetPost { ... }\")\n```\n\nRegister a subscription to listen for events:\n\n```elixir\n{:ok, subscription_id} = GraphQLWSClient.subscribe(\n  socket,\n  \"subscription PostCreated { ... }\"\n)\n\nGraphQLWSClient.query!(socket, \"mutation CreatePost { ... }\")\n\nreceive do\n  %GraphQLWSClient.Event{type: :error, id: ^subscription_id, payload: error} -\u003e\n    IO.inspect(error, label: \"error\")\n  %GraphQLWSClient.Event{type: :next, id: ^subscription_id, payload: result} -\u003e\n    IO.inspect(result)\n  %GraphQLWSClient.Event{type: :complete, id: ^subscription_id} -\u003e\n    IO.puts(\"Stream closed\")\nend\n\nGraphQLClient.close(socket)\n```\n\nYou would usually put this inside of a custom `GenServer` and handle the events\nin `handle_info/3`.\n\nAlternatively, you can create a stream of results:\n\n```elixir\nsocket\n|\u003e GraphQLWSClient.stream!(\"subscription PostCreated { ... }\")\n|\u003e Stream.each(fn result -\u003e\n  IO.inspect(result)\nend)\n|\u003e Stream.run()\n```\n\n## Custom Client\n\nIf you want to run the client as part of a supervision tree in your\napplication, you can also `use GraphQLWSClient` to create your own client.\n\n```elixir\ndefmodule MyClient do\n  use GraphQLWSClient, otp_app: :my_app\nend\n```\n\nThen, you can configure your client using a config file:\n\n```elixir\nimport Config\n\nconfig :my_app, MyClient,\n  url: \"ws://localhost:4000/socket\"\n```\n\n## Docs\n\nDocumentation can be found at \u003chttps://hexdocs.pm/graphql_ws_client\u003e or\ngenerated locally using `mix docs`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlux%2Fgraphql_ws_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlux%2Fgraphql_ws_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlux%2Fgraphql_ws_client/lists"}