0.0.12 • Published 4 years ago

@r26d/absinthe-apollo-upload-client v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Table of Contents generated with DocToc

@r26d/absinthe-apollo-upload-client

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. Modified to support the Absinthe way of posting files

apollo-upload-client-absinthe

This fork modifies the request format to support Absinthe's way of handling file uploads.

API

ReactNativeFileSubstitute

A React Native File substitute.

Be aware that inspecting network requests with Chrome dev tools interferes with the React Native FormData implementation, causing network errors.

Type: object

Properties

  • uri string Filesystem path.
  • name string? File name.
  • type string? File content type. Some environments (particularly Android) require a valid MIME type; Expo ImageResult.type is unreliable as it can be just image.

Examples

A camera roll file.

```js
{
  uri: uriFromCameraRoll,
  name: 'a.jpg',
  type: 'image/jpeg'
}
```

ReactNativeFile

Used to mark a React Native File substitute(#reactnativefilesubstitute). It’s too risky to assume all objects with uri, type and name properties are files to extract. Re-exported from extract-files for convenience.

Parameters

Examples

A React Native file that can be used in query or mutation variables.

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

const file = new ReactNativeFile({
  uri: uriFromCameraRoll,
  name: 'a.jpg',
  type: 'image/jpeg'
})
```

FetchOptions

GraphQL request fetch options.

Type: object

Properties

  • headers object HTTP request headers.
  • credentials string? Authentication credentials mode.

createUploadLink

Creates a terminating Apollo Link capable of file uploads. Options match createHttpLink.

Parameters

  • options object Options.
    • options.uri string GraphQL endpoint URI. (optional, default /graphql)
    • options.fetch Function? fetch implementation to use, defaulting to the fetch global.
    • options.fetchOptions FetchOptions? fetch options; overridden by upload requirements.
    • options.credentials string? Overrides options.fetchOptions.credentials.
    • options.headers object? Merges with and overrides options.fetchOptions.headers.
    • options.includeExtensions boolean Toggles sending extensions fields to the GraphQL server. (optional, default false)

Examples

A basic Apollo Client setup.

```js
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()
})
```

Returns ApolloLink A terminating Apollo Link capable of file uploads.

API

License

MIT :copyright: r26D LLC