Skip to content

Client

The client module creates a Socket.IO-backed URQL client with custom exchanges for caching, invalidation, and live query support.

import { createClient } from '@requence/socketql/client'
const { client, manager, invalidate } = createClient({
path: '/ws/',
transports: ['websocket'],
})
PropertyDescription
clientA configured URQL Client instance
managerThe underlying Socket.IO Manager
invalidateFunction to manually invalidate cached queries

Pass auth data on connect:

createClient({
onConnect: () => ({
token: getAccessToken(),
}),
})

Manually invalidate queries by operation name or document:

import { MyQueryDocument } from './generated'
// By operation name
invalidate('MyQuery')
// By document node
invalidate(MyQueryDocument)
// Multiple at once
invalidate(['QueryA', 'QueryB'])

The client automatically includes:

  1. holdSubscriptionExchange — delays teardown of live subscriptions by 500ms to prevent re-subscribe flicker during Suspense transitions
  2. emitExchange — emits result events for cross-component coordination via waitForResult
  3. cacheExchange — request-level cache that doesn’t auto-invalidate live queries
  4. subscriptionExchange — routes all operations through Socket.IO with JSON diff-patching