![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@allsquare/apollo-upload-client
Advanced tools
Enhances Apollo Client for intuitive file uploads via GraphQL mutations.
Enhances Apollo for intuitive file uploads via GraphQL queries or mutations. Use with a GraphQL multipart request spec server implementation such as apollo-upload-server.
Install with peer dependencies using npm:
npm install apollo-upload-client apollo-link
Initialize Apollo Client with this terminating link:
import { createUploadLink } from 'apollo-upload-client'
const link = createUploadLink(/* Options */)
createUploadLink
options match createHttpLink
options:
includeExtensions
(boolean): Toggles sending extensions
fields to the GraphQL server. (default: false
).uri
(string): GraphQL endpoint URI (default: /graphql
).credentials
(string): Overrides fetchOptions.credentials
.headers
(object): Merges with and overrides fetchOptions.headers
.fetchOptions
(object): fetch
init; overridden by upload requirements.fetch
(function): Fetch API to use (default: Global fetch
).Use FileList
, File
, Blob
or ReactNativeFile
instances anywhere within query or mutation input variables to send a GraphQL multipart request. See also apollo-upload-server usage and the example API and client.
FileList
import gql from 'graphql-tag'
import { graphql } from 'react-apollo'
export default graphql(gql`
mutation($files: [Upload!]!) {
uploadFiles(files: $files) {
id
}
}
`)(({ mutate }) => (
<input
type="file"
multiple
required
onChange={({ target: { validity, files } }) =>
validity.valid && mutate({ variables: { files } })
}
/>
))
File
import gql from 'graphql-tag'
import { graphql } from 'react-apollo'
export default graphql(gql`
mutation($file: Upload!) {
uploadFile(file: $file) {
id
}
}
`)(({ mutate }) => (
<input
type="file"
required
onChange={({
target: {
validity,
files: [file]
}
}) => validity.valid && mutate({ variables: { file } })}
/>
))
Blob
import gql from 'graphql-tag'
// Apollo Client instance
import client from './apollo'
const file = new Blob(['Foo.'], { type: 'text/plain' })
// Optional, defaults to `blob`
file.name = 'bar.txt'
client.mutate({
mutation: gql`
mutation($file: Upload!) {
uploadFile(file: $file) {
id
}
}
`,
variables: { file }
})
Substitute File
with ReactNativeFile
from extract-files
:
import { ReactNativeFile } from 'apollo-upload-client'
const file = new ReactNativeFile({
uri: '…',
type: 'image/jpeg',
name: 'photo.jpg'
})
const files = ReactNativeFile.list([
{
uri: '…',
type: 'image/jpeg',
name: 'photo-1.jpg'
},
{
uri: '…',
type: 'image/jpeg',
name: 'photo-2.jpg'
}
])
package.json
engines
.package.json
browserslist
.8.0.0
.mjs
until Apollo provides native ESM, fixing #72.FAQs
Enhances Apollo Client for intuitive file uploads via GraphQL mutations.
We found that @allsquare/apollo-upload-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.