@graphql-mesh/config 2.1.0-alpha-49f1a5d8a.0 → 2.1.0-alpha-1f8e9e5a3.0

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.
Files changed (3) hide show
  1. package/index.js +21 -1
  2. package/index.mjs +21 -1
  3. package/package.json +3 -1
package/index.js CHANGED
@@ -14,6 +14,8 @@ const store = require('@graphql-mesh/store');
14
14
  const pascalCase = require('pascal-case');
15
15
  const camelCase = require('camel-case');
16
16
  const core = require('@envelop/core');
17
+ const crossUndiciFetch = require('cross-undici-fetch');
18
+ const fetchache = require('fetchache');
17
19
 
18
20
  async function getPackage({ name, type, importFn, cwd, additionalPrefixes = [], }) {
19
21
  const casedName = paramCase.paramCase(name);
@@ -293,6 +295,22 @@ async function processConfig(config, options) {
293
295
  const { cache, importCode: cacheImportCode, code: cacheCode, } = await resolveCache(config.cache, importFn, rootStore, dir, pubsub, additionalPackagePrefixes);
294
296
  importCodes.push(cacheImportCode);
295
297
  codes.push(cacheCode);
298
+ if (config.customFetch) {
299
+ importCodes.push(`import fetchFn from ${JSON.stringify(config.customFetch)}`);
300
+ }
301
+ else {
302
+ importCodes.push(`import { fetchFactory } from 'fetchache';`);
303
+ importCodes.push(`import { fetch, Request, Response } from 'cross-undici-fetch';`);
304
+ codes.push('const fetchFn = fetchFactory({ cache, fetch, Request, Response });');
305
+ }
306
+ const fetchFn = config.customFetch
307
+ ? await importFn(config.customFetch, true)
308
+ : fetchache.fetchFactory({
309
+ cache,
310
+ fetch: crossUndiciFetch.fetch,
311
+ Request: crossUndiciFetch.Request,
312
+ Response: crossUndiciFetch.Response,
313
+ });
296
314
  const sourcesStore = rootStore.child('sources');
297
315
  codes.push(`const sourcesStore = rootStore.child('sources');`);
298
316
  const { logger, importCode: loggerImportCode, code: loggerCode, } = await resolveLogger(config.logger, importFn, dir, additionalPackagePrefixes, options === null || options === void 0 ? void 0 : options.initialLoggerPrefix);
@@ -328,7 +346,8 @@ async function processConfig(config, options) {
328
346
  pubsub,
329
347
  store: sourcesStore.child(${JSON.stringify(source.name)}),
330
348
  logger: logger.child(${JSON.stringify(source.name)}),
331
- importFn
349
+ importFn,
350
+ fetchFn,
332
351
  });`);
333
352
  }
334
353
  return new HandlerCtor({
@@ -340,6 +359,7 @@ async function processConfig(config, options) {
340
359
  store: sourcesStore.child(source.name),
341
360
  logger: logger.child(source.name),
342
361
  importFn,
362
+ fetchFn,
343
363
  });
344
364
  }),
345
365
  Promise.all((source.transforms || []).map(async (t, transformIndex) => {
package/index.mjs CHANGED
@@ -10,6 +10,8 @@ import { MeshStore, FsStoreStorageAdapter, InMemoryStoreStorageAdapter } from '@
10
10
  import { pascalCase } from 'pascal-case';
11
11
  import { camelCase } from 'camel-case';
12
12
  import { useMaskedErrors, useImmediateIntrospection } from '@envelop/core';
13
+ import { fetch, Request, Response } from 'cross-undici-fetch';
14
+ import { fetchFactory } from 'fetchache';
13
15
 
14
16
  async function getPackage({ name, type, importFn, cwd, additionalPrefixes = [], }) {
15
17
  const casedName = paramCase(name);
@@ -289,6 +291,22 @@ async function processConfig(config, options) {
289
291
  const { cache, importCode: cacheImportCode, code: cacheCode, } = await resolveCache(config.cache, importFn, rootStore, dir, pubsub, additionalPackagePrefixes);
290
292
  importCodes.push(cacheImportCode);
291
293
  codes.push(cacheCode);
294
+ if (config.customFetch) {
295
+ importCodes.push(`import fetchFn from ${JSON.stringify(config.customFetch)}`);
296
+ }
297
+ else {
298
+ importCodes.push(`import { fetchFactory } from 'fetchache';`);
299
+ importCodes.push(`import { fetch, Request, Response } from 'cross-undici-fetch';`);
300
+ codes.push('const fetchFn = fetchFactory({ cache, fetch, Request, Response });');
301
+ }
302
+ const fetchFn = config.customFetch
303
+ ? await importFn(config.customFetch, true)
304
+ : fetchFactory({
305
+ cache,
306
+ fetch,
307
+ Request,
308
+ Response,
309
+ });
292
310
  const sourcesStore = rootStore.child('sources');
293
311
  codes.push(`const sourcesStore = rootStore.child('sources');`);
294
312
  const { logger, importCode: loggerImportCode, code: loggerCode, } = await resolveLogger(config.logger, importFn, dir, additionalPackagePrefixes, options === null || options === void 0 ? void 0 : options.initialLoggerPrefix);
@@ -324,7 +342,8 @@ async function processConfig(config, options) {
324
342
  pubsub,
325
343
  store: sourcesStore.child(${JSON.stringify(source.name)}),
326
344
  logger: logger.child(${JSON.stringify(source.name)}),
327
- importFn
345
+ importFn,
346
+ fetchFn,
328
347
  });`);
329
348
  }
330
349
  return new HandlerCtor({
@@ -336,6 +355,7 @@ async function processConfig(config, options) {
336
355
  store: sourcesStore.child(source.name),
337
356
  logger: logger.child(source.name),
338
357
  importFn,
358
+ fetchFn,
339
359
  });
340
360
  }),
341
361
  Promise.all((source.transforms || []).map(async (t, transformIndex) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/config",
3
- "version": "2.1.0-alpha-49f1a5d8a.0",
3
+ "version": "2.1.0-alpha-1f8e9e5a3.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@graphql-mesh/runtime": "^0.38.0",
@@ -20,6 +20,8 @@
20
20
  "@graphql-tools/load": "7.5.14",
21
21
  "@graphql-tools/utils": "8.6.13",
22
22
  "camel-case": "4.1.2",
23
+ "cross-undici-fetch": "0.4.7",
24
+ "fetchache": "0.1.2",
23
25
  "param-case": "3.0.4",
24
26
  "pascal-case": "3.1.2",
25
27
  "tslib": "^2.4.0"