apollo-upload-client is a terminating Apollo Link for Apollo Client that facilitates file uploads within GraphQL mutations using the GraphQL multipart request specification. It automatically detects `FileList`, `File`, or `Blob` instances in GraphQL variables and constructs a multipart request, falling back to a standard GraphQL POST or GET request otherwise. The current stable version is 19.0.0, with major versions released somewhat frequently to align with `@apollo/client` updates and Node.js LTS changes. Its primary differentiator is seamless integration with Apollo Client for file uploads, abstracting the multipart request complexity, and adhering to the community-standard GraphQL multipart request specification. It requires a compatible server-side implementation that also follows the specification.
npm install apollo-upload-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `apollo-upload-client` with Apollo Client, define a GraphQL mutation for file uploads, and use it within a React component. It initializes `createUploadLink` with a GraphQL endpoint and wraps a file input with a `useMutation` hook to send the selected file to the server.
Upgrade Node.js to a supported version, e.g., Node.js 20.9.0 or later LTS.
Ensure your `@apollo/client` package aligns with the `apollo-upload-client` peer dependency range. For v19.0.0, install `@apollo/client@^4.0.0`.
For React Native environments, alternative file handling or custom implementations for file extraction are now required. Consider external packages or manual serialization.
Install `rxjs@^7.3.0` alongside `apollo-upload-client` and `@apollo/client` v4.
Manually install `@apollo/client` in your project if you haven't already: `npm install @apollo/client graphql`.
Remove any other terminating links (e.g., `HttpLink`) from your Apollo Client link chain when using `createUploadLink` or `UploadHttpLink`.
Run `npm install @apollo/client` or `yarn add @apollo/client`.
Ensure your GraphQL server is compatible with the `graphql-multipart-request-spec` and that your resolvers are correctly processing the `Upload` scalar.
Verify that you are using `import { createUploadLink } from 'apollo-upload-client';` and that your `@apollo/client` version matches the peer dependency requirements.Ensure your project uses ES modules (`import`/`export`) or is transpiled correctly. For Node.js, confirm `type: module` in `package.json` or use `.mjs` files.