relay_network_bdt

1.2.0 • Public • Published

relay-network

relay-network is a TypeScript package designed to build Relay environment objects for Beyond Digital APIs. It provides a set of middlewares and utilities to facilitate network operations in Relay.

Table of Contents

Installation

To install the package, use npm:

npm install relay_network_bdt

Usage

To create a Relay environment, use the EnvironmentBuilder function:

import EnvironmentBuilder from 'relay-network';

const environment = EnvironmentBuilder({
    url: 'https://api.example.com/graphql',
    apiToken: 'your-api-token',
    extraHeaders: {
        'X-Custom-Header': 'value'
    },
    networkOpts: {
        noThrow: true
    }
});

API

EnvironmentBuilder

The EnvironmentBuilder function creates a Relay environment with the specified middlewares and network options.

import EnvironmentBuilder from 'relay-network';

const environment = EnvironmentBuilder(props: MiddlewareBuilderProps): Environment;

MiddlewareBuilderProps

The MiddlewareBuilderProps interface defines the properties for building the middleware.

export interface MiddlewareBuilderProps {
    url: string;
    apiToken: string;
    token?: string;
    extraHeaders?: Record<string, string>;
    extraMiddleware?: Middleware[];
    networkOpts?: RelayNetworkLayerOpts;
}

Custom Events

The progressMiddleware emits a custom event named loadingProgress during the loading process. You can listen to this event as follows:

Web

window.addEventListener('loadingProgress', (event: CustomEvent) => {
    const { current, total } = event.detail;
    console.log(`Downloaded: ${current} B, total: ${total} B`);
});

React Native

import { DeviceEventEmitter } from 'react-native';

DeviceEventEmitter.addListener('loadingProgress', (data) => {
    const { current, total } = data;
    console.log(`Downloaded: ${current} B, total: ${total} B`);
});

Development

To build the project, run:

npm run build

To run tests, use:

npm test

License

This project is licensed under the MIT License. See the LICENSE file for details.

Readme

Keywords

none

Package Sidebar

Install

npm i relay_network_bdt

Weekly Downloads

3

Version

1.2.0

License

MIT

Unpacked Size

23.1 kB

Total Files

19

Last publish

Collaborators

  • jaex