@graphql-tools/load 7.5.0-alpha-c3063363.0 → 7.5.1-alpha-b9b6301d.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/documents.d.ts +1 -1
- package/index.js +26 -15
- package/index.mjs +27 -16
- package/load-typedefs.d.ts +1 -0
- package/package.json +5 -4
- package/utils/custom-loader.d.ts +1 -2
- package/utils/queue.d.ts +1 -1
package/documents.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const OPERATION_KINDS: KindList;
|
|
|
9
9
|
/**
|
|
10
10
|
* Kinds of AST nodes that are included in type system definition documents
|
|
11
11
|
*/
|
|
12
|
-
export declare const NON_OPERATION_KINDS:
|
|
12
|
+
export declare const NON_OPERATION_KINDS: KindList;
|
|
13
13
|
/**
|
|
14
14
|
* Asynchronously loads executable documents (i.e. operations and fragments) from
|
|
15
15
|
* the provided pointers. The pointers may be individual files or a glob pattern.
|
package/index.js
CHANGED
|
@@ -24,8 +24,11 @@ function _interopNamespace(e) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const utils = require('@graphql-tools/utils');
|
|
27
|
+
const process = require('process');
|
|
27
28
|
const graphql = require('graphql');
|
|
28
29
|
const pLimit = _interopDefault(require('p-limit'));
|
|
30
|
+
const module$1 = require('module');
|
|
31
|
+
const path = require('path');
|
|
29
32
|
const schema = require('@graphql-tools/schema');
|
|
30
33
|
|
|
31
34
|
function normalizePointers(unnormalizedPointerOrPointers) {
|
|
@@ -44,8 +47,13 @@ function normalizePointers(unnormalizedPointerOrPointers) {
|
|
|
44
47
|
handlePointer(rawPointer);
|
|
45
48
|
}
|
|
46
49
|
else if (typeof rawPointer === 'object') {
|
|
47
|
-
|
|
48
|
-
handlePointer(
|
|
50
|
+
if ('require' in rawPointer && 'config' in rawPointer) {
|
|
51
|
+
handlePointer(rawPointer['require'], rawPointer['config']);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
for (const [path, options] of Object.entries(rawPointer)) {
|
|
55
|
+
handlePointer(path, options);
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
else {
|
|
@@ -57,7 +65,7 @@ function normalizePointers(unnormalizedPointerOrPointers) {
|
|
|
57
65
|
|
|
58
66
|
function applyDefaultOptions(options) {
|
|
59
67
|
options.cache = options.cache || {};
|
|
60
|
-
options.cwd = options.cwd ||
|
|
68
|
+
options.cwd = options.cwd || process.cwd();
|
|
61
69
|
options.sort = 'sort' in options ? options.sort : true;
|
|
62
70
|
}
|
|
63
71
|
|
|
@@ -73,7 +81,7 @@ async function loadFile(pointer, options) {
|
|
|
73
81
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
74
82
|
}
|
|
75
83
|
catch (error) {
|
|
76
|
-
if (process
|
|
84
|
+
if (process.env['DEBUG']) {
|
|
77
85
|
console.error(error);
|
|
78
86
|
}
|
|
79
87
|
if (error instanceof utils.AggregateError) {
|
|
@@ -113,7 +121,7 @@ function loadFileSync(pointer, options) {
|
|
|
113
121
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
114
122
|
}
|
|
115
123
|
catch (error) {
|
|
116
|
-
if (process
|
|
124
|
+
if (process.env['DEBUG']) {
|
|
117
125
|
console.error(error);
|
|
118
126
|
}
|
|
119
127
|
if (error instanceof utils.AggregateError) {
|
|
@@ -176,23 +184,20 @@ function useLimit(concurrency) {
|
|
|
176
184
|
return pLimit(concurrency);
|
|
177
185
|
}
|
|
178
186
|
|
|
179
|
-
|
|
187
|
+
function getCustomLoaderByPath(path$1, cwd) {
|
|
180
188
|
try {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const requiredModule = await new Promise(function (resolve) { resolve(_interopNamespace(require(absoluteFilePath))); });
|
|
189
|
+
const requireFn = module$1.createRequire(path.join(cwd, 'noop.js'));
|
|
190
|
+
const requiredModule = requireFn(path$1);
|
|
184
191
|
if (requiredModule) {
|
|
185
|
-
if (requiredModule
|
|
186
|
-
return requiredModule
|
|
192
|
+
if (requiredModule.default && typeof requiredModule.default === 'function') {
|
|
193
|
+
return requiredModule.default;
|
|
187
194
|
}
|
|
188
195
|
if (typeof requiredModule === 'function') {
|
|
189
196
|
return requiredModule;
|
|
190
197
|
}
|
|
191
198
|
}
|
|
192
199
|
}
|
|
193
|
-
catch (e) {
|
|
194
|
-
console.log(e);
|
|
195
|
-
}
|
|
200
|
+
catch (e) { }
|
|
196
201
|
return null;
|
|
197
202
|
}
|
|
198
203
|
async function useCustomLoader(loaderPointer, cwd) {
|
|
@@ -350,6 +355,7 @@ function collectDocumentString({ pointer, pointerOptions, options, addSource, qu
|
|
|
350
355
|
function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
351
356
|
if (pointerOptions.loader) {
|
|
352
357
|
return queue(async () => {
|
|
358
|
+
await Promise.all(utils.asArray(pointerOptions.require).map(m => new Promise(function (resolve) { resolve(_interopNamespace(require(m))); })));
|
|
353
359
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
354
360
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
355
361
|
const loader = await useCustomLoader(pointerOptions.loader, options.cwd);
|
|
@@ -365,6 +371,10 @@ function collectCustomLoader({ pointer, pointerOptions, queue, addSource, option
|
|
|
365
371
|
function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
366
372
|
if (pointerOptions.loader) {
|
|
367
373
|
return queue(() => {
|
|
374
|
+
const cwdRequire = module$1.createRequire(options.cwd || process.cwd());
|
|
375
|
+
for (const m of utils.asArray(pointerOptions.require)) {
|
|
376
|
+
cwdRequire(m);
|
|
377
|
+
}
|
|
368
378
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
369
379
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
370
380
|
const loader = useCustomLoaderSync(pointerOptions.loader, options.cwd);
|
|
@@ -419,7 +429,7 @@ const filterKind = (content, filterKinds) => {
|
|
|
419
429
|
}
|
|
420
430
|
}
|
|
421
431
|
if (invalidDefinitions.length > 0) {
|
|
422
|
-
if (process
|
|
432
|
+
if (process.env['DEBUG']) {
|
|
423
433
|
for (const d of invalidDefinitions) {
|
|
424
434
|
console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
|
|
425
435
|
}
|
|
@@ -495,6 +505,7 @@ const CONCURRENCY_LIMIT$1 = 100;
|
|
|
495
505
|
* Asynchronously loads any GraphQL documents (i.e. executable documents like
|
|
496
506
|
* operations and fragments as well as type system definitions) from the
|
|
497
507
|
* provided pointers.
|
|
508
|
+
* loadTypedefs does not merge the typeDefs when `#import` is used ( https://github.com/ardatan/graphql-tools/issues/2980#issuecomment-1003692728 )
|
|
498
509
|
* @param pointerOrPointers Pointers to the sources to load the documents from
|
|
499
510
|
* @param options Additional options
|
|
500
511
|
*/
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { asArray, AggregateError,
|
|
1
|
+
import { asArray, AggregateError, isDocumentString, parseGraphQLSDL, getDocumentNodeFromSchema, printSchemaWithDirectives, printWithComments, resetComments, compareStrings } from '@graphql-tools/utils';
|
|
2
|
+
import { cwd, env } from 'process';
|
|
2
3
|
import { isSchema, Kind, lexicographicSortSchema, Source, print } from 'graphql';
|
|
3
4
|
import pLimit from 'p-limit';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
import { join } from 'path';
|
|
4
7
|
import { mergeSchemas } from '@graphql-tools/schema';
|
|
5
8
|
|
|
6
9
|
function normalizePointers(unnormalizedPointerOrPointers) {
|
|
@@ -19,8 +22,13 @@ function normalizePointers(unnormalizedPointerOrPointers) {
|
|
|
19
22
|
handlePointer(rawPointer);
|
|
20
23
|
}
|
|
21
24
|
else if (typeof rawPointer === 'object') {
|
|
22
|
-
|
|
23
|
-
handlePointer(
|
|
25
|
+
if ('require' in rawPointer && 'config' in rawPointer) {
|
|
26
|
+
handlePointer(rawPointer['require'], rawPointer['config']);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
for (const [path, options] of Object.entries(rawPointer)) {
|
|
30
|
+
handlePointer(path, options);
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
else {
|
|
@@ -32,7 +40,7 @@ function normalizePointers(unnormalizedPointerOrPointers) {
|
|
|
32
40
|
|
|
33
41
|
function applyDefaultOptions(options) {
|
|
34
42
|
options.cache = options.cache || {};
|
|
35
|
-
options.cwd = options.cwd ||
|
|
43
|
+
options.cwd = options.cwd || cwd();
|
|
36
44
|
options.sort = 'sort' in options ? options.sort : true;
|
|
37
45
|
}
|
|
38
46
|
|
|
@@ -48,7 +56,7 @@ async function loadFile(pointer, options) {
|
|
|
48
56
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
49
57
|
}
|
|
50
58
|
catch (error) {
|
|
51
|
-
if (
|
|
59
|
+
if (env['DEBUG']) {
|
|
52
60
|
console.error(error);
|
|
53
61
|
}
|
|
54
62
|
if (error instanceof AggregateError) {
|
|
@@ -88,7 +96,7 @@ function loadFileSync(pointer, options) {
|
|
|
88
96
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
89
97
|
}
|
|
90
98
|
catch (error) {
|
|
91
|
-
if (
|
|
99
|
+
if (env['DEBUG']) {
|
|
92
100
|
console.error(error);
|
|
93
101
|
}
|
|
94
102
|
if (error instanceof AggregateError) {
|
|
@@ -151,23 +159,20 @@ function useLimit(concurrency) {
|
|
|
151
159
|
return pLimit(concurrency);
|
|
152
160
|
}
|
|
153
161
|
|
|
154
|
-
|
|
162
|
+
function getCustomLoaderByPath(path, cwd) {
|
|
155
163
|
try {
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const requiredModule = await import(absoluteFilePath);
|
|
164
|
+
const requireFn = createRequire(join(cwd, 'noop.js'));
|
|
165
|
+
const requiredModule = requireFn(path);
|
|
159
166
|
if (requiredModule) {
|
|
160
|
-
if (requiredModule
|
|
161
|
-
return requiredModule
|
|
167
|
+
if (requiredModule.default && typeof requiredModule.default === 'function') {
|
|
168
|
+
return requiredModule.default;
|
|
162
169
|
}
|
|
163
170
|
if (typeof requiredModule === 'function') {
|
|
164
171
|
return requiredModule;
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
console.log(e);
|
|
170
|
-
}
|
|
175
|
+
catch (e) { }
|
|
171
176
|
return null;
|
|
172
177
|
}
|
|
173
178
|
async function useCustomLoader(loaderPointer, cwd) {
|
|
@@ -325,6 +330,7 @@ function collectDocumentString({ pointer, pointerOptions, options, addSource, qu
|
|
|
325
330
|
function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
326
331
|
if (pointerOptions.loader) {
|
|
327
332
|
return queue(async () => {
|
|
333
|
+
await Promise.all(asArray(pointerOptions.require).map(m => import(m)));
|
|
328
334
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
329
335
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
330
336
|
const loader = await useCustomLoader(pointerOptions.loader, options.cwd);
|
|
@@ -340,6 +346,10 @@ function collectCustomLoader({ pointer, pointerOptions, queue, addSource, option
|
|
|
340
346
|
function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
341
347
|
if (pointerOptions.loader) {
|
|
342
348
|
return queue(() => {
|
|
349
|
+
const cwdRequire = createRequire(options.cwd || cwd());
|
|
350
|
+
for (const m of asArray(pointerOptions.require)) {
|
|
351
|
+
cwdRequire(m);
|
|
352
|
+
}
|
|
343
353
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
344
354
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
345
355
|
const loader = useCustomLoaderSync(pointerOptions.loader, options.cwd);
|
|
@@ -394,7 +404,7 @@ const filterKind = (content, filterKinds) => {
|
|
|
394
404
|
}
|
|
395
405
|
}
|
|
396
406
|
if (invalidDefinitions.length > 0) {
|
|
397
|
-
if (
|
|
407
|
+
if (env['DEBUG']) {
|
|
398
408
|
for (const d of invalidDefinitions) {
|
|
399
409
|
console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
|
|
400
410
|
}
|
|
@@ -470,6 +480,7 @@ const CONCURRENCY_LIMIT$1 = 100;
|
|
|
470
480
|
* Asynchronously loads any GraphQL documents (i.e. executable documents like
|
|
471
481
|
* operations and fragments as well as type system definitions) from the
|
|
472
482
|
* provided pointers.
|
|
483
|
+
* loadTypedefs does not merge the typeDefs when `#import` is used ( https://github.com/ardatan/graphql-tools/issues/2980#issuecomment-1003692728 )
|
|
473
484
|
* @param pointerOrPointers Pointers to the sources to load the documents from
|
|
474
485
|
* @param options Additional options
|
|
475
486
|
*/
|
package/load-typedefs.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare type UnnormalizedTypeDefPointer = {
|
|
|
16
16
|
* Asynchronously loads any GraphQL documents (i.e. executable documents like
|
|
17
17
|
* operations and fragments as well as type system definitions) from the
|
|
18
18
|
* provided pointers.
|
|
19
|
+
* loadTypedefs does not merge the typeDefs when `#import` is used ( https://github.com/ardatan/graphql-tools/issues/2980#issuecomment-1003692728 )
|
|
19
20
|
* @param pointerOrPointers Pointers to the sources to load the documents from
|
|
20
21
|
* @param options Additional options
|
|
21
22
|
*/
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/load",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.1-alpha-b9b6301d.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
|
|
11
|
-
"@graphql-tools/utils": "8.
|
|
10
|
+
"@graphql-tools/schema": "8.3.1",
|
|
11
|
+
"@graphql-tools/utils": "^8.5.5",
|
|
12
12
|
"p-limit": "3.1.0",
|
|
13
13
|
"tslib": "~2.3.0"
|
|
14
14
|
},
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"./*": {
|
|
34
34
|
"require": "./*.js",
|
|
35
35
|
"import": "./*.mjs"
|
|
36
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/utils/custom-loader.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function getCustomLoaderByPath(
|
|
2
|
-
export declare function getCustomLoaderByPathSync(pathExpression: string, cwd: string): any;
|
|
1
|
+
export declare function getCustomLoaderByPath(path: string, cwd: string): any;
|
|
3
2
|
export declare function useCustomLoader(loaderPointer: any, cwd: string): Promise<any>;
|
|
4
3
|
export declare function useCustomLoaderSync(loaderPointer: any, cwd: string): any;
|
package/utils/queue.d.ts
CHANGED