{"_id":"apollo-upload-client@20.0.0","bugs":{"url":"https://github.com/jaydenseric/apollo-upload-client/issues"},"dist":{"shasum":"9b2aece6ac5f35023e27af62e0f15baa4caa8ab8","tarball":"http://registry-npm.ywwl.com/apollo-upload-client/download/apollo-upload-client-20.0.0.tgz","fileCount":5,"integrity":"sha512-nCot+4kmi/hq4xDvPDewPyK9y5QSKtu4vg1qwi2njmPwXuD28wiCR07rV+A0E9V2wvmOts3sltpT7UkaQ9ST2A==","signatures":[{"sig":"MEQCIC8SMonQ9pYNtUzRlxD1gMx7khqVewEUgeh5+fuHvU9qAiA3urEHcWrdPS2ynp9XUtctYcIAFx8lN77IqfZDNmV02Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDZUjeIk8O15pB1TH2lQCbETfgIr4Qxn5v+fhTFxLKirAIhAJ9HiU1rgv3VuTRW/iAG0ydMdNhgsDM0uasO49pwdZRN"}],"unpackedSize":21873,"size":6117,"noattachment":false,"key":"/apollo-upload-client/-/apollo-upload-client-20.0.0.tgz"},"name":"apollo-upload-client","author":{"url":"https://jaydenseric.com","name":"Jayden Seric","email":"me@jaydenseric.com"},"engines":{"node":"^22.13.0 || ^24.0.0 || >=26.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":"02aa3daa38648d26a77fe9c20f6eb3059c8982ec","license":"MIT","scripts":{"test":"node --test --experimental-test-coverage --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 --test-coverage-exclude='**/*.test.*' --test-coverage-exclude='test-helpers/**' --test-reporter=spec","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"},"version":"20.0.0","_npmUser":{"name":"jaydenseric","email":"me@jaydenseric.com"},"homepage":"https://github.com/jaydenseric/apollo-upload-client#readme","keywords":["graphql","multipart","request","file","upload","apollo","client","link","react","esm","mjs"],"repository":{"url":"git+https://github.com/jaydenseric/apollo-upload-client.git","type":"git"},"_npmVersion":"11.17.0","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":{},"maintainers":[{"name":"jaydenseric","email":"me@jaydenseric.com"}],"sideEffects":false,"_nodeVersion":"26.5.0","browserslist":"Node 22.13 - 23 and Node < 23, Node 24 - 25 and Node < 25, Node >= 26, > 0.5%, not OperaMini all, not dead","dependencies":{"extract-files":"^14.0.0"},"_hasShrinkwrap":false,"devDependencies":{"rxjs":"^7.8.2","eslint":"^10.8.0","esbuild":"^0.28.1","globals":"^17.8.0","graphql":"^17.0.2","prettier":"^3.8.1","gzip-size":"^7.0.0","@eslint/js":"^10.0.1","typescript":"^7.0.2","@types/node":"^26.1.1","graphql-tag":"^2.12.6","@apollo/client":"^4.1.6","revertable-globals":"^4.0.0","eslint-plugin-optimal-modules":"^4.0.0","eslint-plugin-simple-import-sort":"^14.0.0"},"peerDependencies":{"rxjs":"^7.3.0","graphql":"^16.0.0 || ^17.0.0","@apollo/client":"^4.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/apollo-upload-client_20.0.0_1785302058839_0.541674803856981"},"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":1785302058919,"_cnpm_publish_time":1785302058919,"dist-tags":{"latest":"20.0.0"}}