{"name":"apollo-upload-client","version":"19.0.0","keywords":["graphql","multipart","request","file","upload","apollo","client","link","react","esm","mjs"],"author":{"url":"https://jaydenseric.com","name":"Jayden Seric","email":"me@jaydenseric.com"},"license":"MIT","_id":"apollo-upload-client@19.0.0","maintainers":[{"name":"jaydenseric","email":"me@jaydenseric.com"}],"homepage":"https://github.com/jaydenseric/apollo-upload-client#readme","bugs":{"url":"https://github.com/jaydenseric/apollo-upload-client/issues"},"dist":{"shasum":"8c6c8f0d124ae305f4eeae3b2cf0eac85674b4fc","tarball":"http://registry-npm.ywwl.com/apollo-upload-client/download/apollo-upload-client-19.0.0.tgz","fileCount":5,"integrity":"sha512-SOORV4GB71Pd1Ktdb5D8qBthu/gtTQirTx6rAhgujR+Z24dwmLU47hUERFVeffnFpCMRsir/V5ijOSfqqJdC4A==","signatures":[{"sig":"MEQCIFwCxyk13Q7CYRwZvdVWR8/SSHmUpTPO1zj4Ysyob+KoAiANpfFLjUXzYXcmKeiIS1R2pRgAdekVBmnLJmzZ14OiPw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21728,"size":6012,"noattachment":false,"key":"/apollo-upload-client/-/apollo-upload-client-19.0.0.tgz"},"engines":{"node":"^20.9.0 || >=22.0.0"},"exports":{"./package.json":"./package.json","./UploadHttpLink.mjs":"./UploadHttpLink.mjs","./isExtractableFile.mjs":"./isExtractableFile.mjs","./formDataAppendFile.mjs":"./formDataAppendFile.mjs"},"funding":"https://github.com/sponsors/jaydenseric","gitHead":"03dca0e234cd5ab8449ab147f3e563e639d5e3e8","scripts":{"test":"coverage-node --test-reporter=spec --test *.test.mjs","check":"node --run prettier && node --run eslint && node --run types && node --run test","types":"tsc -p jsconfig.json","eslint":"eslint","prettier":"prettier -c .","prepublishOnly":"node --run check"},"_npmUser":{"name":"jaydenseric","email":"me@jaydenseric.com"},"repository":{"url":"git+https://github.com/jaydenseric/apollo-upload-client.git","type":"git"},"_npmVersion":"11.5.1","description":"A terminating Apollo Link for Apollo Client that fetches a GraphQL multipart request if the GraphQL variables contain files (by default FileList, File, or Blob instances), or else fetches a regular GraphQL POST or GET request (depending on the config and ","directories":{},"sideEffects":false,"_nodeVersion":"24.7.0","browserslist":"Node 20.9 - 21 and Node < 21, Node >= 22, > 0.5%, not OperaMini all, not dead","dependencies":{"extract-files":"^13.0.0"},"_hasShrinkwrap":false,"devDependencies":{"rxjs":"^7.8.2","eslint":"^9.34.0","esbuild":"^0.25.9","graphql":"^16.11.0","prettier":"^3.6.2","gzip-size":"^7.0.0","@eslint/js":"^9.34.0","typescript":"^5.9.2","@types/node":"^24.3.0","graphql-tag":"^2.12.6","coverage-node":"^8.0.0","@apollo/client":"^4.0.2","revertable-globals":"^4.0.0","eslint-plugin-optimal-modules":"^3.0.0","eslint-plugin-simple-import-sort":"^12.1.1"},"peerDependencies":{"rxjs":"^7.3.0","graphql":"14 - 16","@apollo/client":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/apollo-upload-client_19.0.0_1756427614981_0.3421362477048997","host":"s3://npm-registry-packages-npm-production"},"readme":"![Apollo upload logo](https://cdn.jsdelivr.net/gh/jaydenseric/apollo-upload-client@1.0.0/apollo-upload-logo.svg)\n\n# apollo-upload-client\n\nA [terminating Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction#the-terminating-link) for [Apollo Client](https://www.apollographql.com/docs/react) that fetches a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec) if the GraphQL variables contain files (by default [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), or [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) instances), or else fetches a regular [GraphQL POST or GET request](https://www.apollographql.com/docs/apollo-server/workflow/requests) (depending on the config and GraphQL operation).\n\n- [Installation](#installation)\n- [Examples](#examples)\n- [Requirements](#requirements)\n- [Exports](#exports)\n\n## Installation\n\nTo install with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), run:\n\n```sh\nnpm install apollo-upload-client\n```\n\nPolyfill any required globals (see [_**Requirements**_](#requirements)) that are missing in your server and client environments.\n\n[Apollo Client](https://www.apollographql.com/docs/react) can only have 1 [terminating Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction#the-terminating-link) that sends the GraphQL requests; if one such as [`HttpLink`](https://www.apollographql.com/docs/react/api/link/apollo-link-http) is already setup, remove it.\n\nConstruct [`ApolloClient`](https://www.apollographql.com/docs/react/api/core/ApolloClient) with a [terminating Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction#the-terminating-link) using the class [`UploadHttpLink`](./UploadHttpLink.mjs). For client awareness features, compose the Apollo Link [`ClientAwarenessLink`](https://www.apollographql.com/docs/react/api/link/apollo-link-client-awareness) before the terminating link.\n\nAlso ensure the GraphQL server implements the [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec) and that uploads are handled correctly in resolvers.\n\n## Examples\n\nUse [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), or [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) instances anywhere within query or mutation variables to send a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).\n\nSee also the [example API and client](https://github.com/jaydenseric/apollo-upload-examples).\n\n### [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList)\n\n```tsx\nimport { gql } from \"@apollo/client\";\nimport { useMutation } from \"@apollo/client/react\";\n\n/** React component for uploading a file list. */\nfunction UploadFileList() {\n  const [mutate] = useMutation<\n    {\n      uploadFiles: {\n        success: boolean;\n      };\n    },\n    {\n      files: FileList;\n    }\n  >(mutation);\n\n  return (\n    <input\n      type=\"file\"\n      multiple\n      required\n      onChange={({ target: { validity, files } }) => {\n        if (validity.valid && files?.length)\n          mutate({\n            variables: {\n              files,\n            },\n          });\n      }}\n    />\n  );\n}\n\nconst mutation = gql`\n  mutation ($files: [Upload!]!) {\n    uploadFiles(files: $files) {\n      success\n    }\n  }\n`;\n```\n\n### [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File)\n\n```tsx\nimport { gql } from \"@apollo/client\";\nimport { useMutation } from \"@apollo/client/react\";\n\n/** React component for uploading a file. */\nfunction UploadFile() {\n  const [mutate] = useMutation<\n    {\n      uploadFile: {\n        success: boolean;\n      };\n    },\n    {\n      file: File;\n    }\n  >(mutation);\n\n  return (\n    <input\n      type=\"file\"\n      required\n      onChange={({ target: { validity, files } }) => {\n        if (validity.valid && files?.[0])\n          mutate({\n            variables: {\n              file: files[0],\n            },\n          });\n      }}\n    />\n  );\n}\n\nconst mutation = gql`\n  mutation ($file: Upload!) {\n    uploadFile(file: $file) {\n      success\n    }\n  }\n`;\n```\n\n### [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)\n\n```tsx\nimport { gql } from \"@apollo/client\";\nimport { useMutation } from \"@apollo/client/react\";\n\n/** React component for uploading a blob. */\nfunction UploadBlob() {\n  const [mutate] = useMutation<\n    {\n      uploadFile: {\n        success: boolean;\n      };\n    },\n    {\n      file: Blob;\n    }\n  >(mutation);\n\n  return (\n    <button\n      type=\"button\"\n      onClick={() => {\n        mutate({\n          variables: {\n            file: new Blob([\"Content here.\"], {\n              type: \"text/plain\",\n            }),\n          },\n        });\n      }}\n    >\n      Upload\n    </button>\n  );\n}\n\nconst mutation = gql`\n  mutation ($file: Upload!) {\n    uploadFile(file: $file) {\n      success\n    }\n  }\n`;\n```\n\nTo avoid the upload default file name `blob`, replace the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) approach with [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File):\n\n```ts\nnew File(\n  [value],\n  // Custom file name.\n  \"text.txt\",\n  {\n    type: \"text/plain\",\n  },\n);\n```\n\n## Requirements\n\n- [Node.js](https://nodejs.org) versions `^22.13.0 || ^24.0.0 || >=26.0.0`.\n- Browsers matching the [Browserslist](https://browsersl.ist) query [`> 0.5%, not OperaMini all, not dead`](https://browsersl.ist/?q=%3E+0.5%25%2C+not+OperaMini+all%2C+not+dead).\n\nProjects must configure [TypeScript](https://www.typescriptlang.org) to use types from the ECMAScript modules that have a `// @ts-check` comment:\n\n- [`compilerOptions.allowJs`](https://www.typescriptlang.org/tsconfig#allowJs) should be `true`.\n- [`compilerOptions.maxNodeModuleJsDepth`](https://www.typescriptlang.org/tsconfig#maxNodeModuleJsDepth) should be reasonably large, e.g. `10`.\n- [`compilerOptions.module`](https://www.typescriptlang.org/tsconfig#module) should be `\"node16\"` or `\"nodenext\"`.\n\n## Exports\n\nThe [npm](https://npmjs.com) package [`apollo-upload-client`](https://npm.im/apollo-upload-client) features [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design). It doesn’t have a main index module, so use deep imports from the ECMAScript modules that are exported via the [`package.json`](./package.json) field [`exports`](https://nodejs.org/api/packages.html#exports):\n\n- [`formDataAppendFile.mjs`](./formDataAppendFile.mjs)\n- [`isExtractableFile.mjs`](./isExtractableFile.mjs)\n- [`UploadHttpLink.mjs`](./UploadHttpLink.mjs)\n","publish_time":1756427615168,"_cnpm_publish_time":1756427615168,"dist-tags":{"latest":"20.0.0"}}