Skip to content

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.

Notifications You must be signed in to change notification settings

r26D/apollo-upload-client-absinthe

 
 

Repository files navigation

apollo-upload-client-absinthe

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

API

Table of contents

class ReactNativeFile

Used to mark a React Native File substitute. 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.

Parameter Type Description
file ReactNativeFileSubstitute A React Native File substitute.

Examples

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

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

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

function createUploadLink

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

Parameter Type Description
options object Options.
options.uri string? = /graphql GraphQL endpoint URI.
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? = false Toggles sending extensions fields to the GraphQL server.

Returns: ApolloLink — A terminating Apollo Link capable of file uploads.

See

Examples

A basic Apollo Client setup.

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

type FetchOptions

GraphQL request fetch options.

Type: object

Property Type Description
headers object HTTP request headers.
credentials string? Authentication credentials mode.

See


type 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

Property Type Description
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.

See

Examples

A camera roll file.

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

About

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.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%