Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-upload-client

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-upload-client - npm Package Compare versions

Comparing version 12.1.0 to 13.0.0

33

changelog.md
# apollo-upload-client changelog
## 13.0.0
### Major
- Updated Node.js support from v8.10+ to v10+.
- Updated dependencies, some of which require Node.js v10+.
### Minor
- Support uploading files from a server environment, fixing [#172](https://github.com/jaydenseric/apollo-upload-client/issues/172) via [#179](https://github.com/jaydenseric/apollo-upload-client/pull/179) and [#184](https://github.com/jaydenseric/apollo-upload-client/pull/184).
- Added `createUploadLink` options:
- `isExtractableFile`
- `FormData`
- `formDataAppendFile`
- Added exports for the new `createUploadLink` option defaults:
- `isExtractableFile`
- `formDataAppendFile`
### Patch
- Removed the now redundant [`eslint-plugin-import-order-alphabetical`](https://npm.im/eslint-plugin-import-order-alphabetical) dev dependency.
- Added a [`size-limit`](https://npm.im/size-limit) dev dependency.
- Stop using [`husky`](https://npm.im/husky) and [`lint-staged`](https://npm.im/lint-staged).
- Ensure GitHub Actions CI runs for pull requests.
- Use strict mode for scripts.
- Move Babel config from `babel.config.js` to `src/.babelrc.json`.
- Improved the package `prepare:prettier` and `test:prettier` scripts.
- Configured Prettier option `semi` to the default, `true`.
- Removed `package-lock.json` from `.gitignore` and `.prettierignore` as it’s disabled in `.npmrc` anyway.
- Updated external documentation link URLs.
- Replaced “Apollo Engine” with “Apollo Graph Manager” in comments.
- Improved the examples in the readme.
## 12.1.0

@@ -4,0 +37,0 @@

154

lib/index.js

@@ -1,12 +0,12 @@

'use strict'
'use strict';
var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault')
var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');
var _extends2 = _interopRequireDefault(
require('@babel/runtime/helpers/extends')
)
);
var _require = require('apollo-link'),
ApolloLink = _require.ApolloLink,
Observable = _require.Observable
Observable = _require.Observable;

@@ -19,38 +19,56 @@ var _require2 = require('apollo-link-http-common'),

createSignalIfSupported = _require2.createSignalIfSupported,
parseAndCheckHttpResponse = _require2.parseAndCheckHttpResponse
parseAndCheckHttpResponse = _require2.parseAndCheckHttpResponse;
var _require3 = require('extract-files'),
extractFiles = _require3.extractFiles,
ReactNativeFile = _require3.ReactNativeFile
isExtractableFile = _require3.isExtractableFile,
ReactNativeFile = _require3.ReactNativeFile;
exports.ReactNativeFile = ReactNativeFile
exports.ReactNativeFile = ReactNativeFile;
exports.isExtractableFile = isExtractableFile;
exports.createUploadLink = function(_temp) {
function formDataAppendFile(formData, fieldName, file) {
formData.append(fieldName, file, file.name);
}
exports.formDataAppendFile = formDataAppendFile;
exports.createUploadLink = function (_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$uri = _ref.uri,
fetchUri = _ref$uri === void 0 ? '/graphql' : _ref$uri,
_ref$fetch = _ref.fetch,
linkFetch = _ref$fetch === void 0 ? fetch : _ref$fetch,
_ref$isExtractableFil = _ref.isExtractableFile,
customIsExtractableFile =
_ref$isExtractableFil === void 0
? isExtractableFile
: _ref$isExtractableFil,
CustomFormData = _ref.FormData,
_ref$formDataAppendFi = _ref.formDataAppendFile,
customFormDataAppendFile =
_ref$formDataAppendFi === void 0
? formDataAppendFile
: _ref$formDataAppendFi,
customFetch = _ref.fetch,
fetchOptions = _ref.fetchOptions,
credentials = _ref.credentials,
headers = _ref.headers,
includeExtensions = _ref.includeExtensions
includeExtensions = _ref.includeExtensions;
var linkConfig = {
http: {
includeExtensions: includeExtensions
includeExtensions: includeExtensions,
},
options: fetchOptions,
credentials: credentials,
headers: headers
}
return new ApolloLink(function(operation) {
var uri = selectURI(operation, fetchUri)
var context = operation.getContext()
var _context$clientAwaren = context.clientAwareness
headers: headers,
};
return new ApolloLink(function (operation) {
var uri = selectURI(operation, fetchUri);
var context = operation.getContext();
var _context$clientAwaren = context.clientAwareness;
_context$clientAwaren =
_context$clientAwaren === void 0 ? {} : _context$clientAwaren
_context$clientAwaren === void 0 ? {} : _context$clientAwaren;
var name = _context$clientAwaren.name,
version = _context$clientAwaren.version,
headers = context.headers
headers = context.headers;
var contextConfig = {

@@ -63,12 +81,12 @@ http: context.http,

name && {
'apollographql-client-name': name
'apollographql-client-name': name,
},
{},
version && {
'apollographql-client-version': version
'apollographql-client-version': version,
},
{},
headers
)
}
),
};

@@ -82,63 +100,65 @@ var _selectHttpOptionsAnd = selectHttpOptionsAndBody(

options = _selectHttpOptionsAnd.options,
body = _selectHttpOptionsAnd.body
body = _selectHttpOptionsAnd.body;
var _extractFiles = extractFiles(body),
var _extractFiles = extractFiles(body, '', customIsExtractableFile),
clone = _extractFiles.clone,
files = _extractFiles.files
files = _extractFiles.files;
var payload = serializeFetchParameter(clone, 'Payload')
var payload = serializeFetchParameter(clone, 'Payload');
if (files.size) {
delete options.headers['content-type']
var form = new FormData()
form.append('operations', payload)
var map = {}
var i = 0
files.forEach(function(paths) {
map[++i] = paths
})
form.append('map', JSON.stringify(map))
i = 0
files.forEach(function(paths, file) {
form.append(++i, file, file.name)
})
options.body = form
} else options.body = payload
delete options.headers['content-type'];
var RuntimeFormData = CustomFormData || FormData;
var form = new RuntimeFormData();
form.append('operations', payload);
var map = {};
var i = 0;
files.forEach(function (paths) {
map[++i] = paths;
});
form.append('map', JSON.stringify(map));
i = 0;
files.forEach(function (paths, file) {
customFormDataAppendFile(form, ++i, file);
});
options.body = form;
} else options.body = payload;
return new Observable(function(observer) {
var abortController
return new Observable(function (observer) {
var abortController;
if (!options.signal) {
var _createSignalIfSuppor = createSignalIfSupported(),
controller = _createSignalIfSuppor.controller
controller = _createSignalIfSuppor.controller;
if (controller) {
abortController = controller
options.signal = abortController.signal
abortController = controller;
options.signal = abortController.signal;
}
}
linkFetch(uri, options)
.then(function(response) {
var runtimeFetch = customFetch || fetch;
runtimeFetch(uri, options)
.then(function (response) {
operation.setContext({
response: response
})
return response
response: response,
});
return response;
})
.then(parseAndCheckHttpResponse(operation))
.then(function(result) {
observer.next(result)
observer.complete()
.then(function (result) {
observer.next(result);
observer.complete();
})
.catch(function(error) {
if (error.name === 'AbortError') return
.catch(function (error) {
if (error.name === 'AbortError') return;
if (error.result && error.result.errors && error.result.data)
observer.next(error.result)
observer.error(error)
})
return function() {
if (abortController) abortController.abort()
}
})
})
}
observer.next(error.result);
observer.error(error);
});
return function () {
if (abortController) abortController.abort();
};
});
});
};
{
"name": "apollo-upload-client",
"version": "12.1.0",
"version": "13.0.0",
"description": "A terminating Apollo Link for Apollo Client that allows FileList, File, Blob or ReactNativeFile instances within query or mutation variables and sends GraphQL multipart requests.",

@@ -33,31 +33,29 @@ "license": "MIT",

"engines": {
"node": ">=8.10"
"node": ">=10"
},
"browserslist": "Node >= 8.10, > 0.5%, not OperaMini all, not dead",
"browserslist": "Node >= 10, > 0.5%, not OperaMini all, not dead",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@babel/runtime": "^7.9.2",
"apollo-link": "^1.2.12",
"apollo-link-http-common": "^0.2.14",
"extract-files": "^5.0.1"
"extract-files": "^8.0.0"
},
"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.4",
"@babel/plugin-transform-runtime": "^7.5.0",
"@babel/preset-env": "^7.5.4",
"@size-limit/preset-small-lib": "^2.2.1",
"babel-eslint": "^10.0.2",
"eslint": "^6.0.1",
"eslint-config-env": "^11.0.1",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-import-order-alphabetical": "^1.0.0",
"eslint-plugin-jsdoc": "^18.1.5",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.0",
"graphql": "^14.4.2",
"husky": "^3.0.0",
"jsdoc-md": "^4.0.1",
"lint-staged": "^9.1.0",
"prettier": "^1.18.2"
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@size-limit/preset-small-lib": "^4.4.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-env": "^13.0.4",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsdoc": "^22.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.2",
"graphql": "^14.6.0",
"jsdoc-md": "^5.0.1",
"prettier": "^2.0.2",
"size-limit": "^4.4.2"
},

@@ -69,6 +67,6 @@ "scripts": {

"prepare:jsdoc": "jsdoc-md",
"prepare:prettier": "prettier 'lib/**/*.js' readme.md --write",
"prepare:prettier": "prettier --write lib readme.md",
"test": "npm run test:eslint && npm run test:prettier && npm run test:size",
"test:eslint": "eslint .",
"test:prettier": "prettier '**/*.{json,yml,md}' -l",
"test:prettier": "prettier -c .",
"test:size": "size-limit",

@@ -75,0 +73,0 @@ "prepublishOnly": "npm test"

@@ -7,3 +7,3 @@ ![Apollo upload logo](https://cdn.jsdelivr.net/gh/jaydenseric/apollo-upload-client@1.0.0/apollo-upload-logo.svg)

A terminating [Apollo Link](https://apollographql.com/docs/link) for [Apollo Client](https://apollographql.com/docs/link#apollo-client) that allows [`FileList`](https://developer.mozilla.org/docs/web/api/filelist), [`File`](https://developer.mozilla.org/docs/web/api/file), [`Blob`](https://developer.mozilla.org/docs/web/api/blob) or [`ReactNativeFile`](#class-reactnativefile) instances within query or mutation variables and sends [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec).
A terminating [Apollo Link](https://apollographql.com/docs/link) for [Apollo Client](https://apollographql.com/docs/link/#apollo-client) that allows [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`ReactNativeFile`](#class-reactnativefile) instances within query or mutation variables and sends [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec).

@@ -18,5 +18,5 @@ ## Setup

[Apollo Boost](https://npm.im/apollo-boost) doesn’t allow link customization; if you are using it [migrate to a manual Apollo Client setup](https://apollographql.com/docs/react/advanced/boost-migration).
[Apollo Boost](https://npm.im/apollo-boost) doesn’t allow link customization; if you are using it [migrate to a manual Apollo Client setup](https://apollographql.com/docs/react/migrating/boost-migration).
[Apollo Client](https://apollographql.com/docs/link#apollo-client) can only have 1 “terminating” [Apollo Link](https://apollographql.com/docs/link) that sends the GraphQL requests; if one such as [`apollo-link-http`](https://apollographql.com/docs/link/links/http) is already setup, remove it.
[Apollo Client](https://apollographql.com/docs/link/#apollo-client) can only have 1 “terminating” [Apollo Link](https://apollographql.com/docs/link) that sends the GraphQL requests; if one such as [`apollo-link-http`](https://apollographql.com/docs/link/links/http) is already setup, remove it.

@@ -29,11 +29,11 @@ Initialize the client with a terminating link using [`createUploadLink`](#function-createuploadlink).

Use [`FileList`](https://developer.mozilla.org/docs/web/api/filelist), [`File`](https://developer.mozilla.org/docs/web/api/file), [`Blob`](https://developer.mozilla.org/docs/web/api/blob) or [`ReactNativeFile`](#class-reactnativefile) instances anywhere within query or mutation variables to send a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
Use [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`ReactNativeFile`](#class-reactnativefile) instances anywhere within query or mutation variables to send a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
See also the [example API and client](https://github.com/jaydenseric/apollo-upload-examples).
### [`FileList`](https://developer.mozilla.org/docs/web/api/filelist)
### [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList)
```jsx
const { useMutation } = require('@apollo/react-hooks')
const gql = require('graphql-tag')
const { useMutation } = require('@apollo/react-hooks');
const gql = require('graphql-tag');

@@ -46,18 +46,20 @@ const MUTATION = gql`

}
`
`;
const UploadFile = () => {
const [mutate] = useMutation(MUTATION)
const onChange = ({ target: { validity, files } }) =>
validity.valid && mutate({ variables: { files } })
function UploadFiles() {
const [mutate] = useMutation(MUTATION);
return <input type="file" multiple required onChange={onChange} />
function onChange({ target: { validity, files } }) {
if (validity.valid) mutate({ variables: { files } });
}
return <input type="file" multiple required onChange={onChange} />;
}
```
### [`File`](https://developer.mozilla.org/docs/web/api/file)
### [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File)
```jsx
const { useMutation } = require('@apollo/react-hooks')
const gql = require('graphql-tag')
const { useMutation } = require('@apollo/react-hooks');
const gql = require('graphql-tag');

@@ -70,40 +72,50 @@ const MUTATION = gql`

}
`
`;
const UploadFile = () => {
const [mutate] = useMutation(MUTATION)
const onChange = ({
function UploadFile() {
const [mutate] = useMutation(MUTATION);
function onChange({
target: {
validity,
files: [file]
}
}) => validity.valid && mutate({ variables: { file } })
files: [file],
},
}) {
if (validity.valid) mutate({ variables: { file } });
}
return <input type="file" required onChange={onChange} />
return <input type="file" required onChange={onChange} />;
}
```
### [`Blob`](https://developer.mozilla.org/docs/web/api/blob)
### [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
```jsx
const gql = require('graphql-tag')
const { useMutation } = require('@apollo/react-hooks');
const gql = require('graphql-tag');
// Apollo Client instance.
const client = require('./client')
const MUTATION = gql`
mutation($file: Upload!) {
uploadFile(file: $file) {
success
}
}
`;
const file = new Blob(['Foo.'], { type: 'text/plain' })
function UploadFile() {
const [mutate] = useMutation(MUTATION);
// Optional, defaults to `blob`.
file.name = 'bar.txt'
function onChange({ target: { validity, value } }) {
if (validity.valid) {
const file = new Blob([value], { type: 'text/plain' });
client.mutate({
mutation: gql`
mutation($file: Upload!) {
uploadFile(file: $file) {
success
}
// Optional, defaults to `blob`.
file.name = 'text.txt';
mutate({ variables: { file } });
}
`,
variables: { file }
})
}
return <input type="text" required onChange={onChange} />;
}
```

@@ -113,3 +125,3 @@

- Node.js v8.10+
- Node.js v10+
- Browsers [`> 0.5%, not OperaMini all, not dead`](https://browserl.ist/?q=%3E+0.5%25%2C+not+OperaMini+all%2C+not+dead)

@@ -120,5 +132,5 @@ - React Native

- [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
- [`fetch`](https://developer.mozilla.org/docs/Web/API/Fetch_API)
- [`FormData`](https://developer.mozilla.org/docs/Web/API/FormData)
- [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
- [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
- [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)

@@ -131,3 +143,7 @@ ## API

- [function createUploadLink](#function-createuploadlink)
- [function formDataAppendFile](#function-formdataappendfile)
- [function isExtractableFile](#function-isextractablefile)
- [type ExtractableFileMatcher](#type-extractablefilematcher)
- [type FetchOptions](#type-fetchoptions)
- [type FormDataFileAppender](#type-formdatafileappender)
- [type ReactNativeFileSubstitute](#type-reactnativefilesubstitute)

@@ -137,8 +153,12 @@

Used to mark a [React Native `File` substitute](#type-reactnativefilesubstitute). It’s too risky to assume all objects with `uri`, `type` and `name` properties are files to extract. Re-exported from [`extract-files`](https://npm.im/extract-files) for convenience.
Used to mark [React Native `File` substitutes](#type-reactnativefilesubstitute) as it’s too risky to assume all objects with `uri`, `type` and `name` properties are extractable files.
| Parameter | Type | Description |
| :-- | :-- | :-- |
| `file` | [ReactNativeFileSubstitute](#type-reactnativefilesubstitute) | A React Native [`File`](https://developer.mozilla.org/docs/web/api/file) substitute. |
| `file` | [ReactNativeFileSubstitute](#type-reactnativefilesubstitute) | A React Native [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) substitute. |
#### See
- [`extract-files` `ReactNativeFile` docs](https://github.com/jaydenseric/extract-files#class-reactnativefile).
#### Examples

@@ -149,3 +169,3 @@

> ```js
> const { ReactNativeFile } = require('apollo-upload-client')
> const { ReactNativeFile } = require('apollo-upload-client');
>

@@ -155,4 +175,4 @@ > const file = new ReactNativeFile({

> name: 'a.jpg',
> type: 'image/jpeg'
> })
> type: 'image/jpeg',
> });
> ```

@@ -164,4 +184,8 @@

Creates a terminating [Apollo Link](https://apollographql.com/docs/link) capable of file uploads. Options match [`createHttpLink`](https://apollographql.com/docs/link/links/http#options).
Creates a terminating [Apollo Link](https://apollographql.com/docs/link) capable of file uploads.
The link matches and extracts files in the GraphQL operation. If there are files it uses a [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instance as the [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) `options.body` to make a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec), otherwise it sends a regular POST request.
Some of the options are similar to the [`createHttpLink` options](https://apollographql.com/docs/link/links/http/#options).
| Parameter | Type | Description |

@@ -171,4 +195,7 @@ | :-- | :-- | :-- |

| `options.uri` | string? = /graphql | GraphQL endpoint URI. |
| `options.fetch` | Function? | [`fetch`](https://fetch.spec.whatwg.org) implementation to use, defaulting to the `fetch` global. |
| `options.fetchOptions` | [FetchOptions](#type-fetchoptions)? | `fetch` options; overridden by upload requirements. |
| `options.isExtractableFile` | [ExtractableFileMatcher](#type-extractablefilematcher)? = [isExtractableFile](#function-isextractablefile) | Customizes how files are matched in the GraphQL operation for extraction. |
| `options.FormData` | class? | [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) implementation to use, defaulting to the [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) global. |
| `options.formDataAppendFile` | [FormDataFileAppender](#type-formdatafileappender)? = [formDataAppendFile](#function-formdataappendfile) | Customizes how extracted files are appended to the [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instance. |
| `options.fetch` | Function? | [`fetch`](https://fetch.spec.whatwg.org) implementation to use, defaulting to the [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) global. |
| `options.fetchOptions` | [FetchOptions](#type-fetchoptions)? | [`fetch` options](#type-fetchoptions); overridden by upload requirements. |
| `options.credentials` | string? | Overrides `options.fetchOptions.credentials`. |

@@ -183,3 +210,3 @@ | `options.headers` | object? | Merges with and overrides `options.fetchOptions.headers`. |

- [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec).
- [apollo-link on GitHub](https://github.com/apollographql/apollo-link).
- [`apollo-link` on GitHub](https://github.com/apollographql/apollo-link).

@@ -191,10 +218,10 @@ #### Examples

> ```js
> const { ApolloClient } = require('apollo-client')
> const { InMemoryCache } = require('apollo-cache-inmemory')
> const { createUploadLink } = require('apollo-upload-client')
> const { ApolloClient } = require('apollo-client');
> const { InMemoryCache } = require('apollo-cache-inmemory');
> const { createUploadLink } = require('apollo-upload-client');
>
> const client = new ApolloClient({
> cache: new InMemoryCache(),
> link: createUploadLink()
> })
> link: createUploadLink(),
> });
> ```

@@ -204,2 +231,64 @@

### function formDataAppendFile
The default implementation for [`createUploadLink`](#function-createuploadlink) `options.formDataAppendFile` that uses the standard [`FormData.append`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/append) method.
**Type:** [FormDataFileAppender](#type-formdatafileappender)
| Parameter | Type | Description |
| :-- | :-- | :-- |
| `formData` | FormData | [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instance to append the specified file to. |
| `fieldName` | string | Field name for the file. |
| `file` | \* | File to append. |
---
### function isExtractableFile
The default implementation for [`createUploadLink`](#function-createuploadlink) `options.isExtractableFile`.
**Type:** [ExtractableFileMatcher](#type-extractablefilematcher)
| Parameter | Type | Description |
| :-------- | :--- | :-------------- |
| `value` | \* | Value to check. |
**Returns:** boolean — Is the value an extractable file.
#### See
- [`extract-files` `isExtractableFile` docs](https://github.com/jaydenseric/extract-files#function-isextractablefile).
---
### type ExtractableFileMatcher
A function that checks if a value is an extractable file.
**Type:** Function
| Parameter | Type | Description |
| :-------- | :--- | :-------------- |
| `value` | \* | Value to check. |
**Returns:** boolean — Is the value an extractable file.
#### See
- [`isExtractableFile`](#function-isextractablefile) has this type.
#### Examples
_How to check for the default exactable files, as well as a custom type of file._
> ```js
> const { isExtractableFile } = require('apollo-upload-client');
>
> const isExtractableFileEnhanced = (value) =>
> isExtractableFile(value) ||
> (typeof CustomFile !== 'undefined' && value instanceof CustomFile);
> ```
---
### type FetchOptions

@@ -222,5 +311,22 @@

### type FormDataFileAppender
Appends a file extracted from the GraphQL operation to the [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instance used as the [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) `options.body` for the [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).
| Parameter | Type | Description |
| :-- | :-- | :-- |
| `formData` | FormData | [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instance to append the specified file to. |
| `fieldName` | string | Field name for the file. |
| `file` | \* | File to append. The file type depends on what the [`ExtractableFileMatcher`](#type-extractablefilematcher) extracts. |
#### See
- [`formDataAppendFile`](#function-formdataappendfile) has this type.
- [`createUploadLink`](#function-createuploadlink) accepts this type in `options.formDataAppendFile`.
---
### type ReactNativeFileSubstitute
A React Native [`File`](https://developer.mozilla.org/docs/web/api/file) substitute.
A React Native [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) substitute.

@@ -239,3 +345,3 @@ Be aware that inspecting network requests with Chrome dev tools interferes with the React Native `FormData` implementation, causing network errors.

- [`extract-files` docs](https://github.com/jaydenseric/extract-files#type-reactnativefilesubstitute).
- [`extract-files` `ReactNativeFileSubstitute` docs](https://github.com/jaydenseric/extract-files#type-reactnativefilesubstitute).
- [React Native `FormData` polyfill source](https://github.com/facebook/react-native/blob/v0.45.1/Libraries/Network/FormData.js#L34).

@@ -242,0 +348,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc