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/server/redis | Redis adapter for multi-instance deployments |
@requence/socketql/client | Client-side: createClient setup |
@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 manages GraphQL operations transparently under the hood
- 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, defineSchema } from '@requence/socketql/server'
const mySchema = defineSchema({ typeDefs, resolvers })
const { attach } = createServer({ path: '/ws/', schemas: [mySchema],})
attach(httpServer)// Server (Bun)import { createServer, defineSchema } from '@requence/socketql/server/bun'
const mySchema = defineSchema({ typeDefs, resolvers })
const { handler } = createServer({ path: '/ws/', schemas: [mySchema],})
export default { port: 4000, ...handler() }// Clientimport { createClient } from '@requence/socketql/client'
const { client } = createClient({ path: '/ws/',})