framework for streaming data to browser and mobile clients using grapqhl subscriptions, websockets, and webhook
install all packages to existing project
npx gsox
install packages individually
npm install @gsox/schema
npm install @gsox/client
npm install @gsox/server
describe your data types
import { Type, Field } from "@gsox/schema"
@Type()
class Notification {
@Field('Int')
id:number
@Field()
type:string
}
@Type()
class MessageType { ... }
const inject = [Notification, MessageType]
Supports both TypeScript and JavaScript decorators
consume/subscribe to one or more types
import { createClient, StreamProvider, StreamConsumer } from "@gsox/client"
const client = createClient({ host, port })
<StreamProvider client={client}>
<StreamConsumer types={[Notification]}>
{({ data, error, loading }) => {
if(loading) return <Loading />
if(data) return <DataView />
}}
</StreamConsumer>
</StreamProvider>
import { createClient } from "@gsox/client"
const client = createClient({ host, port })
client.subscribe([Notification, MessageType], {
next: data => console.log(data),
error: error => console.log(error)
})
inject data types and apply express middleware
import { applyMiddleware } from "@gsox/server"
const app = express()
const server = applyMiddleware(app, { host, port, inject })
server.listen(() => console.log(`gsox listening 🧦🧦🧦`))
ws://host:port/graphql
- publishes webhook body to client subscribers
http://host:port/webhook
- accepts shape of your schema
{
host: "localhost",
port: 3000,
routes: {
graphql: "/graphql",
webhook: "/webhook"
},
inject: [...types]
}