diff --git a/types/apollo-upload-client/UploadHttpLink.d.mts b/types/apollo-upload-client/UploadHttpLink.d.mts new file mode 100644 index 00000000000000..0d6b0c20196eaf --- /dev/null +++ b/types/apollo-upload-client/UploadHttpLink.d.mts @@ -0,0 +1,90 @@ +import { ApolloLink } from "@apollo/client/link"; +import { BaseHttpLink, selectURI } from "@apollo/client/link/http"; + +interface UploadHttpLinkOptions { + /** + * @param {Parameters[1]} [options.uri] GraphQL endpoint + * URI. Defaults to `"/graphql"`. + */ + uri?: Parameters[1]; + + /** + * @param {boolean} [options.useGETForQueries] Should GET be used to fetch + * queries, if there are no files to upload. + */ + useGETForQueries?: boolean; + + /** + * @param {ExtractableFileMatcher} [options.isExtractableFile] Matches + * extractable files in the GraphQL operation. Defaults to + * {@linkcode isExtractableFile}. + */ + isExtractableFile?: ExtractableFileMatcher; + + /** + * @param {typeof FormData} [options.FormData] + * `FormData` class. Defaults to the {@linkcode FormData} global. + */ + FormData?: typeof FormData; + + /** + * @param {FormDataFileAppender} [options.formDataAppendFile] + * Customizes how extracted files are appended to the `FormData` instance. + * Defaults to {@linkcode formDataAppendFile}. + */ + formDataAppendFile?: FormDataFileAppender; + + print?: BaseHttpLink.Printer; + + /** + * @param {typeof fetch} [options.fetch] + * `fetch` implementation. Defaults to the {@linkcode fetch} global. + */ + fetch?: typeof fetch; + + /** + * @param {RequestInit} [options.fetchOptions] `fetch` options; overridden by + * upload requirements. + */ + fetchOptions?: RequestInit; + + /** + * @param {string} [options.credentials] Overrides + * {@linkcode RequestInit.credentials credentials} in {@linkcode fetchOptions}. + */ + credentials?: string; + + /** + * @param {{ [headerName: string]: string }} [options.headers] Merges with and + * overrides {@linkcode RequestInit.headers headers} in {@linkcode fetchOptions}. + */ + headers?: { [headerName: string]: string }; + + /** + * @param {boolean} [options.includeExtensions] Toggles sending `extensions` + * fields to the GraphQL server. Defaults to `false`. + */ + includeExtensions?: boolean; + + /** + * @param {boolean} [options.includeUnusedVariables] Toggles including unused + * GraphQL variables in the request. Defaults to `false`. + */ + includeUnusedVariables?: boolean; +} + +export default class UploadHttpLink extends ApolloLink { + constructor( + options?: UploadHttpLinkOptions, + ); +} + +type ExtractableFileMatcher = (value: unknown) => value is ExtractableFile; + +type FormDataFileAppender = ( + formData: FormData, + fieldName: string, + file: ExtractableFile, +) => any; + +export { ExtractableFileMatcher, FormDataFileAppender }; diff --git a/types/apollo-upload-client/apollo-upload-client-tests.ts b/types/apollo-upload-client/apollo-upload-client-tests.ts index f7eb541a796fe2..964c0668feed62 100644 --- a/types/apollo-upload-client/apollo-upload-client-tests.ts +++ b/types/apollo-upload-client/apollo-upload-client-tests.ts @@ -1,11 +1,11 @@ -import createUploadLink from "apollo-upload-client/createUploadLink.mjs"; import formDataAppendFile from "apollo-upload-client/formDataAppendFile.mjs"; import isExtractableFile from "apollo-upload-client/isExtractableFile.mjs"; +import UploadHttpLink from "apollo-upload-client/UploadHttpLink.mjs"; // ============================================================================== -// createUploadLink +// UploadHttpLink // ============================================================================== -createUploadLink({ +new UploadHttpLink({ uri: "http://localhost", isExtractableFile, formDataAppendFile, diff --git a/types/apollo-upload-client/createUploadLink.d.mts b/types/apollo-upload-client/createUploadLink.d.mts deleted file mode 100644 index 3b70e5e474e64a..00000000000000 --- a/types/apollo-upload-client/createUploadLink.d.mts +++ /dev/null @@ -1,45 +0,0 @@ -import { ApolloLink } from "@apollo/client/link/core/ApolloLink.js"; - -export default function createUploadLink( - { - uri: fetchUri, - useGETForQueries, - isExtractableFile: customIsExtractableFile, - FormData: CustomFormData, - formDataAppendFile: customFormDataAppendFile, - print, - fetch: customFetch, - fetchOptions, - credentials, - headers, - includeExtensions, - }?: { - uri?: [ - operation: import("@apollo/client/core").Operation, - fallbackURI?: string | ((operation: import("@apollo/client/core").Operation) => string) | undefined, - ][1]; - useGETForQueries?: boolean | undefined; - isExtractableFile?: ExtractableFileMatcher | undefined; - FormData?: { - new(form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData; - prototype: FormData; - } | undefined; - formDataAppendFile?: FormDataFileAppender | undefined; - print?: import("@apollo/client/link/http/selectHttpOptionsAndBody.js").Printer | undefined; - fetch?: typeof fetch | undefined; - fetchOptions?: RequestInit | undefined; - credentials?: string | undefined; - headers?: { - [headerName: string]: string; - } | undefined; - includeExtensions?: boolean | undefined; - }, -): ApolloLink; - -export type ExtractableFileMatcher = (value: unknown) => value is ExtractableFile; - -export type FormDataFileAppender = ( - formData: FormData, - fieldName: string, - file: ExtractableFile, -) => any; diff --git a/types/apollo-upload-client/package.json b/types/apollo-upload-client/package.json index cb73b1dc63d2d8..51c07babefed3f 100644 --- a/types/apollo-upload-client/package.json +++ b/types/apollo-upload-client/package.json @@ -1,13 +1,13 @@ { "private": true, "name": "@types/apollo-upload-client", - "version": "18.0.9999", + "version": "19.0.9999", "projects": [ "https://github.com/jaydenseric/apollo-upload-client#readme" ], "exports": { - "./createUploadLink.mjs": { - "types": "./createUploadLink.d.mts" + "./UploadHttpLink.mjs": { + "types": "./UploadHttpLink.d.mts" }, "./formDataAppendFile.mjs": { "types": "./formDataAppendFile.d.mts" @@ -18,7 +18,7 @@ "./package.json": "./package.json" }, "dependencies": { - "@apollo/client": "^3.8.0", + "@apollo/client": "^4.0.0", "@types/extract-files": "*", "graphql": "14 - 16" }, diff --git a/types/apollo-upload-client/tsconfig.json b/types/apollo-upload-client/tsconfig.json index e311ee0056ff3b..3c515c110766bc 100644 --- a/types/apollo-upload-client/tsconfig.json +++ b/types/apollo-upload-client/tsconfig.json @@ -18,7 +18,7 @@ "files": [ "index.d.ts", "apollo-upload-client-tests.ts", - "createUploadLink.d.mts", + "UploadHttpLink.d.mts", "formDataAppendFile.d.mts", "isExtractableFile.d.mts" ]