@graphql-tools/url-loader 7.13.4 → 7.13.5-alpha-20220810092901-11f0084b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -67,6 +67,14 @@ class UrlLoader {
67
67
  (0, utils_1.isAsyncIterable)(v) ||
68
68
  (v === null || v === void 0 ? void 0 : v.then) ||
69
69
  typeof (v === null || v === void 0 ? void 0 : v.arrayBuffer) === 'function'));
70
+ if (files.size === 0) {
71
+ return JSON.stringify({
72
+ query,
73
+ variables,
74
+ operationName,
75
+ extensions,
76
+ });
77
+ }
70
78
  const map = {};
71
79
  const uploads = [];
72
80
  let currIndex = 0;
@@ -199,11 +207,14 @@ class UrlLoader {
199
207
  case 'POST':
200
208
  if (options === null || options === void 0 ? void 0 : options.multipart) {
201
209
  return new value_or_promise_1.ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
202
- .then(form => fetch(endpoint, {
210
+ .then(body => fetch(endpoint, {
203
211
  method: 'POST',
204
212
  ...(credentials != null ? { credentials } : {}),
205
- body: form,
206
- headers,
213
+ body,
214
+ headers: {
215
+ ...headers,
216
+ ...(typeof body === 'string' ? { 'content-type': 'application/json' } : {}),
217
+ },
207
218
  signal: controller.signal,
208
219
  }))
209
220
  .resolve();
package/esm/index.js CHANGED
@@ -63,6 +63,14 @@ export class UrlLoader {
63
63
  isAsyncIterable(v) ||
64
64
  (v === null || v === void 0 ? void 0 : v.then) ||
65
65
  typeof (v === null || v === void 0 ? void 0 : v.arrayBuffer) === 'function'));
66
+ if (files.size === 0) {
67
+ return JSON.stringify({
68
+ query,
69
+ variables,
70
+ operationName,
71
+ extensions,
72
+ });
73
+ }
66
74
  const map = {};
67
75
  const uploads = [];
68
76
  let currIndex = 0;
@@ -195,11 +203,14 @@ export class UrlLoader {
195
203
  case 'POST':
196
204
  if (options === null || options === void 0 ? void 0 : options.multipart) {
197
205
  return new ValueOrPromise(() => this.createFormDataFromVariables(requestBody))
198
- .then(form => fetch(endpoint, {
206
+ .then(body => fetch(endpoint, {
199
207
  method: 'POST',
200
208
  ...(credentials != null ? { credentials } : {}),
201
- body: form,
202
- headers,
209
+ body,
210
+ headers: {
211
+ ...headers,
212
+ ...(typeof body === 'string' ? { 'content-type': 'application/json' } : {}),
213
+ },
203
214
  signal: controller.signal,
204
215
  }))
205
216
  .resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/url-loader",
3
- "version": "7.13.4",
3
+ "version": "7.13.5-alpha-20220810092901-11f0084b",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -120,7 +120,7 @@ export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
120
120
  variables: TVariables;
121
121
  operationName?: string;
122
122
  extensions?: any;
123
- }): FormData | Promise<FormData>;
123
+ }): string | FormData | Promise<FormData>;
124
124
  prepareGETUrl({ baseUrl, query, variables, operationName, extensions, }: {
125
125
  baseUrl: string;
126
126
  query: string;
@@ -120,7 +120,7 @@ export declare class UrlLoader implements Loader<LoadFromUrlOptions> {
120
120
  variables: TVariables;
121
121
  operationName?: string;
122
122
  extensions?: any;
123
- }): FormData | Promise<FormData>;
123
+ }): string | FormData | Promise<FormData>;
124
124
  prepareGETUrl({ baseUrl, query, variables, operationName, extensions, }: {
125
125
  baseUrl: string;
126
126
  query: string;