Kraken Js Kraken Js Save Abandoned

Real Serverless Graphql Experience with Realtime Powers!

Project README

@kraken.js

Real Serverless Graphql Experience with Realtime Powers!

continuous integration codecov

Instalation

npm i -g @kraken.js/cli

Usage

kraken new [--name|--version]
cd {name}
yarn dev

offline: Starting Offline: offline/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:4002
offline: route '$connect'
offline: route '$disconnect'
offline: route '$default'
offline: Offline [websocket] listening on ws://localhost:4001
offline: Offline [http for websocket] listening on http://localhost:4001

In Action

Check the demo project

The websocket protocol implementation is based on Apollo subscriptions-transport-ws

With this simple schema and an even simpler resolver

type Subscription {
    onPing(channel: String): Ping @sub(triggerName: "onPing#{channel}")
}

type Mutation {
    ping(channel: String!): Ping @pub(triggerNames: ["onPing#{channel}"])
}

type Ping {
    channel: String!
    timestamp: Float!
}
{
    Mutation: {
      ping: (_, args) => ({
        ...args,
        timestamp: Date.now()
      })
    }
  }

...and you are ready to use pubsub on serverless

wscat --connect ws://localhost:4001
# initialize the connection (required)
> {"type":"connection_init"}
< {"type":"connection_ack"}

# start a subscription
> {"type":"start", "id": "1", "payload":{"query":"subscription { onPing(channel: \"global\") { channel timestamp }}"}}

# publish to the subscription
> {"type":"start", "id": "2", "payload":{"query":"mutation { ping(channel: \"global\") { channel timestamp } }"}}

# subscription response
< {"id":"1","type":"data","payload":{"data":{"onPing":{"channel":"global","timestamp":1599781288309,"__typename":"Ping"}}}}

# mutation response
< {"id":"2","type":"data","payload":{"data":{"ping":{"channel":"global","timestamp":1599781288309}}}} # mutation response
< {"id":"2","type":"complete"}
Open Source Agenda is not affiliated with "Kraken Js Kraken Js" Project. README Source: kraken-js/kraken-js

Open Source Agenda Badge

Open Source Agenda Rating