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.
To install the package, use npm:
npm install relay_network_bdt
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
}
});
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;
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;
}
The progressMiddleware
emits a custom event named loadingProgress
during the loading process. You can listen to this event as follows:
window.addEventListener('loadingProgress', (event: CustomEvent) => {
const { current, total } = event.detail;
console.log(`Downloaded: ${current} B, total: ${total} B`);
});
import { DeviceEventEmitter } from 'react-native';
DeviceEventEmitter.addListener('loadingProgress', (data) => {
const { current, total } = data;
console.log(`Downloaded: ${current} B, total: ${total} B`);
});
To build the project, run:
npm run build
To run tests, use:
npm test
This project is licensed under the MIT License. See the LICENSE file for details.