diff --git a/types/apollo-upload-client/apollo-upload-client-tests.ts b/types/apollo-upload-client/apollo-upload-client-tests.ts index 4db60bfaf3..3018b5a42e 100644 --- a/types/apollo-upload-client/apollo-upload-client-tests.ts +++ b/types/apollo-upload-client/apollo-upload-client-tests.ts @@ -1,16 +1,50 @@ -import { createUploadLink, ReactNativeFile } from "apollo-upload-client"; +import { + UploadLinkOptions, + createUploadLink, + formDataAppendFile, + ReactNativeFile, + isExtractableFile, +} from 'apollo-upload-client'; +// ============================================================================== +// UploadLinkOptions +// ============================================================================== +const uploadLinkOptions: UploadLinkOptions = { + uri: 'http://localhost', + isExtractableFile, + formDataAppendFile, + useGETForQueries: true, + fetch: (uri, options) => fetch(`http://localhost/${uri}`, options), + fetchOptions: { method: 'GET' }, + headers: { special: 'Special header value' }, + includeExtensions: true, + credentials: 'beepboop', +}; + +// ============================================================================== +// createUploadLink +// ============================================================================== +createUploadLink(uploadLinkOptions); + +// ============================================================================== +// formDataAppendFile +// ============================================================================== +const form: HTMLFormElement | undefined = undefined; +const formData = new FormData(form); +const fieldName = 'field name'; +const file = new Blob(); +formDataAppendFile(formData, fieldName, file); + +// ============================================================================== +// ReactNativeFile +// ============================================================================== new ReactNativeFile({ - name: "its coming home", - type: "its coming", + name: 'its coming home', + type: 'its coming', uri: "football's coming home", }); -createUploadLink({ - fetch: (uri, options) => fetch(`http://localhost/${uri}`, options), - fetchOptions: { method: "GET" }, - headers: { special: "Special header value" }, - includeExtensions: true, - uri: "http://localhost", - credentials: "beepboop", -}); +// ============================================================================== +// isExtractableFile +// ============================================================================== +isExtractableFile(''); diff --git a/types/apollo-upload-client/index.d.ts b/types/apollo-upload-client/index.d.ts index b219b84510..d992decf41 100644 --- a/types/apollo-upload-client/index.d.ts +++ b/types/apollo-upload-client/index.d.ts @@ -1,22 +1,52 @@ -// Type definitions for apollo-upload-client 8.1 +// Type definitions for apollo-upload-client 14.1 // Project: https://github.com/jaydenseric/apollo-upload-client#readme -// Definitions by: Edward Sammut Alessi +// Definitions by: Edward Sammut Alessi , tyankatsu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.1 +// TypeScript Version: 3.6 -import { ApolloLink } from "apollo-link"; -import { HttpOptions } from "apollo-link-http-common"; +// ============================================================================== +// imports +// ============================================================================== -export { ReactNativeFile } from "extract-files"; +import { ApolloLink } from '@apollo/client/core'; +import { HttpOptions } from '@apollo/client/link/http'; +import { isExtractableFile, ExtractableFile } from 'extract-files'; + +// ============================================================================== +// declare +// ============================================================================== declare global { interface GlobalFetch { - fetch: WindowOrWorkerGlobalScope["fetch"]; + fetch: WindowOrWorkerGlobalScope['fetch']; } } +// ============================================================================== +// types +// ============================================================================== + +export type UploadLinkOptions = HttpOptions & + Partial<{ + isExtractableFile: typeof isExtractableFile; + formDataAppendFile: typeof formDataAppendFile; + }>; + +// ============================================================================== +// export +// ============================================================================== + +export { ReactNativeFile, isExtractableFile } from 'extract-files'; + /** - * `createUploadLink` options match `createHttpLink` options - * @param linkOptions `HttpOptions` + * Creates a [terminating Apollo Link](https://www.apollographql.com/docs/link/overview/#terminating-links) capable of file uploads. + * @see https://github.com/jaydenseric/apollo-upload-client#function-createuploadlink */ -export function createUploadLink(linkOptions?: HttpOptions): ApolloLink; +export function createUploadLink(uploadLinkOptions?: UploadLinkOptions): ApolloLink; + +/** + * The default implementation for [`createUploadLink`](https://github.com/jaydenseric/apollo-upload-client#function-createuploadlink) `options.formDataAppendFile` + * that uses the standard [`FormData.append`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/append) method. + * @see https://github.com/jaydenseric/apollo-upload-client#function-formdataappendfile + */ +export function formDataAppendFile(formData: FormData, fieldName: string, file: ExtractableFile): void; diff --git a/types/apollo-upload-client/package.json b/types/apollo-upload-client/package.json index 6f942a3b01..e0d191f260 100644 --- a/types/apollo-upload-client/package.json +++ b/types/apollo-upload-client/package.json @@ -1,8 +1,7 @@ { "private": true, "dependencies": { - "apollo-link": "^1.2.12", - "apollo-link-http-common": "^0.2.4", - "graphql": "^14.5.3" + "@apollo/client": "^3.1.3", + "graphql": "^15.3.0" } } diff --git a/types/apollo-upload-client/tsconfig.json b/types/apollo-upload-client/tsconfig.json index a78e75500c..60b83ed89e 100644 --- a/types/apollo-upload-client/tsconfig.json +++ b/types/apollo-upload-client/tsconfig.json @@ -16,7 +16,8 @@ ], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true }, "files": [ "index.d.ts",