This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
admin-panel/graphql-types/node_modules/graphql-upload/public/Upload.js

76 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* A file expected to be uploaded as it has been declared in the `map` field of
* a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
* The [`processRequest`]{@link processRequest} function places references to an
* instance of this class wherever the file is expected in the
* [GraphQL operation]{@link GraphQLOperation}. The
* [`Upload` scalar]{@link GraphQLUpload} derives its value from the
* [`promise`]{@link Upload#promise} property.
* @kind class
* @name Upload
* @example <caption>Ways to `import`.</caption>
* ```js
* import { Upload } from 'graphql-upload';
* ```
*
* ```js
* import Upload from 'graphql-upload/public/Upload.js';
* ```
* @example <caption>Ways to `require`.</caption>
* ```js
* const { Upload } = require('graphql-upload');
* ```
*
* ```js
* const Upload = require('graphql-upload/public/Upload');
* ```
*/
module.exports = class Upload {
constructor() {
/**
* Promise that resolves file upload details. This should only be utilized
* by [`GraphQLUpload`]{@link GraphQLUpload}.
* @kind member
* @name Upload#promise
* @type {Promise<FileUpload>}
*/
this.promise = new Promise((resolve, reject) => {
/**
* Resolves the upload promise with the file upload details. This should
* only be utilized by [`processRequest`]{@link processRequest}.
* @kind function
* @name Upload#resolve
* @param {FileUpload} file File upload details.
*/
this.resolve = (file) => {
/**
* The file upload details, available when the
* [upload promise]{@link Upload#promise} resolves. This should only be
* utilized by [`processRequest`]{@link processRequest}.
* @kind member
* @name Upload#file
* @type {undefined|FileUpload}
*/
this.file = file;
resolve(file);
};
/**
* Rejects the upload promise with an error. This should only be
* utilized by [`processRequest`]{@link processRequest}.
* @kind function
* @name Upload#reject
* @param {object} error Error instance.
*/
this.reject = reject;
});
// Prevent errors crashing Node.js, see:
// https://github.com/nodejs/node/issues/20392
this.promise.catch(() => {});
}
};