@os-team/relay-network-mw-upload-progress

The middleware for @os-team/relay-network-creator to track upload progress.
Usage
Step 1. Install the package
Install the package using the following command:
yarn add @os-team/relay-network-mw-upload-progress
Step 2. Add the middleware
import createRelayNetwork from '@os-team/relay-network-creator';
import uploadProgress from '@os-team/relay-network-mw-upload-progress';
createRelayNetwork({
url: 'https://api.domain.com/graphql',
middlewares: [uploadProgress],
});
Step 3. Pass the progress callback to mutation variables
const FileUpload: React.FC = () => {
const [progress, setProgress] = useState(0);
const [commit] = useMutation(graphql`
mutation FileUploadMutation($input: UploadFileInput!) {
uploadFile(input: $input) {
id
}
}
`);
const upload = useCallback(
(file: File) => {
commit({
variables: {
input: {
file: null,
onUploadProgress: ({ percent }) => setProgress(percent),
},
},
uploadables: {
file,
},
});
},
[commit]
);
return null; // Your component
};