@graphql-tools/load 7.4.1-alpha-d26984bf.0 → 7.5.0-alpha-4a5363f2.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.
package/index.js CHANGED
@@ -4,12 +4,28 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) { return e; } else {
9
+ var n = {};
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () {
16
+ return e[k];
17
+ }
18
+ });
19
+ });
20
+ }
21
+ n['default'] = e;
22
+ return n;
23
+ }
24
+ }
25
+
7
26
  const utils = require('@graphql-tools/utils');
8
- const process = require('process');
9
27
  const graphql = require('graphql');
10
28
  const pLimit = _interopDefault(require('p-limit'));
11
- const module$1 = require('module');
12
- const path = require('path');
13
29
  const schema = require('@graphql-tools/schema');
14
30
 
15
31
  function normalizePointers(unnormalizedPointerOrPointers) {
@@ -41,7 +57,7 @@ function normalizePointers(unnormalizedPointerOrPointers) {
41
57
 
42
58
  function applyDefaultOptions(options) {
43
59
  options.cache = options.cache || {};
44
- options.cwd = options.cwd || process.cwd();
60
+ options.cwd = options.cwd || (process === null || process === void 0 ? void 0 : process.cwd());
45
61
  options.sort = 'sort' in options ? options.sort : true;
46
62
  }
47
63
 
@@ -57,7 +73,7 @@ async function loadFile(pointer, options) {
57
73
  loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
58
74
  }
59
75
  catch (error) {
60
- if (process.env['DEBUG']) {
76
+ if (process === null || process === void 0 ? void 0 : process.env['DEBUG']) {
61
77
  console.error(error);
62
78
  }
63
79
  if (error instanceof utils.AggregateError) {
@@ -97,7 +113,7 @@ function loadFileSync(pointer, options) {
97
113
  loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
98
114
  }
99
115
  catch (error) {
100
- if (process.env['DEBUG']) {
116
+ if (process === null || process === void 0 ? void 0 : process.env['DEBUG']) {
101
117
  console.error(error);
102
118
  }
103
119
  if (error instanceof utils.AggregateError) {
@@ -160,20 +176,23 @@ function useLimit(concurrency) {
160
176
  return pLimit(concurrency);
161
177
  }
162
178
 
163
- function getCustomLoaderByPath(path$1, cwd) {
179
+ async function getCustomLoaderByPath(pathExpression, cwd) {
164
180
  try {
165
- const requireFn = module$1.createRequire(path.join(cwd, 'noop.js'));
166
- const requiredModule = requireFn(path$1);
181
+ const [modulePath, exportName = 'default'] = pathExpression.split('#');
182
+ const absoluteFilePath = utils.isAbsolutePath(modulePath) ? modulePath : utils.joinPaths(cwd, modulePath);
183
+ const requiredModule = await new Promise(function (resolve) { resolve(_interopNamespace(require(absoluteFilePath))); });
167
184
  if (requiredModule) {
168
- if (requiredModule.default && typeof requiredModule.default === 'function') {
169
- return requiredModule.default;
185
+ if (requiredModule[exportName] && typeof requiredModule[exportName] === 'function') {
186
+ return requiredModule[exportName];
170
187
  }
171
188
  if (typeof requiredModule === 'function') {
172
189
  return requiredModule;
173
190
  }
174
191
  }
175
192
  }
176
- catch (e) { }
193
+ catch (e) {
194
+ console.log(e);
195
+ }
177
196
  return null;
178
197
  }
179
198
  async function useCustomLoader(loaderPointer, cwd) {
@@ -400,7 +419,7 @@ const filterKind = (content, filterKinds) => {
400
419
  }
401
420
  }
402
421
  if (invalidDefinitions.length > 0) {
403
- if (process.env['DEBUG']) {
422
+ if (process === null || process === void 0 ? void 0 : process.env['DEBUG']) {
404
423
  for (const d of invalidDefinitions) {
405
424
  console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
406
425
  }
package/index.mjs CHANGED
@@ -1,9 +1,6 @@
1
- import { asArray, AggregateError, isDocumentString, parseGraphQLSDL, getDocumentNodeFromSchema, printSchemaWithDirectives, printWithComments, resetComments, compareStrings } from '@graphql-tools/utils';
2
- import { cwd, env } from 'process';
1
+ import { asArray, AggregateError, isAbsolutePath, joinPaths, isDocumentString, parseGraphQLSDL, getDocumentNodeFromSchema, printSchemaWithDirectives, printWithComments, resetComments, compareStrings } from '@graphql-tools/utils';
3
2
  import { isSchema, Kind, lexicographicSortSchema, Source, print } from 'graphql';
4
3
  import pLimit from 'p-limit';
5
- import { createRequire } from 'module';
6
- import { join } from 'path';
7
4
  import { mergeSchemas } from '@graphql-tools/schema';
8
5
 
9
6
  function normalizePointers(unnormalizedPointerOrPointers) {
@@ -35,7 +32,7 @@ function normalizePointers(unnormalizedPointerOrPointers) {
35
32
 
36
33
  function applyDefaultOptions(options) {
37
34
  options.cache = options.cache || {};
38
- options.cwd = options.cwd || cwd();
35
+ options.cwd = options.cwd || (process === null || process === void 0 ? void 0 : process.cwd());
39
36
  options.sort = 'sort' in options ? options.sort : true;
40
37
  }
41
38
 
@@ -51,7 +48,7 @@ async function loadFile(pointer, options) {
51
48
  loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
52
49
  }
53
50
  catch (error) {
54
- if (env['DEBUG']) {
51
+ if (process === null || process === void 0 ? void 0 : process.env['DEBUG']) {
55
52
  console.error(error);
56
53
  }
57
54
  if (error instanceof AggregateError) {
@@ -91,7 +88,7 @@ function loadFileSync(pointer, options) {
91
88
  loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
92
89
  }
93
90
  catch (error) {
94
- if (env['DEBUG']) {
91
+ if (process === null || process === void 0 ? void 0 : process.env['DEBUG']) {
95
92
  console.error(error);
96
93
  }
97
94
  if (error instanceof AggregateError) {
@@ -154,20 +151,23 @@ function useLimit(concurrency) {
154
151
  return pLimit(concurrency);
155
152
  }
156
153
 
157
- function getCustomLoaderByPath(path, cwd) {
154
+ async function getCustomLoaderByPath(pathExpression, cwd) {
158
155
  try {
159
- const requireFn = createRequire(join(cwd, 'noop.js'));
160
- const requiredModule = requireFn(path);
156
+ const [modulePath, exportName = 'default'] = pathExpression.split('#');
157
+ const absoluteFilePath = isAbsolutePath(modulePath) ? modulePath : joinPaths(cwd, modulePath);
158
+ const requiredModule = await import(absoluteFilePath);
161
159
  if (requiredModule) {
162
- if (requiredModule.default && typeof requiredModule.default === 'function') {
163
- return requiredModule.default;
160
+ if (requiredModule[exportName] && typeof requiredModule[exportName] === 'function') {
161
+ return requiredModule[exportName];
164
162
  }
165
163
  if (typeof requiredModule === 'function') {
166
164
  return requiredModule;
167
165
  }
168
166
  }
169
167
  }
170
- catch (e) { }
168
+ catch (e) {
169
+ console.log(e);
170
+ }
171
171
  return null;
172
172
  }
173
173
  async function useCustomLoader(loaderPointer, cwd) {
@@ -394,7 +394,7 @@ const filterKind = (content, filterKinds) => {
394
394
  }
395
395
  }
396
396
  if (invalidDefinitions.length > 0) {
397
- if (env['DEBUG']) {
397
+ if (process === null || process === void 0 ? void 0 : process.env['DEBUG']) {
398
398
  for (const d of invalidDefinitions) {
399
399
  console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
400
400
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-tools/load",
3
- "version": "7.4.1-alpha-d26984bf.0",
3
+ "version": "7.5.0-alpha-4a5363f2.0",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/schema": "8.3.1-alpha-d26984bf.0",
11
- "@graphql-tools/utils": "8.5.0-alpha-d26984bf.0",
10
+ "@graphql-tools/schema": "8.3.1-alpha-4a5363f2.0",
11
+ "@graphql-tools/utils": "8.6.0-alpha-4a5363f2.0",
12
12
  "p-limit": "3.1.0",
13
13
  "tslib": "~2.3.0"
14
14
  },
@@ -1,3 +1,4 @@
1
- export declare function getCustomLoaderByPath(path: string, cwd: string): any;
1
+ export declare function getCustomLoaderByPath(pathExpression: string, cwd: string): Promise<any>;
2
+ export declare function getCustomLoaderByPathSync(pathExpression: string, cwd: string): any;
2
3
  export declare function useCustomLoader(loaderPointer: any, cwd: string): Promise<any>;
3
4
  export declare function useCustomLoaderSync(loaderPointer: any, cwd: string): any;