ekobi

ekobi

Hi,

Many GraphQL clients implement subscriptions using the graphql-ws WebSockets subprotocol. I have been experimenting with adding support in Absinthe-based servers, and could use some help getting it over the finish line.

The basic idea is to define a separate mount point, e.g. /graphql-ws, which gets routed to a socket with a different JSON serializer:

  socket "/graphql-ws", GrapixDemo.UserSocket,
    websocket: [
      subprotocols: ["graphql-ws"],
      serializer: [{Grapix.GraphqlWS.V1.JSONSerializer, ">= 1.0.0"}]
    ],
    longpoll: false

What I can’t seem to figure out is how to inject the client-defined reference ID into the subscription data updates processed by fastlane!(%{Broadcast} = msg) in the serializer implementation:

  def fastlane!(%Broadcast{} = msg) do
    msg |> IO.inspect(label: "#{__MODULE__}/fastlane -- broadcast msg")

    # "1" should be client-defined refId
    data = phoenix2gql(nil, "1", msg.topic, msg.event, msg.payload.result)

    {:socket_push, :text, Phoenix.json_library().encode_to_iodata!(data)}
  end

I’m assuming that the Broadcast message omits the client-specific reference ID by design – it’s a broadcast, after all. But Absinthe clearly keeps track of per-client and per-subscription data with a unique topic:sub-topic identifier:

Elixir.Grapix.GraphqlWS.V1.JSONSerializer/fastlane -- broadcast msg: %Phoenix.Socket.Broadcast{
  event: "subscription:data",
  payload: %{
    result: %{
      data: %{
        "serviceStatus" => %{
          "__typename" => "ServiceStatus",
          "messages" => [
            %{
              "__typename" => "ServiceStatusMessage",
              "level" => "ADVISORY",
              "message" => "Wake up, dude!",
              "timestamp" => "2020-03-17T15:25:25.170999Z"
            }
          ]
        }
      }
    },
    subscriptionId: "__absinthe__:doc:73257102"
  },
  topic: "__absinthe__:doc:73257102"
}

Any thoughts on how to proceed? Thanks.

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews