relay_network_bdt
v1.2.0
Published
relay Network package to build relay environment objects for Beyond Digital APIs
Downloads
207
Readme
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.