{"version":3,"file":"apollo-upload-client-BwkY3MnZ.js","sources":["../../node_modules/apollo-upload-client/formDataAppendFile.mjs","../../node_modules/apollo-upload-client/createUploadLink.mjs"],"sourcesContent":["// @ts-check\n\n/**\n * The default implementation for the function `createUploadLink` option\n * `formDataAppendFile` that uses the standard {@linkcode FormData.append}\n * method.\n * @param {FormData} formData Form data to append the specified file to.\n * @param {string} fieldName Field name for the file.\n * @param {import(\"./isExtractableFile.mjs\").ExtractableFile} file File to\n * append.\n */\nexport default function formDataAppendFile(formData, fieldName, file) {\n \"name\" in file\n ? formData.append(fieldName, file, file.name)\n : formData.append(fieldName, file);\n}\n","// @ts-check\n\nimport { ApolloLink } from \"@apollo/client/link/core/ApolloLink.js\";\nimport { createSignalIfSupported } from \"@apollo/client/link/http/createSignalIfSupported.js\";\nimport { parseAndCheckHttpResponse } from \"@apollo/client/link/http/parseAndCheckHttpResponse.js\";\nimport { rewriteURIForGET } from \"@apollo/client/link/http/rewriteURIForGET.js\";\nimport {\n defaultPrinter,\n fallbackHttpConfig,\n selectHttpOptionsAndBodyInternal,\n} from \"@apollo/client/link/http/selectHttpOptionsAndBody.js\";\nimport { selectURI } from \"@apollo/client/link/http/selectURI.js\";\nimport { serializeFetchParameter } from \"@apollo/client/link/http/serializeFetchParameter.js\";\nimport { Observable } from \"@apollo/client/utilities/observables/Observable.js\";\nimport extractFiles from \"extract-files/extractFiles.mjs\";\n\nimport formDataAppendFile from \"./formDataAppendFile.mjs\";\nimport isExtractableFile from \"./isExtractableFile.mjs\";\n\n/**\n * Creates a\n * [terminating Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link)\n * for [Apollo Client](https://www.apollographql.com/docs/react) that fetches a\n * [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec)\n * if the GraphQL variables contain files (by default\n * [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList),\n * [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), or\n * [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) instances),\n * or else fetches a regular\n * [GraphQL POST or GET request](https://www.apollographql.com/docs/apollo-server/workflow/requests)\n * (depending on the config and GraphQL operation).\n *\n * Some of the options are similar to the\n * [`createHttpLink` options](https://www.apollographql.com/docs/react/api/link/apollo-link-http/#httplink-constructor-options).\n * @see [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec).\n * @param {object} options Options.\n * @param {Parameters[1]} [options.uri] GraphQL endpoint URI.\n * Defaults to `\"/graphql\"`.\n * @param {boolean} [options.useGETForQueries] Should GET be used to fetch\n * queries, if there are no files to upload.\n * @param {ExtractableFileMatcher} [options.isExtractableFile] Matches\n * extractable files in the GraphQL operation. Defaults to\n * {@linkcode isExtractableFile}.\n * @param {typeof FormData} [options.FormData]\n * [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)\n * class. Defaults to the {@linkcode FormData} global.\n * @param {FormDataFileAppender} [options.formDataAppendFile]\n * Customizes how extracted files are appended to the\n * [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)\n * instance. Defaults to {@linkcode formDataAppendFile}.\n * @param {import(\"@apollo/client/link/http/selectHttpOptionsAndBody.js\").Printer} [options.print]\n * Prints the GraphQL query or mutation AST to a string for transport.\n * Defaults to {@linkcode defaultPrinter}.\n * @param {typeof fetch} [options.fetch] [`fetch`](https://fetch.spec.whatwg.org)\n * implementation. Defaults to the {@linkcode fetch} global.\n * @param {RequestInit} [options.fetchOptions] `fetch` options; overridden by\n * upload requirements.\n * @param {string} [options.credentials] Overrides\n * {@linkcode RequestInit.credentials credentials} in\n * {@linkcode fetchOptions}.\n * @param {{ [headerName: string]: string }} [options.headers] Merges with and\n * overrides {@linkcode RequestInit.headers headers} in\n * {@linkcode fetchOptions}.\n * @param {boolean} [options.includeExtensions] Toggles sending `extensions`\n * fields to the GraphQL server. Defaults to `false`.\n * @returns A [terminating Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link).\n * @example\n * A basic Apollo Client setup:\n *\n * ```js\n * import { ApolloClient, InMemoryCache } from \"@apollo/client\";\n * import createUploadLink from \"apollo-upload-client/createUploadLink.mjs\";\n *\n * const client = new ApolloClient({\n * cache: new InMemoryCache(),\n * link: createUploadLink(),\n * });\n * ```\n */\nexport default function createUploadLink({\n uri: fetchUri = \"/graphql\",\n useGETForQueries,\n isExtractableFile: customIsExtractableFile = isExtractableFile,\n FormData: CustomFormData,\n formDataAppendFile: customFormDataAppendFile = formDataAppendFile,\n print = defaultPrinter,\n fetch: customFetch,\n fetchOptions,\n credentials,\n headers,\n includeExtensions,\n} = {}) {\n const linkConfig = {\n http: { includeExtensions },\n options: fetchOptions,\n credentials,\n headers,\n };\n\n return new ApolloLink((operation) => {\n const context =\n /**\n * @type {import(\"@apollo/client/core/types.js\").DefaultContext & {\n * clientAwareness?: {\n * name?: string,\n * version?: string,\n * },\n * }}\n */\n (operation.getContext());\n const {\n // Apollo Studio client awareness `name` and `version` can be configured\n // via `ApolloClient` constructor options:\n // https://www.apollographql.com/docs/graphos/metrics/client-awareness/#setup\n clientAwareness: { name, version } = {},\n headers,\n } = context;\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: {\n // Client awareness headers can be overridden by context `headers`.\n ...(name && { \"apollographql-client-name\": name }),\n ...(version && { \"apollographql-client-version\": version }),\n ...headers,\n },\n };\n\n const { options, body } = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig,\n );\n\n const { clone, files } = extractFiles(body, customIsExtractableFile, \"\");\n\n let uri = selectURI(operation, fetchUri);\n\n if (files.size) {\n if (options.headers)\n // Automatically set by `fetch` when the `body` is a `FormData` instance.\n delete options.headers[\"content-type\"];\n\n // GraphQL multipart request spec:\n // https://github.com/jaydenseric/graphql-multipart-request-spec\n\n const RuntimeFormData = CustomFormData || FormData;\n\n const form = new RuntimeFormData();\n\n form.append(\"operations\", serializeFetchParameter(clone, \"Payload\"));\n\n /** @type {{ [key: string]: Array }} */\n const map = {};\n\n let i = 0;\n files.forEach((paths) => {\n map[++i] = paths;\n });\n form.append(\"map\", JSON.stringify(map));\n\n i = 0;\n files.forEach((_paths, file) => {\n customFormDataAppendFile(form, String(++i), file);\n });\n\n options.body = form;\n } else {\n if (\n useGETForQueries &&\n // If the operation contains some mutations GET shouldn’t be used.\n !operation.query.definitions.some(\n (definition) =>\n definition.kind === \"OperationDefinition\" &&\n definition.operation === \"mutation\",\n )\n )\n options.method = \"GET\";\n\n if (options.method === \"GET\") {\n const { newURI, parseError } = rewriteURIForGET(uri, body);\n if (parseError)\n // Apollo’s `HttpLink` uses `fromError` for this, but it’s not\n // exported from `@apollo/client/link/http`.\n return new Observable((observer) => {\n observer.error(parseError);\n });\n uri = newURI;\n } else options.body = serializeFetchParameter(clone, \"Payload\");\n }\n\n const { controller } = createSignalIfSupported();\n\n if (typeof controller !== \"boolean\") {\n if (options.signal)\n // Respect the user configured abort controller signal.\n options.signal.aborted\n ? // Signal already aborted, so immediately abort.\n controller.abort()\n : // Signal not already aborted, so setup a listener to abort when it\n // does.\n options.signal.addEventListener(\n \"abort\",\n () => {\n controller.abort();\n },\n {\n // Prevent a memory leak if the user configured abort controller\n // is long lasting, or controls multiple things.\n once: true,\n },\n );\n\n options.signal = controller.signal;\n }\n\n const runtimeFetch = customFetch || fetch;\n\n return new Observable((observer) => {\n /**\n * Is the observable being cleaned up.\n * @type {boolean}\n */\n let cleaningUp;\n\n runtimeFetch(uri, options)\n .then((response) => {\n // Forward the response on the context.\n operation.setContext({ response });\n return response;\n })\n .then(parseAndCheckHttpResponse(operation))\n .then((result) => {\n observer.next(result);\n observer.complete();\n })\n .catch((error) => {\n // If the observable is being cleaned up, there is no need to call\n // next or error because there are no more subscribers. An error after\n // cleanup begins is likely from the cleanup function aborting the\n // fetch.\n if (!cleaningUp) {\n // For errors such as an invalid fetch URI there will be no GraphQL\n // result with errors or data to forward.\n if (error.result && error.result.errors && error.result.data)\n observer.next(error.result);\n\n observer.error(error);\n }\n });\n\n // Cleanup function.\n return () => {\n cleaningUp = true;\n\n // Abort fetch. It’s ok to signal an abort even when not fetching.\n if (typeof controller !== \"boolean\") controller.abort();\n };\n });\n });\n}\n\n/**\n * Checks if a value is an extractable file.\n * @template [ExtractableFile=any] Extractable file.\n * @callback ExtractableFileMatcher\n * @param {unknown} value Value to check.\n * @returns {value is ExtractableFile} Is the value an extractable file.\n * @example\n * How to check for the default exactable files, as well as a custom type of\n * file:\n *\n * ```js\n * import isExtractableFile from \"apollo-upload-client/isExtractableFile.mjs\";\n *\n * const isExtractableFileEnhanced = (value) =>\n * isExtractableFile(value) ||\n * (typeof CustomFile !== \"undefined\" && value instanceof CustomFile);\n * ```\n */\n\n/**\n * Appends a file extracted from the GraphQL operation to the\n * [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)\n * instance used as the\n * [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch)\n * `options.body` for the\n * [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec).\n * @template [ExtractableFile=any] Extractable file.\n * @callback FormDataFileAppender\n * @param {FormData} formData\n * [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)\n * instance to append the specified file to.\n * @param {string} fieldName Form data field name to append the file with.\n * @param {ExtractableFile} file File to append. The file type depends on what\n * the extractable file matcher extracts.\n */\n"],"names":["formDataAppendFile","formData","fieldName","file","append","name","createUploadLink","uri","fetchUri","useGETForQueries","isExtractableFile","customIsExtractableFile","FormData","CustomFormData","customFormDataAppendFile","print","defaultPrinter","fetch","customFetch","fetchOptions","credentials","headers","includeExtensions","linkConfig","http","options","ApolloLink","operation","context","getContext","clientAwareness","version","contextConfig","body","selectHttpOptionsAndBodyInternal","fallbackHttpConfig","clone","files","extractFiles","selectURI","size","form","serializeFetchParameter","map","i","forEach","paths","JSON","stringify","_paths","String","query","definitions","some","definition","kind","method","newURI","parseError","rewriteURIForGET","Observable","observer","error","controller","createSignalIfSupported","signal","aborted","abort","addEventListener","once","runtimeFetch","cleaningUp","then","response","setContext","parseAndCheckHttpResponse","result","next","complete","catch","errors","data"],"mappings":"6MAWe,SAASA,EAAmBC,EAAUC,EAAWC,GACpD,SAAAA,EACNF,EAASG,OAAOF,EAAWC,EAAMA,EAAKE,MACtCJ,EAASG,OAAOF,EAAWC,EACjC,CCgEe,SAASG,GACtBC,IAAKC,EAAW,WAAAC,iBAChBA,EACAC,kBAAmBC,EAA0BD,EAC7CE,SAAUC,EACVb,mBAAoBc,EAA2Bd,EAAAe,MAC/CA,EAAQC,EACRC,MAAOC,EAAAC,aACPA,EAAAC,YACAA,EAAAC,QACAA,EAAAC,kBACAA,GACE,IACF,MAAMC,EAAa,CACjBC,KAAM,CAAEF,qBACRG,QAASN,EACTC,cACAC,WAGK,OAAA,IAAIK,GAAYC,IACf,MAAAC,EASHD,EAAUE,cAKXC,iBAAiBzB,KAAEA,EAAM0B,QAAAA,GAAY,CAAE,EACvCV,QAAAA,GACEO,EAEEI,EAAgB,CACpBR,KAAMI,EAAQJ,KACdC,QAASG,EAAQT,aACjBC,YAAaQ,EAAQR,YACrBC,QAAS,IAEHhB,GAAQ,CAAE,4BAA6BA,MACvC0B,GAAW,CAAE,+BAAgCA,MAC9CV,KAIDI,QAAEA,EAASQ,KAAAA,GAASC,EACxBP,EACAZ,EACAoB,EACAZ,EACAS,IAGII,MAAEA,EAAOC,MAAAA,GAAUC,EAAaL,EAAMtB,EAAyB,IAEjE,IAAAJ,EAAMgC,EAAUZ,EAAWnB,GAE/B,GAAI6B,EAAMG,KAAM,CACVf,EAAQJ,gBAEHI,EAAQJ,QAAQ,gBAKzB,MAEMoB,EAAO,IAFW5B,GAAkBD,UAI1C6B,EAAKrC,OAAO,aAAcsC,EAAwBN,EAAO,YAGzD,MAAMO,EAAM,CAAA,EAEZ,IAAIC,EAAI,EACFP,EAAAQ,SAASC,IACTH,IAAEC,GAAKE,CAAA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