UNPKG

overmind-graphql

Version:
50 lines (49 loc) 1.46 kB
import { Socket as PhoenixSocket, Channel } from 'phoenix'; /** * Custom Absinthe Socket implementation * * This replaces the abandoned @absinthe/socket package with a direct * implementation using Phoenix Channels. It provides the same API for * working with Absinthe GraphQL subscriptions over Phoenix. * * Absinthe uses Phoenix channels for subscriptions, which is different * from the standard GraphQL WebSocket protocol. */ export interface AbsintheSocket { phoenixSocket: PhoenixSocket; channel: Channel; subscriptions: Map<string, any>; } export interface Notifier { subscriptionId: string; absintheSocket: AbsintheSocket; } export interface Observer { subscriptionId: string; ref: number; } export declare const absintheSocket: { /** * Create an Absinthe socket wrapper around a Phoenix socket */ create(phoenixSocket: PhoenixSocket): AbsintheSocket; /** * Send a GraphQL subscription request */ send(absintheSocket: AbsintheSocket, request: { operation: string; variables?: any; }): Notifier; /** * Observe subscription results */ observe(absintheSocket: AbsintheSocket, notifier: Notifier, callbacks: { onResult: (result: { data: any; }) => void; }): Observer; /** * Unsubscribe and clean up */ unobserve(absintheSocket: AbsintheSocket, notifier: Notifier, observer: Observer): void; };