@graphql-tools/load 7.7.7 → 7.8.0-alpha-20221018160054-b827d116

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.
@@ -34,6 +34,9 @@ const module_1 = require("module");
34
34
  const process_1 = require("process");
35
35
  const CONCURRENCY_LIMIT = 50;
36
36
  async function collectSources({ pointerOptionMap, options, }) {
37
+ if (process_1.env['DEBUG'] != null) {
38
+ console.time('@graphql-tools/load: collectSources');
39
+ }
37
40
  const sources = [];
38
41
  const queue = (0, queue_js_1.useQueue)({ concurrency: CONCURRENCY_LIMIT });
39
42
  const { addSource, collect } = createHelpers({
@@ -42,6 +45,9 @@ async function collectSources({ pointerOptionMap, options, }) {
42
45
  });
43
46
  for (const pointer in pointerOptionMap) {
44
47
  const pointerOptions = pointerOptionMap[pointer];
48
+ if (process_1.env['DEBUG'] != null) {
49
+ console.time(`@graphql-tools/load: collectSources ${pointer}`);
50
+ }
45
51
  collect({
46
52
  pointer,
47
53
  pointerOptions,
@@ -50,8 +56,17 @@ async function collectSources({ pointerOptionMap, options, }) {
50
56
  addSource,
51
57
  queue: queue.add,
52
58
  });
59
+ if (process_1.env['DEBUG'] != null) {
60
+ console.timeEnd(`@graphql-tools/load: collectSources ${pointer}`);
61
+ }
62
+ }
63
+ if (process_1.env['DEBUG'] != null) {
64
+ console.time('@graphql-tools/load: collectSources queue');
53
65
  }
54
66
  await queue.runAll();
67
+ if (process_1.env['DEBUG'] != null) {
68
+ console.timeEnd('@graphql-tools/load: collectSources queue');
69
+ }
55
70
  return sources;
56
71
  }
57
72
  exports.collectSources = collectSources;
@@ -62,8 +77,14 @@ function collectSourcesSync({ pointerOptionMap, options, }) {
62
77
  sources,
63
78
  stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
64
79
  });
80
+ if (process_1.env['DEBUG'] != null) {
81
+ console.time('@graphql-tools/load: collectSourcesSync');
82
+ }
65
83
  for (const pointer in pointerOptionMap) {
66
84
  const pointerOptions = pointerOptionMap[pointer];
85
+ if (process_1.env['DEBUG'] != null) {
86
+ console.time(`@graphql-tools/load: collectSourcesSync ${pointer}`);
87
+ }
67
88
  collect({
68
89
  pointer,
69
90
  pointerOptions,
@@ -72,8 +93,17 @@ function collectSourcesSync({ pointerOptionMap, options, }) {
72
93
  addSource,
73
94
  queue: queue.add,
74
95
  });
96
+ if (process_1.env['DEBUG'] != null) {
97
+ console.timeEnd(`@graphql-tools/load: collectSourcesSync ${pointer}`);
98
+ }
99
+ }
100
+ if (process_1.env['DEBUG'] != null) {
101
+ console.time('@graphql-tools/load: collectSourcesSync queue');
75
102
  }
76
103
  queue.runAll();
104
+ if (process_1.env['DEBUG'] != null) {
105
+ console.timeEnd('@graphql-tools/load: collectSourcesSync queue');
106
+ }
77
107
  return sources;
78
108
  }
79
109
  exports.collectSourcesSync = collectSourcesSync;
@@ -88,6 +118,9 @@ function createHelpers({ sources, stack }) {
88
118
  };
89
119
  }
90
120
  function addResultOfCustomLoader({ pointer, result, addSource, }) {
121
+ if (process_1.env['DEBUG'] != null) {
122
+ console.time(`@graphql-tools/load: addResultOfCustomLoader ${pointer}`);
123
+ }
91
124
  if ((0, graphql_1.isSchema)(result)) {
92
125
  addSource({
93
126
  source: {
@@ -117,8 +150,14 @@ function addResultOfCustomLoader({ pointer, result, addSource, }) {
117
150
  pointer,
118
151
  });
119
152
  }
153
+ if (process_1.env['DEBUG'] != null) {
154
+ console.timeEnd(`@graphql-tools/load: addResultOfCustomLoader ${pointer}`);
155
+ }
120
156
  }
121
157
  function collectDocumentString({ pointer, pointerOptions, options, addSource, queue }, next) {
158
+ if (process_1.env['DEBUG'] != null) {
159
+ console.time(`@graphql-tools/load: collectDocumentString ${pointer}`);
160
+ }
122
161
  if ((0, utils_1.isDocumentString)(pointer)) {
123
162
  return queue(() => {
124
163
  const source = (0, utils_1.parseGraphQLSDL)(`${(0, helpers_js_1.stringToHash)(pointer)}.graphql`, pointer, {
@@ -131,16 +170,25 @@ function collectDocumentString({ pointer, pointerOptions, options, addSource, qu
131
170
  });
132
171
  });
133
172
  }
173
+ if (process_1.env['DEBUG'] != null) {
174
+ console.timeEnd(`@graphql-tools/load: collectDocumentString ${pointer}`);
175
+ }
134
176
  next();
135
177
  }
136
178
  function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
137
179
  if (pointerOptions.loader) {
138
180
  return queue(async () => {
181
+ if (process_1.env['DEBUG'] != null) {
182
+ console.time(`@graphql-tools/load: collectCustomLoader ${pointer}`);
183
+ }
139
184
  await Promise.all((0, utils_1.asArray)(pointerOptions.require).map(m => Promise.resolve().then(() => __importStar(require(m)))));
140
185
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
141
186
  // @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
142
187
  const loader = await (0, custom_loader_js_1.useCustomLoader)(pointerOptions.loader, options.cwd);
143
188
  const result = await loader(pointer, { ...options, ...pointerOptions }, pointerOptionMap);
189
+ if (process_1.env['DEBUG'] != null) {
190
+ console.timeEnd(`@graphql-tools/load: collectCustomLoader ${pointer}`);
191
+ }
144
192
  if (!result) {
145
193
  return;
146
194
  }
@@ -152,6 +200,9 @@ function collectCustomLoader({ pointer, pointerOptions, queue, addSource, option
152
200
  function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
153
201
  if (pointerOptions.loader) {
154
202
  return queue(() => {
203
+ if (process_1.env['DEBUG'] != null) {
204
+ console.time(`@graphql-tools/load: collectCustomLoaderSync ${pointer}`);
205
+ }
155
206
  const cwdRequire = (0, module_1.createRequire)(options.cwd || (0, process_1.cwd)());
156
207
  for (const m of (0, utils_1.asArray)(pointerOptions.require)) {
157
208
  cwdRequire(m);
@@ -160,6 +211,9 @@ function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, op
160
211
  // @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
161
212
  const loader = (0, custom_loader_js_1.useCustomLoaderSync)(pointerOptions.loader, options.cwd);
162
213
  const result = loader(pointer, { ...options, ...pointerOptions }, pointerOptionMap);
214
+ if (process_1.env['DEBUG'] != null) {
215
+ console.timeEnd(`@graphql-tools/load: collectCustomLoaderSync ${pointer}`);
216
+ }
163
217
  if (result) {
164
218
  addResultOfCustomLoader({ pointer, result, addSource });
165
219
  }
@@ -169,6 +223,9 @@ function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, op
169
223
  }
170
224
  function collectFallback({ queue, pointer, options, pointerOptions, addSource }) {
171
225
  return queue(async () => {
226
+ if (process_1.env['DEBUG'] != null) {
227
+ console.time(`@graphql-tools/load: collectFallback ${pointer}`);
228
+ }
172
229
  const sources = await (0, load_file_js_1.loadFile)(pointer, {
173
230
  ...options,
174
231
  ...pointerOptions,
@@ -178,10 +235,16 @@ function collectFallback({ queue, pointer, options, pointerOptions, addSource })
178
235
  addSource({ source, pointer });
179
236
  }
180
237
  }
238
+ if (process_1.env['DEBUG'] != null) {
239
+ console.timeEnd(`@graphql-tools/load: collectFallback ${pointer}`);
240
+ }
181
241
  });
182
242
  }
183
243
  function collectFallbackSync({ queue, pointer, options, pointerOptions, addSource }) {
184
244
  return queue(() => {
245
+ if (process_1.env['DEBUG'] != null) {
246
+ console.time(`@graphql-tools/load: collectFallbackSync ${pointer}`);
247
+ }
185
248
  const sources = (0, load_file_js_1.loadFileSync)(pointer, {
186
249
  ...options,
187
250
  ...pointerOptions,
@@ -191,5 +254,8 @@ function collectFallbackSync({ queue, pointer, options, pointerOptions, addSourc
191
254
  addSource({ source, pointer });
192
255
  }
193
256
  }
257
+ if (process_1.env['DEBUG'] != null) {
258
+ console.timeEnd(`@graphql-tools/load: collectFallbackSync ${pointer}`);
259
+ }
194
260
  });
195
261
  }
@@ -5,6 +5,9 @@ const utils_1 = require("@graphql-tools/utils");
5
5
  const process_1 = require("process");
6
6
  async function loadFile(pointer, options) {
7
7
  var _a;
8
+ if (process_1.env['DEBUG'] != null) {
9
+ console.time(`@graphql-tools/load: loadFile ${pointer}`);
10
+ }
8
11
  let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
9
12
  if (!results) {
10
13
  results = [];
@@ -40,11 +43,17 @@ async function loadFile(pointer, options) {
40
43
  options.cache[pointer] = results;
41
44
  }
42
45
  }
46
+ if (process_1.env['DEBUG'] != null) {
47
+ console.timeEnd(`@graphql-tools/load: loadFile ${pointer}`);
48
+ }
43
49
  return results;
44
50
  }
45
51
  exports.loadFile = loadFile;
46
52
  function loadFileSync(pointer, options) {
47
53
  var _a;
54
+ if (process_1.env['DEBUG'] != null) {
55
+ console.time(`@graphql-tools/load: loadFileSync ${pointer}`);
56
+ }
48
57
  let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
49
58
  if (!results) {
50
59
  results = [];
@@ -81,6 +90,9 @@ function loadFileSync(pointer, options) {
81
90
  options.cache[pointer] = results;
82
91
  }
83
92
  }
93
+ if (process_1.env['DEBUG'] != null) {
94
+ console.timeEnd(`@graphql-tools/load: loadFileSync ${pointer}`);
95
+ }
84
96
  return results;
85
97
  }
86
98
  exports.loadFileSync = loadFileSync;
@@ -2,8 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSource = void 0;
4
4
  const utils_1 = require("@graphql-tools/utils");
5
+ const process_1 = require("process");
5
6
  const filter_document_kind_js_1 = require("../filter-document-kind.js");
6
7
  function parseSource({ partialSource, options, pointerOptionMap, addValidSource }) {
8
+ if (process_1.env['DEBUG'] != null) {
9
+ console.time(`@graphql-tools/load: parseSource ${partialSource.location}`);
10
+ }
7
11
  if (partialSource) {
8
12
  const input = prepareInput({
9
13
  source: partialSource,
@@ -18,6 +22,9 @@ function parseSource({ partialSource, options, pointerOptionMap, addValidSource
18
22
  collectValidSources(input, addValidSource);
19
23
  }
20
24
  }
25
+ if (process_1.env['DEBUG'] != null) {
26
+ console.timeEnd(`@graphql-tools/load: parseSource ${partialSource.location}`);
27
+ }
21
28
  }
22
29
  exports.parseSource = parseSource;
23
30
  //
@@ -34,29 +41,56 @@ function prepareInput({ source, options, pointerOptionMap, }) {
34
41
  return { source: { ...source }, options: specificOptions };
35
42
  }
36
43
  function parseSchema(input) {
44
+ if (process_1.env['DEBUG'] != null) {
45
+ console.time(`@graphql-tools/load: parseSchema ${input.source.location}`);
46
+ }
37
47
  if (input.source.schema) {
38
48
  input.source.rawSDL = (0, utils_1.printSchemaWithDirectives)(input.source.schema, input.options);
39
49
  }
50
+ if (process_1.env['DEBUG'] != null) {
51
+ console.timeEnd(`@graphql-tools/load: parseSchema ${input.source.location}`);
52
+ }
40
53
  }
41
54
  function parseRawSDL(input) {
55
+ if (process_1.env['DEBUG'] != null) {
56
+ console.time(`@graphql-tools/load: parseRawSDL ${input.source.location}`);
57
+ }
42
58
  if (input.source.rawSDL) {
43
59
  input.source.document = (0, utils_1.parseGraphQLSDL)(input.source.location, input.source.rawSDL, input.options).document;
44
60
  }
61
+ if (process_1.env['DEBUG'] != null) {
62
+ console.timeEnd(`@graphql-tools/load: parseRawSDL ${input.source.location}`);
63
+ }
45
64
  }
46
65
  function useKindsFilter(input) {
66
+ if (process_1.env['DEBUG'] != null) {
67
+ console.time(`@graphql-tools/load: useKindsFilter ${input.source.location}`);
68
+ }
47
69
  if (input.options.filterKinds) {
48
70
  input.source.document = (0, filter_document_kind_js_1.filterKind)(input.source.document, input.options.filterKinds);
49
71
  }
50
72
  }
51
73
  function useComments(input) {
74
+ if (process_1.env['DEBUG'] != null) {
75
+ console.time(`@graphql-tools/load: useComments ${input.source.location}`);
76
+ }
52
77
  if (!input.source.rawSDL && input.source.document) {
53
78
  input.source.rawSDL = (0, utils_1.printWithComments)(input.source.document);
54
79
  (0, utils_1.resetComments)();
55
80
  }
81
+ if (process_1.env['DEBUG'] != null) {
82
+ console.timeEnd(`@graphql-tools/load: useComments ${input.source.location}`);
83
+ }
56
84
  }
57
85
  function collectValidSources(input, addValidSource) {
58
86
  var _a;
87
+ if (process_1.env['DEBUG'] != null) {
88
+ console.time(`@graphql-tools/load: collectValidSources ${input.source.location}`);
89
+ }
59
90
  if (((_a = input.source.document) === null || _a === void 0 ? void 0 : _a.definitions) && input.source.document.definitions.length > 0) {
60
91
  addValidSource(input.source);
61
92
  }
93
+ if (process_1.env['DEBUG'] != null) {
94
+ console.timeEnd(`@graphql-tools/load: collectValidSources ${input.source.location}`);
95
+ }
62
96
  }
@@ -7,6 +7,7 @@ const options_js_1 = require("./load-typedefs/options.js");
7
7
  const collect_sources_js_1 = require("./load-typedefs/collect-sources.js");
8
8
  const parse_js_1 = require("./load-typedefs/parse.js");
9
9
  const helpers_js_1 = require("./utils/helpers.js");
10
+ const process_1 = require("process");
10
11
  const CONCURRENCY_LIMIT = 100;
11
12
  /**
12
13
  * Asynchronously loads any GraphQL documents (i.e. executable documents like
@@ -17,6 +18,9 @@ const CONCURRENCY_LIMIT = 100;
17
18
  * @param options Additional options
18
19
  */
19
20
  async function loadTypedefs(pointerOrPointers, options) {
21
+ if (process_1.env['DEBUG'] != null) {
22
+ console.time('@graphql-tools/load: loadTypedefs');
23
+ }
20
24
  const { ignore, pointerOptionMap } = (0, pointers_js_1.normalizePointers)(pointerOrPointers);
21
25
  options.ignore = (0, utils_1.asArray)(options.ignore || []);
22
26
  options.ignore.push(...ignore);
@@ -36,7 +40,11 @@ async function loadTypedefs(pointerOrPointers, options) {
36
40
  validSources.push(source);
37
41
  },
38
42
  }))));
39
- return prepareResult({ options, pointerOptionMap, validSources });
43
+ const result = prepareResult({ options, pointerOptionMap, validSources });
44
+ if (process_1.env['DEBUG'] != null) {
45
+ console.timeEnd('@graphql-tools/load: loadTypedefs');
46
+ }
47
+ return result;
40
48
  }
41
49
  exports.loadTypedefs = loadTypedefs;
42
50
  /**
@@ -47,6 +55,9 @@ exports.loadTypedefs = loadTypedefs;
47
55
  * @param options Additional options
48
56
  */
49
57
  function loadTypedefsSync(pointerOrPointers, options) {
58
+ if (process_1.env['DEBUG'] != null) {
59
+ console.time('@graphql-tools/load: loadTypedefsSync');
60
+ }
50
61
  const { ignore, pointerOptionMap } = (0, pointers_js_1.normalizePointers)(pointerOrPointers);
51
62
  options.ignore = (0, utils_1.asArray)(options.ignore || []).concat(ignore);
52
63
  (0, options_js_1.applyDefaultOptions)(options);
@@ -65,11 +76,18 @@ function loadTypedefsSync(pointerOrPointers, options) {
65
76
  },
66
77
  });
67
78
  }
68
- return prepareResult({ options, pointerOptionMap, validSources });
79
+ const result = prepareResult({ options, pointerOptionMap, validSources });
80
+ if (process_1.env['DEBUG'] != null) {
81
+ console.timeEnd('@graphql-tools/load: loadTypedefsSync');
82
+ }
83
+ return result;
69
84
  }
70
85
  exports.loadTypedefsSync = loadTypedefsSync;
71
86
  //
72
87
  function prepareResult({ options, pointerOptionMap, validSources, }) {
88
+ if (process_1.env['DEBUG'] != null) {
89
+ console.time('@graphql-tools/load: prepareResult');
90
+ }
73
91
  const pointerList = Object.keys(pointerOptionMap);
74
92
  if (pointerList.length > 0 && validSources.length === 0) {
75
93
  throw new Error(`
@@ -78,7 +96,11 @@ function prepareResult({ options, pointerOptionMap, validSources, }) {
78
96
  - ${p}
79
97
  `)}`);
80
98
  }
81
- return options.sort
99
+ const sortedResult = options.sort
82
100
  ? validSources.sort((left, right) => (0, utils_1.compareStrings)(left.location, right.location))
83
101
  : validSources;
102
+ if (process_1.env['DEBUG'] != null) {
103
+ console.timeEnd('@graphql-tools/load: prepareResult');
104
+ }
105
+ return sortedResult;
84
106
  }
@@ -2,7 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizePointers = void 0;
4
4
  const utils_1 = require("@graphql-tools/utils");
5
+ const process_1 = require("process");
5
6
  function normalizePointers(unnormalizedPointerOrPointers) {
7
+ if (process_1.env['DEBUG'] != null) {
8
+ console.time(`@graphql-tools/load: normalizePointers`);
9
+ }
6
10
  const ignore = [];
7
11
  const pointerOptionMap = {};
8
12
  const handlePointer = (rawPointer, options = {}) => {
@@ -14,6 +18,9 @@ function normalizePointers(unnormalizedPointerOrPointers) {
14
18
  }
15
19
  };
16
20
  for (const rawPointer of (0, utils_1.asArray)(unnormalizedPointerOrPointers)) {
21
+ if (process_1.env['DEBUG'] != null) {
22
+ console.time(`@graphql-tools/load: normalizePointers ${rawPointer}`);
23
+ }
17
24
  if (typeof rawPointer === 'string') {
18
25
  handlePointer(rawPointer);
19
26
  }
@@ -25,6 +32,12 @@ function normalizePointers(unnormalizedPointerOrPointers) {
25
32
  else {
26
33
  throw new Error(`Invalid pointer '${rawPointer}'.`);
27
34
  }
35
+ if (process_1.env['DEBUG'] != null) {
36
+ console.timeEnd(`@graphql-tools/load: normalizePointers ${rawPointer}`);
37
+ }
38
+ }
39
+ if (process_1.env['DEBUG'] != null) {
40
+ console.timeEnd(`@graphql-tools/load: normalizePointers`);
28
41
  }
29
42
  return { ignore, pointerOptionMap };
30
43
  }
@@ -5,9 +5,12 @@ import { stringToHash, useStack } from '../utils/helpers.js';
5
5
  import { useCustomLoader, useCustomLoaderSync } from '../utils/custom-loader.js';
6
6
  import { useQueue, useSyncQueue } from '../utils/queue.js';
7
7
  import { createRequire } from 'module';
8
- import { cwd } from 'process';
8
+ import { cwd, env } from 'process';
9
9
  const CONCURRENCY_LIMIT = 50;
10
10
  export async function collectSources({ pointerOptionMap, options, }) {
11
+ if (env['DEBUG'] != null) {
12
+ console.time('@graphql-tools/load: collectSources');
13
+ }
11
14
  const sources = [];
12
15
  const queue = useQueue({ concurrency: CONCURRENCY_LIMIT });
13
16
  const { addSource, collect } = createHelpers({
@@ -16,6 +19,9 @@ export async function collectSources({ pointerOptionMap, options, }) {
16
19
  });
17
20
  for (const pointer in pointerOptionMap) {
18
21
  const pointerOptions = pointerOptionMap[pointer];
22
+ if (env['DEBUG'] != null) {
23
+ console.time(`@graphql-tools/load: collectSources ${pointer}`);
24
+ }
19
25
  collect({
20
26
  pointer,
21
27
  pointerOptions,
@@ -24,8 +30,17 @@ export async function collectSources({ pointerOptionMap, options, }) {
24
30
  addSource,
25
31
  queue: queue.add,
26
32
  });
33
+ if (env['DEBUG'] != null) {
34
+ console.timeEnd(`@graphql-tools/load: collectSources ${pointer}`);
35
+ }
36
+ }
37
+ if (env['DEBUG'] != null) {
38
+ console.time('@graphql-tools/load: collectSources queue');
27
39
  }
28
40
  await queue.runAll();
41
+ if (env['DEBUG'] != null) {
42
+ console.timeEnd('@graphql-tools/load: collectSources queue');
43
+ }
29
44
  return sources;
30
45
  }
31
46
  export function collectSourcesSync({ pointerOptionMap, options, }) {
@@ -35,8 +50,14 @@ export function collectSourcesSync({ pointerOptionMap, options, }) {
35
50
  sources,
36
51
  stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
37
52
  });
53
+ if (env['DEBUG'] != null) {
54
+ console.time('@graphql-tools/load: collectSourcesSync');
55
+ }
38
56
  for (const pointer in pointerOptionMap) {
39
57
  const pointerOptions = pointerOptionMap[pointer];
58
+ if (env['DEBUG'] != null) {
59
+ console.time(`@graphql-tools/load: collectSourcesSync ${pointer}`);
60
+ }
40
61
  collect({
41
62
  pointer,
42
63
  pointerOptions,
@@ -45,8 +66,17 @@ export function collectSourcesSync({ pointerOptionMap, options, }) {
45
66
  addSource,
46
67
  queue: queue.add,
47
68
  });
69
+ if (env['DEBUG'] != null) {
70
+ console.timeEnd(`@graphql-tools/load: collectSourcesSync ${pointer}`);
71
+ }
72
+ }
73
+ if (env['DEBUG'] != null) {
74
+ console.time('@graphql-tools/load: collectSourcesSync queue');
48
75
  }
49
76
  queue.runAll();
77
+ if (env['DEBUG'] != null) {
78
+ console.timeEnd('@graphql-tools/load: collectSourcesSync queue');
79
+ }
50
80
  return sources;
51
81
  }
52
82
  function createHelpers({ sources, stack }) {
@@ -60,6 +90,9 @@ function createHelpers({ sources, stack }) {
60
90
  };
61
91
  }
62
92
  function addResultOfCustomLoader({ pointer, result, addSource, }) {
93
+ if (env['DEBUG'] != null) {
94
+ console.time(`@graphql-tools/load: addResultOfCustomLoader ${pointer}`);
95
+ }
63
96
  if (isSchema(result)) {
64
97
  addSource({
65
98
  source: {
@@ -89,8 +122,14 @@ function addResultOfCustomLoader({ pointer, result, addSource, }) {
89
122
  pointer,
90
123
  });
91
124
  }
125
+ if (env['DEBUG'] != null) {
126
+ console.timeEnd(`@graphql-tools/load: addResultOfCustomLoader ${pointer}`);
127
+ }
92
128
  }
93
129
  function collectDocumentString({ pointer, pointerOptions, options, addSource, queue }, next) {
130
+ if (env['DEBUG'] != null) {
131
+ console.time(`@graphql-tools/load: collectDocumentString ${pointer}`);
132
+ }
94
133
  if (isDocumentString(pointer)) {
95
134
  return queue(() => {
96
135
  const source = parseGraphQLSDL(`${stringToHash(pointer)}.graphql`, pointer, {
@@ -103,16 +142,25 @@ function collectDocumentString({ pointer, pointerOptions, options, addSource, qu
103
142
  });
104
143
  });
105
144
  }
145
+ if (env['DEBUG'] != null) {
146
+ console.timeEnd(`@graphql-tools/load: collectDocumentString ${pointer}`);
147
+ }
106
148
  next();
107
149
  }
108
150
  function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
109
151
  if (pointerOptions.loader) {
110
152
  return queue(async () => {
153
+ if (env['DEBUG'] != null) {
154
+ console.time(`@graphql-tools/load: collectCustomLoader ${pointer}`);
155
+ }
111
156
  await Promise.all(asArray(pointerOptions.require).map(m => import(m)));
112
157
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
113
158
  // @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
114
159
  const loader = await useCustomLoader(pointerOptions.loader, options.cwd);
115
160
  const result = await loader(pointer, { ...options, ...pointerOptions }, pointerOptionMap);
161
+ if (env['DEBUG'] != null) {
162
+ console.timeEnd(`@graphql-tools/load: collectCustomLoader ${pointer}`);
163
+ }
116
164
  if (!result) {
117
165
  return;
118
166
  }
@@ -124,6 +172,9 @@ function collectCustomLoader({ pointer, pointerOptions, queue, addSource, option
124
172
  function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
125
173
  if (pointerOptions.loader) {
126
174
  return queue(() => {
175
+ if (env['DEBUG'] != null) {
176
+ console.time(`@graphql-tools/load: collectCustomLoaderSync ${pointer}`);
177
+ }
127
178
  const cwdRequire = createRequire(options.cwd || cwd());
128
179
  for (const m of asArray(pointerOptions.require)) {
129
180
  cwdRequire(m);
@@ -132,6 +183,9 @@ function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, op
132
183
  // @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
133
184
  const loader = useCustomLoaderSync(pointerOptions.loader, options.cwd);
134
185
  const result = loader(pointer, { ...options, ...pointerOptions }, pointerOptionMap);
186
+ if (env['DEBUG'] != null) {
187
+ console.timeEnd(`@graphql-tools/load: collectCustomLoaderSync ${pointer}`);
188
+ }
135
189
  if (result) {
136
190
  addResultOfCustomLoader({ pointer, result, addSource });
137
191
  }
@@ -141,6 +195,9 @@ function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, op
141
195
  }
142
196
  function collectFallback({ queue, pointer, options, pointerOptions, addSource }) {
143
197
  return queue(async () => {
198
+ if (env['DEBUG'] != null) {
199
+ console.time(`@graphql-tools/load: collectFallback ${pointer}`);
200
+ }
144
201
  const sources = await loadFile(pointer, {
145
202
  ...options,
146
203
  ...pointerOptions,
@@ -150,10 +207,16 @@ function collectFallback({ queue, pointer, options, pointerOptions, addSource })
150
207
  addSource({ source, pointer });
151
208
  }
152
209
  }
210
+ if (env['DEBUG'] != null) {
211
+ console.timeEnd(`@graphql-tools/load: collectFallback ${pointer}`);
212
+ }
153
213
  });
154
214
  }
155
215
  function collectFallbackSync({ queue, pointer, options, pointerOptions, addSource }) {
156
216
  return queue(() => {
217
+ if (env['DEBUG'] != null) {
218
+ console.time(`@graphql-tools/load: collectFallbackSync ${pointer}`);
219
+ }
157
220
  const sources = loadFileSync(pointer, {
158
221
  ...options,
159
222
  ...pointerOptions,
@@ -163,5 +226,8 @@ function collectFallbackSync({ queue, pointer, options, pointerOptions, addSourc
163
226
  addSource({ source, pointer });
164
227
  }
165
228
  }
229
+ if (env['DEBUG'] != null) {
230
+ console.timeEnd(`@graphql-tools/load: collectFallbackSync ${pointer}`);
231
+ }
166
232
  });
167
233
  }
@@ -2,6 +2,9 @@ import { AggregateError } from '@graphql-tools/utils';
2
2
  import { env } from 'process';
3
3
  export async function loadFile(pointer, options) {
4
4
  var _a;
5
+ if (env['DEBUG'] != null) {
6
+ console.time(`@graphql-tools/load: loadFile ${pointer}`);
7
+ }
5
8
  let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
6
9
  if (!results) {
7
10
  results = [];
@@ -37,10 +40,16 @@ export async function loadFile(pointer, options) {
37
40
  options.cache[pointer] = results;
38
41
  }
39
42
  }
43
+ if (env['DEBUG'] != null) {
44
+ console.timeEnd(`@graphql-tools/load: loadFile ${pointer}`);
45
+ }
40
46
  return results;
41
47
  }
42
48
  export function loadFileSync(pointer, options) {
43
49
  var _a;
50
+ if (env['DEBUG'] != null) {
51
+ console.time(`@graphql-tools/load: loadFileSync ${pointer}`);
52
+ }
44
53
  let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
45
54
  if (!results) {
46
55
  results = [];
@@ -77,5 +86,8 @@ export function loadFileSync(pointer, options) {
77
86
  options.cache[pointer] = results;
78
87
  }
79
88
  }
89
+ if (env['DEBUG'] != null) {
90
+ console.timeEnd(`@graphql-tools/load: loadFileSync ${pointer}`);
91
+ }
80
92
  return results;
81
93
  }
@@ -1,6 +1,10 @@
1
1
  import { printSchemaWithDirectives, parseGraphQLSDL, printWithComments, resetComments, } from '@graphql-tools/utils';
2
+ import { env } from 'process';
2
3
  import { filterKind } from '../filter-document-kind.js';
3
4
  export function parseSource({ partialSource, options, pointerOptionMap, addValidSource }) {
5
+ if (env['DEBUG'] != null) {
6
+ console.time(`@graphql-tools/load: parseSource ${partialSource.location}`);
7
+ }
4
8
  if (partialSource) {
5
9
  const input = prepareInput({
6
10
  source: partialSource,
@@ -15,6 +19,9 @@ export function parseSource({ partialSource, options, pointerOptionMap, addValid
15
19
  collectValidSources(input, addValidSource);
16
20
  }
17
21
  }
22
+ if (env['DEBUG'] != null) {
23
+ console.timeEnd(`@graphql-tools/load: parseSource ${partialSource.location}`);
24
+ }
18
25
  }
19
26
  //
20
27
  function prepareInput({ source, options, pointerOptionMap, }) {
@@ -30,29 +37,56 @@ function prepareInput({ source, options, pointerOptionMap, }) {
30
37
  return { source: { ...source }, options: specificOptions };
31
38
  }
32
39
  function parseSchema(input) {
40
+ if (env['DEBUG'] != null) {
41
+ console.time(`@graphql-tools/load: parseSchema ${input.source.location}`);
42
+ }
33
43
  if (input.source.schema) {
34
44
  input.source.rawSDL = printSchemaWithDirectives(input.source.schema, input.options);
35
45
  }
46
+ if (env['DEBUG'] != null) {
47
+ console.timeEnd(`@graphql-tools/load: parseSchema ${input.source.location}`);
48
+ }
36
49
  }
37
50
  function parseRawSDL(input) {
51
+ if (env['DEBUG'] != null) {
52
+ console.time(`@graphql-tools/load: parseRawSDL ${input.source.location}`);
53
+ }
38
54
  if (input.source.rawSDL) {
39
55
  input.source.document = parseGraphQLSDL(input.source.location, input.source.rawSDL, input.options).document;
40
56
  }
57
+ if (env['DEBUG'] != null) {
58
+ console.timeEnd(`@graphql-tools/load: parseRawSDL ${input.source.location}`);
59
+ }
41
60
  }
42
61
  function useKindsFilter(input) {
62
+ if (env['DEBUG'] != null) {
63
+ console.time(`@graphql-tools/load: useKindsFilter ${input.source.location}`);
64
+ }
43
65
  if (input.options.filterKinds) {
44
66
  input.source.document = filterKind(input.source.document, input.options.filterKinds);
45
67
  }
46
68
  }
47
69
  function useComments(input) {
70
+ if (env['DEBUG'] != null) {
71
+ console.time(`@graphql-tools/load: useComments ${input.source.location}`);
72
+ }
48
73
  if (!input.source.rawSDL && input.source.document) {
49
74
  input.source.rawSDL = printWithComments(input.source.document);
50
75
  resetComments();
51
76
  }
77
+ if (env['DEBUG'] != null) {
78
+ console.timeEnd(`@graphql-tools/load: useComments ${input.source.location}`);
79
+ }
52
80
  }
53
81
  function collectValidSources(input, addValidSource) {
54
82
  var _a;
83
+ if (env['DEBUG'] != null) {
84
+ console.time(`@graphql-tools/load: collectValidSources ${input.source.location}`);
85
+ }
55
86
  if (((_a = input.source.document) === null || _a === void 0 ? void 0 : _a.definitions) && input.source.document.definitions.length > 0) {
56
87
  addValidSource(input.source);
57
88
  }
89
+ if (env['DEBUG'] != null) {
90
+ console.timeEnd(`@graphql-tools/load: collectValidSources ${input.source.location}`);
91
+ }
58
92
  }
@@ -4,6 +4,7 @@ import { applyDefaultOptions } from './load-typedefs/options.js';
4
4
  import { collectSources, collectSourcesSync } from './load-typedefs/collect-sources.js';
5
5
  import { parseSource } from './load-typedefs/parse.js';
6
6
  import { useLimit } from './utils/helpers.js';
7
+ import { env } from 'process';
7
8
  const CONCURRENCY_LIMIT = 100;
8
9
  /**
9
10
  * Asynchronously loads any GraphQL documents (i.e. executable documents like
@@ -14,6 +15,9 @@ const CONCURRENCY_LIMIT = 100;
14
15
  * @param options Additional options
15
16
  */
16
17
  export async function loadTypedefs(pointerOrPointers, options) {
18
+ if (env['DEBUG'] != null) {
19
+ console.time('@graphql-tools/load: loadTypedefs');
20
+ }
17
21
  const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);
18
22
  options.ignore = asArray(options.ignore || []);
19
23
  options.ignore.push(...ignore);
@@ -33,7 +37,11 @@ export async function loadTypedefs(pointerOrPointers, options) {
33
37
  validSources.push(source);
34
38
  },
35
39
  }))));
36
- return prepareResult({ options, pointerOptionMap, validSources });
40
+ const result = prepareResult({ options, pointerOptionMap, validSources });
41
+ if (env['DEBUG'] != null) {
42
+ console.timeEnd('@graphql-tools/load: loadTypedefs');
43
+ }
44
+ return result;
37
45
  }
38
46
  /**
39
47
  * Synchronously loads any GraphQL documents (i.e. executable documents like
@@ -43,6 +51,9 @@ export async function loadTypedefs(pointerOrPointers, options) {
43
51
  * @param options Additional options
44
52
  */
45
53
  export function loadTypedefsSync(pointerOrPointers, options) {
54
+ if (env['DEBUG'] != null) {
55
+ console.time('@graphql-tools/load: loadTypedefsSync');
56
+ }
46
57
  const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);
47
58
  options.ignore = asArray(options.ignore || []).concat(ignore);
48
59
  applyDefaultOptions(options);
@@ -61,10 +72,17 @@ export function loadTypedefsSync(pointerOrPointers, options) {
61
72
  },
62
73
  });
63
74
  }
64
- return prepareResult({ options, pointerOptionMap, validSources });
75
+ const result = prepareResult({ options, pointerOptionMap, validSources });
76
+ if (env['DEBUG'] != null) {
77
+ console.timeEnd('@graphql-tools/load: loadTypedefsSync');
78
+ }
79
+ return result;
65
80
  }
66
81
  //
67
82
  function prepareResult({ options, pointerOptionMap, validSources, }) {
83
+ if (env['DEBUG'] != null) {
84
+ console.time('@graphql-tools/load: prepareResult');
85
+ }
68
86
  const pointerList = Object.keys(pointerOptionMap);
69
87
  if (pointerList.length > 0 && validSources.length === 0) {
70
88
  throw new Error(`
@@ -73,7 +91,11 @@ function prepareResult({ options, pointerOptionMap, validSources, }) {
73
91
  - ${p}
74
92
  `)}`);
75
93
  }
76
- return options.sort
94
+ const sortedResult = options.sort
77
95
  ? validSources.sort((left, right) => compareStrings(left.location, right.location))
78
96
  : validSources;
97
+ if (env['DEBUG'] != null) {
98
+ console.timeEnd('@graphql-tools/load: prepareResult');
99
+ }
100
+ return sortedResult;
79
101
  }
@@ -1,5 +1,9 @@
1
1
  import { asArray } from '@graphql-tools/utils';
2
+ import { env } from 'process';
2
3
  export function normalizePointers(unnormalizedPointerOrPointers) {
4
+ if (env['DEBUG'] != null) {
5
+ console.time(`@graphql-tools/load: normalizePointers`);
6
+ }
3
7
  const ignore = [];
4
8
  const pointerOptionMap = {};
5
9
  const handlePointer = (rawPointer, options = {}) => {
@@ -11,6 +15,9 @@ export function normalizePointers(unnormalizedPointerOrPointers) {
11
15
  }
12
16
  };
13
17
  for (const rawPointer of asArray(unnormalizedPointerOrPointers)) {
18
+ if (env['DEBUG'] != null) {
19
+ console.time(`@graphql-tools/load: normalizePointers ${rawPointer}`);
20
+ }
14
21
  if (typeof rawPointer === 'string') {
15
22
  handlePointer(rawPointer);
16
23
  }
@@ -22,6 +29,12 @@ export function normalizePointers(unnormalizedPointerOrPointers) {
22
29
  else {
23
30
  throw new Error(`Invalid pointer '${rawPointer}'.`);
24
31
  }
32
+ if (env['DEBUG'] != null) {
33
+ console.timeEnd(`@graphql-tools/load: normalizePointers ${rawPointer}`);
34
+ }
35
+ }
36
+ if (env['DEBUG'] != null) {
37
+ console.timeEnd(`@graphql-tools/load: normalizePointers`);
25
38
  }
26
39
  return { ignore, pointerOptionMap };
27
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/load",
3
- "version": "7.7.7",
3
+ "version": "7.8.0-alpha-20221018160054-b827d116",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {