@gsox/client
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

gsox-client

subscription client for consuming webhook data

Installation

npm i @gsox/client

React

import { createClient, StreamProvider, StreamConsumer } from "@gsox/client"

const client = createClient({ host, port, inject })

<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, inject })

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

Subscribe with GraphQL DocumentNode

import gql from "graphql-tag";

const query = gql`
  subscription {
    Alert {
      id
      timestamp
    }
  }
`
client.subscribeWithQuery(query, {
      next: data => console.log(data),
      error: error => console.log(error)
});

Options

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

Readme

Keywords

none

Package Sidebar

Install

npm i @gsox/client

Weekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

30.4 kB

Total Files

29

Last publish

Collaborators

  • amerani