@graphql-tools/executor-http
Advanced tools
Comparing version 0.1.5-alpha-20230206141333-eca45023 to 0.1.5-alpha-20230206142014-5dc7b19e
@@ -9,3 +9,3 @@ "use strict"; | ||
const fetch_1 = require("@whatwg-node/fetch"); | ||
function createFormDataFromVariables({ query, variables, operationName, extensions, }) { | ||
function createFormDataFromVariables({ query, variables, operationName, extensions, }, { File: FileCtor = fetch_1.File, FormData: FormDataCtor = fetch_1.FormData, }) { | ||
const vars = Object.assign({}, variables); | ||
@@ -33,3 +33,3 @@ const { clone, files } = (0, extract_files_1.extractFiles)(vars, 'variables', ((v) => (0, extract_files_1.isExtractableFile)(v) || | ||
} | ||
const form = new fetch_1.FormData(); | ||
const form = new FormDataCtor(); | ||
form.append('operations', JSON.stringify({ | ||
@@ -63,7 +63,7 @@ query, | ||
const blobPart = new Uint8Array(chunks); | ||
form.append(indexStr, new fetch_1.File([blobPart], filename, { type: upload.mimetype }), filename); | ||
form.append(indexStr, new FileCtor([blobPart], filename, { type: upload.mimetype }), filename); | ||
}); | ||
} | ||
else { | ||
form.append(indexStr, new fetch_1.File([upload], filename), filename); | ||
form.append(indexStr, new FileCtor([upload], filename), filename); | ||
} | ||
@@ -70,0 +70,0 @@ } |
@@ -65,3 +65,6 @@ "use strict"; | ||
case 'POST': | ||
return new value_or_promise_1.ValueOrPromise(() => (0, createFormDataFromVariables_js_1.createFormDataFromVariables)(requestBody)) | ||
return new value_or_promise_1.ValueOrPromise(() => (0, createFormDataFromVariables_js_1.createFormDataFromVariables)(requestBody, { | ||
File: options === null || options === void 0 ? void 0 : options.File, | ||
FormData: options === null || options === void 0 ? void 0 : options.FormData, | ||
})) | ||
.then(body => fetchFn(endpoint, { | ||
@@ -68,0 +71,0 @@ method: 'POST', |
@@ -5,4 +5,4 @@ import { isAsyncIterable, isPromise } from '@graphql-tools/utils'; | ||
import { ValueOrPromise } from 'value-or-promise'; | ||
import { FormData, File } from '@whatwg-node/fetch'; | ||
export function createFormDataFromVariables({ query, variables, operationName, extensions, }) { | ||
import { FormData as DefaultFormData, File as DefaultFile } from '@whatwg-node/fetch'; | ||
export function createFormDataFromVariables({ query, variables, operationName, extensions, }, { File: FileCtor = DefaultFile, FormData: FormDataCtor = DefaultFormData, }) { | ||
const vars = Object.assign({}, variables); | ||
@@ -30,3 +30,3 @@ const { clone, files } = extractFiles(vars, 'variables', ((v) => isExtractableFile(v) || | ||
} | ||
const form = new FormData(); | ||
const form = new FormDataCtor(); | ||
form.append('operations', JSON.stringify({ | ||
@@ -60,7 +60,7 @@ query, | ||
const blobPart = new Uint8Array(chunks); | ||
form.append(indexStr, new File([blobPart], filename, { type: upload.mimetype }), filename); | ||
form.append(indexStr, new FileCtor([blobPart], filename, { type: upload.mimetype }), filename); | ||
}); | ||
} | ||
else { | ||
form.append(indexStr, new File([upload], filename), filename); | ||
form.append(indexStr, new FileCtor([upload], filename), filename); | ||
} | ||
@@ -67,0 +67,0 @@ } |
@@ -61,3 +61,6 @@ import { createGraphQLError, getOperationASTFromRequest, } from '@graphql-tools/utils'; | ||
case 'POST': | ||
return new ValueOrPromise(() => createFormDataFromVariables(requestBody)) | ||
return new ValueOrPromise(() => createFormDataFromVariables(requestBody, { | ||
File: options === null || options === void 0 ? void 0 : options.File, | ||
FormData: options === null || options === void 0 ? void 0 : options.FormData, | ||
})) | ||
.then(body => fetchFn(endpoint, { | ||
@@ -64,0 +67,0 @@ method: 'POST', |
{ | ||
"name": "@graphql-tools/executor-http", | ||
"version": "0.1.5-alpha-20230206141333-eca45023", | ||
"version": "0.1.5-alpha-20230206142014-5dc7b19e", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -10,3 +10,3 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@graphql-tools/utils": "9.2.1-alpha-20230206141333-eca45023", | ||
"@graphql-tools/utils": "9.2.1-alpha-20230206142014-5dc7b19e", | ||
"value-or-promise": "^1.0.12", | ||
@@ -13,0 +13,0 @@ "@whatwg-node/fetch": "^0.6.9", |
@@ -0,1 +1,2 @@ | ||
import { FormData as DefaultFormData } from '@whatwg-node/fetch'; | ||
export declare function createFormDataFromVariables<TVariables>({ query, variables, operationName, extensions, }: { | ||
@@ -6,2 +7,5 @@ query: string; | ||
extensions?: any; | ||
}, { File: FileCtor, FormData: FormDataCtor, }: { | ||
File?: typeof File; | ||
FormData?: typeof DefaultFormData; | ||
}): string | FormData | Promise<FormData>; |
@@ -42,2 +42,12 @@ import { AsyncExecutor, ExecutionRequest, SyncExecutor } from '@graphql-tools/utils'; | ||
retry?: number; | ||
/** | ||
* WHATWG compatible File implementation | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/File | ||
*/ | ||
File?: typeof File; | ||
/** | ||
* WHATWG compatible FormData implementation | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/FormData | ||
*/ | ||
FormData?: typeof FormData; | ||
} | ||
@@ -44,0 +54,0 @@ export type HeadersConfig = Record<string, string>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52642
1046
+ Added@graphql-tools/utils@9.2.1-alpha-20230206142014-5dc7b19e(transitive)
- Removed@graphql-tools/utils@9.2.1-alpha-20230206141333-eca45023(transitive)
Updated@graphql-tools/utils@9.2.1-alpha-20230206142014-5dc7b19e