Server
The server module creates a Socket.IO server with a full GraphQL execution pipeline, including live query support and schema transformation.
createServer
Section titled “createServer”import { createServer } from '@requence/socketql/server'
const { server, namespace, liveQueryStore, attach, addSchema } = createServer({ path: '/ws/', transports: ['websocket'], redisUrl: 'redis://localhost:6379',})Adding Schemas
Section titled “Adding Schemas”Use addSchema to register GraphQL type definitions and resolvers:
addSchema({ typeDefs: /* GraphQL */ ` type Query { hello: String! @live } `, resolvers: { Query: { hello: () => 'world', }, },})Attaching to a Server
Section titled “Attaching to a Server”Node.js
Section titled “Node.js”import { createServer as createHTTPServer } from 'node:http'
const httpServer = createHTTPServer()attach(httpServer)httpServer.listen(4000)Import from @requence/socketql/server/bun instead — it replaces attach with a handler() method:
import { createServer } from '@requence/socketql/server/bun'
const { addSchema, handler } = createServer({ path: '/ws/' })
addSchema({ typeDefs, resolvers })
export default { port: 4000, ...handler() }Context Extension
Section titled “Context Extension”Extend the GraphQL context per connection:
createServer({ extendContext: ({ socket }) => ({ userId: socket.handshake.auth.userId, }),})Lifecycle Hooks
Section titled “Lifecycle Hooks”createServer({ onConnect: (socket) => { console.log('connected:', socket.id) }, onDisconnect: (socket, reason) => { console.log('disconnected:', socket.id, reason) },})