npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mattkrick/graphql-trebuchet-client

v2.2.1

Published

A graphql client to get your subscriptions through tough firewalls and unreliable mobile networks

Downloads

330

Readme

graphql-trebuchet-client

A graphql client to get your subscriptions through tough firewalls and unreliable mobile networks

Why?

GraphQL subscriptions are important. Some corporate firewalls block long-running requests like WebSockets. This gets through them, one way or another.

What's it do?

  • This is just a GraphQL protocol layer, which sits on top of the connection layer
  • Keeps track of your fetches & subscriptions
  • Resubscribes when the connection is ended prematurely
  • Supports multiple responses for the same fetch, allowing for partial resutls using e.g. @defer

How's it different from other graphql client libs?

  • This lib won't fail silently when WebSockets fail
  • This lib has a pure separation of concerns between connectivity & GraphQL messages
  • Other libs do too much so they can lock you into their monolithic trap (don't get got!)
  • Supports enforced casual ordering

What's the protocol?

From the client:

  • An operations MAY have an id string
  • If id is provided, the server MUST reply, else it MAY not (e.g. analytics mutation)
  • An operation has a type, and payload
  • The type MUST be start or stop
  • a start payload MAY include a query param, or a documentId param (for persisted queries)
  • a stop operation MUST include the id of the operation to unsubscribe from
  • The client MUST send a single operation (batching is left up to the transport)

From the server:

  • An operation has an id, type, and payload
  • The id MUST match the id of the request
  • The type MUST be data, error, or complete
  • The payload MUST be a GraphQLResult ({data, errors})
  • If the type is data, the client MUST call sink.next
  • If the type is error, the client MUST call sink.error with an Error instance
  • If the type is complete, the client MUST call sink.next iif a payload is present and call sink.complete after

API

These are the methods you'll probably want to call.

  • fetch({query, cacheConfig, variables}, sink): Call this for all queries/mutations
  • subscribe({query, variables}, sink): Disposable: Call this to start a subscription. Call the return value to stop it.
  • close(): Unsubscribe from everything and prevent a reconnect. Useful for logouts.

Example

import getTrebuchet, {SocketTrebuchet, SSETrebuchet} from '@mattkrick/trebuchet-client'
import GQLTrebuchetClient, {GQLHTTPClient} from '@mattkrick/graphql-trebuchet-client'

// you can use a plain old websocket here if you don't want to use trebuchet-client.
const trebuchet = await getTrebuchet(settings)
const transport = new GQLTrebuchetClient(trebuchet)
const myFetch = (query, variables) => {
  // If 2 mutations with the same casualOrderingGroup get called in order A,B,
  // then the server response for A is guaranteed to get dispatched before B
  const cacheConfig = {metadata: {casualOrderingGroup: 'orderedStochasticMutations'}}
  // note using a promise is easy to get started, but means you can't return multiple responses
  return new Promise((resolve, reject) => {
    return transport.fetch({query, cacheConfig, variables}, {
      next(result): {
        resolve(result)
      },
      error(error): {
        reject(error)
      },
      complete(maybeResult): {
        resolve(result)
      }
    })
  })

transport.subscribe({query, variables}, subSink)