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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tachyon-relay

v32.0.0

Published

A Relay configuration for working with Twitch's GraphQL implementation.

Readme

Tachyon Relay

A top-level configuration of Relay for consuming GQL at Twitch. tachyon-relay-build is a recommended companion to using this package outside of the Tachyon monorepo.

Usage

This package has been tested with Next.js and Create React App, but should also work elsewhere. See the example consumer for a simple working example.

Configuration

Call configureTachyonRelay at the entry point to your app to ensure the runtime has the right options set:

  • browserRetry: Should the client retry failed fetches in the browser (default: true)
  • clientId: The Twitch API Client-Id value of the consuming app (required)
  • errorsArrayIsFatal: Callback for handling the appearance of an errors array. If no function is passed, then any errors will be treated as failed fetches in line with the current guidance from the API team. This function will receive a copy of the errors array and the GraphQL query string with which to determine whether the application can proceed with the errors as listed
  • gqlEndpoint: The Twitch API Client-Id value of the consuming app (default: https://gql.twitch.tv/gql)
  • serverFetchTimeout: Timeout limit (ms) for fetches on the server (default: 1500)

Debug Mode

Debug mode (enabled by passing debug: true in the config options) triggers a few changes to package functionality:

  • makes the relay store globally available at window.getTachyonRelayStore
  • prints extended error information to the debug console
  • prints services associated with a GQL query to the debug console
  • enables GQL service-failure emulation, via an array of services passed into config under the failServices key

Creating A Relay Environment

This packages exposes an initEnvironment function for generating a proper Relay environment for making GraphQL requests against the Twitch API. On the server, it will return a new environment every time for SSR safety. In the browser it will return the same environment on each call since it assumes the browser is not a multi-tenant environment.

Performing GQL Query Requests With Hooks

The simplest way to make requests is using the Relay Hooks API. This requires putting a RelayEnvironmentProvider in your app's root, and then using hooks like useLazyLoadQuery to perform fetches as needed. You'll need to ensure you have a Suspense boundary in your app as well, to handle loading states while the fetch is performed.

const App: FC = () => {
  const relayEnvironment = useConst(initEnvironment);

  return (
    <RelayEnvironmentProvider environment={relayEnvironment}>
      <Suspense fallback={<MySpinner />}>
        <Foo />
      </Suspense>
    </RelayEnvironmentProvider>
  );
};

const Foo: FC = () => {
  const data = useLazyLoadQuery(myQuery, myQueryVariables);

  return <Bar info={data?.info} />;
};

Performing GQL Query Request With TachyonQueryRenderer (deprecated)

Note: Use new Relay hooks instead.

Relay's default QueryRenderer isn't entirely optimized for SSR, so this package exposes TachyonQueryRenderer which uses a much more streamlined implementation on the server, but it does require a properly hydrated store for SSR rendering because it completely skips any network activity. Use fetchQuery from react-relay to do this.

The 'Authorization' header must be set to make requests that require user authentication. This is set by providing the authorization object, which has token which accepts a string literal or retrieval function, and unauthorizedHandler which is invoked before retrying the request when the GraphQL endpoint returns a 401 Unauthorized.

Working With Ids In Relay

Providing External Object IDs To Relay

Relay requires that all objects have a globally unique ID in order to enable efficient and safe caching behavior. Because Twitch's GQL implementation does not guarantee object IDs are unique (some even intentionally collide), we have a number of custom utilities to build sanitize external IDs being provided to Relay such as when using for Query Variables.

For a full list of these, see the convertToSafe<Type>ID functions in the idConversion module.

Providing Relay Object Ids To Other Systems

When consuming Relay Object Ids in other systems such as event tracking or link building, use the convertToUnsafeID utility.

Validating Response Objects

Use the isValidObject helper to validate that a GQL Object is not null and has a type narrowed, non-null, id field.

GraphQL Preconnect

In order to speed up your first request in an SSR app, this package exposes a <GraphqlPreconnect/> component that should be rendered into the head of your html on the server. This signals the browser to negotiate an HTTPS connection to our GraphQL API, speeding up the first request when it is actually made.

Request Info

If you need to retrieve the RequestInfo GraphQL object in an SSR app, there is a fully contained framework for exposing that without having to augment the rest of your queries.

To do this, add the following to the root of your app:

<RequestInfoRoot environment={relayEnvironment} />

Then use the withRequestInfo HOC or the useRequestInfo hook to access the data. This will only provide the data once on the client.