amerani / gsox

pub-sub framework built with graphql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gsox

framework for streaming data to browser and mobile clients using grapqhl subscriptions, websockets, and webhook

Installation

install all packages to existing project
npx gsox

install packages individually

npm install @gsox/schema
npm install @gsox/client
npm install @gsox/server

Schema

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

README

Client

consume/subscribe to one or more types

React

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>

Observable

import { createClient } from "@gsox/client"

const client = createClient({ host, port })

client.subscribe([Notification, MessageType], {
      next: data => console.log(data),
      error: error => console.log(error)
})

README

Server

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 🧦🧦🧦`))

README

WebSocket Endpoint

ws://host:port/graphql - publishes webhook body to client subscribers

Webhook Endpoint

http://host:port/webhook - accepts shape of your schema

options

{
  host: "localhost",
  port: 3000,
  routes: {
    graphql: "/graphql",
    webhook: "/webhook"
  },
  inject: [...types]
}

About

pub-sub framework built with graphql


Languages

Language:TypeScript 98.3%Language:JavaScript 1.7%