Introduction
@requence/socketql is a Socket.IO-based GraphQL transport that provides real-time communication between server and client using live queries, subscriptions, and JSON diff-patching.
Installation
Section titled “Installation”npm install @requence/socketqlPackage Exports
Section titled “Package Exports”The library ships four entry points:
| Export Path | Description |
|---|---|
@requence/socketql/server | Server-side for Node.js: createServer with attach |
@requence/socketql/server/bun | Server-side for Bun: createServer with handler |
@requence/socketql/client | Client-side: createClient with URQL exchanges |
@requence/socketql/client/react | React hooks: useQuery, useMutation |
How It Works
Section titled “How It Works”- Server creates a Socket.IO namespace with a GraphQL execution layer
- Client connects via WebSocket and sends GraphQL operations through a custom URQL exchange
- Live queries are tracked with resource identifiers — when the server invalidates an identifier, all subscribed queries re-execute and the diff is pushed to clients
Quick Example
Section titled “Quick Example”// Server (Node.js)import { createServer } from '@requence/socketql/server'
const { addSchema, attach } = createServer({ path: '/ws/',})
addSchema({ typeDefs, resolvers })attach(httpServer)// Server (Bun)import { createServer } from '@requence/socketql/server/bun'
const { addSchema, handler } = createServer({ path: '/ws/',})
addSchema({ typeDefs, resolvers })
export default { port: 4000, ...handler() }// Clientimport { createClient } from '@requence/socketql/client'
const { client } = createClient({ path: '/ws/',})