Client
The client module creates a Socket.IO-backed URQL client with custom exchanges for caching, invalidation, and live query support.
createClient
Section titled “createClient”import { createClient } from '@requence/socketql/client'
const { client, manager, invalidate } = createClient({ path: '/ws/', transports: ['websocket'],})Return Values
Section titled “Return Values”| Property | Description |
|---|---|
client | A configured URQL Client instance |
manager | The underlying Socket.IO Manager |
invalidate | Function to manually invalidate cached queries |
Authentication
Section titled “Authentication”Pass auth data on connect:
createClient({ onConnect: () => ({ token: getAccessToken(), }),})Cache Invalidation
Section titled “Cache Invalidation”Manually invalidate queries by operation name or document:
import { MyQueryDocument } from './generated'
// By operation nameinvalidate('MyQuery')
// By document nodeinvalidate(MyQueryDocument)
// Multiple at onceinvalidate(['QueryA', 'QueryB'])Built-in Exchanges
Section titled “Built-in Exchanges”The client automatically includes:
- holdSubscriptionExchange — delays teardown of live subscriptions by 500ms to prevent re-subscribe flicker during Suspense transitions
- emitExchange — emits result events for cross-component coordination via
waitForResult - cacheExchange — request-level cache that doesn’t auto-invalidate live queries
- subscriptionExchange — routes all operations through Socket.IO with JSON diff-patching