@graphql-tools/load 7.5.0-alpha-06eec860.0 → 7.5.1
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 +19 -13
- package/index.mjs +20 -14
- 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) {
|
|
@@ -57,7 +60,7 @@ function normalizePointers(unnormalizedPointerOrPointers) {
|
|
|
57
60
|
|
|
58
61
|
function applyDefaultOptions(options) {
|
|
59
62
|
options.cache = options.cache || {};
|
|
60
|
-
options.cwd = options.cwd ||
|
|
63
|
+
options.cwd = options.cwd || process.cwd();
|
|
61
64
|
options.sort = 'sort' in options ? options.sort : true;
|
|
62
65
|
}
|
|
63
66
|
|
|
@@ -73,7 +76,7 @@ async function loadFile(pointer, options) {
|
|
|
73
76
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
74
77
|
}
|
|
75
78
|
catch (error) {
|
|
76
|
-
if (process
|
|
79
|
+
if (process.env['DEBUG']) {
|
|
77
80
|
console.error(error);
|
|
78
81
|
}
|
|
79
82
|
if (error instanceof utils.AggregateError) {
|
|
@@ -113,7 +116,7 @@ function loadFileSync(pointer, options) {
|
|
|
113
116
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
114
117
|
}
|
|
115
118
|
catch (error) {
|
|
116
|
-
if (process
|
|
119
|
+
if (process.env['DEBUG']) {
|
|
117
120
|
console.error(error);
|
|
118
121
|
}
|
|
119
122
|
if (error instanceof utils.AggregateError) {
|
|
@@ -176,23 +179,20 @@ function useLimit(concurrency) {
|
|
|
176
179
|
return pLimit(concurrency);
|
|
177
180
|
}
|
|
178
181
|
|
|
179
|
-
|
|
182
|
+
function getCustomLoaderByPath(path$1, cwd) {
|
|
180
183
|
try {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const requiredModule = await new Promise(function (resolve) { resolve(_interopNamespace(require(absoluteFilePath))); });
|
|
184
|
+
const requireFn = module$1.createRequire(path.join(cwd, 'noop.js'));
|
|
185
|
+
const requiredModule = requireFn(path$1);
|
|
184
186
|
if (requiredModule) {
|
|
185
|
-
if (requiredModule
|
|
186
|
-
return requiredModule
|
|
187
|
+
if (requiredModule.default && typeof requiredModule.default === 'function') {
|
|
188
|
+
return requiredModule.default;
|
|
187
189
|
}
|
|
188
190
|
if (typeof requiredModule === 'function') {
|
|
189
191
|
return requiredModule;
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
|
-
catch (e) {
|
|
194
|
-
console.log(e);
|
|
195
|
-
}
|
|
195
|
+
catch (e) { }
|
|
196
196
|
return null;
|
|
197
197
|
}
|
|
198
198
|
async function useCustomLoader(loaderPointer, cwd) {
|
|
@@ -350,6 +350,7 @@ function collectDocumentString({ pointer, pointerOptions, options, addSource, qu
|
|
|
350
350
|
function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
351
351
|
if (pointerOptions.loader) {
|
|
352
352
|
return queue(async () => {
|
|
353
|
+
await Promise.all(utils.asArray(pointerOptions.require).map(m => new Promise(function (resolve) { resolve(_interopNamespace(require(m))); })));
|
|
353
354
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
354
355
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
355
356
|
const loader = await useCustomLoader(pointerOptions.loader, options.cwd);
|
|
@@ -365,6 +366,10 @@ function collectCustomLoader({ pointer, pointerOptions, queue, addSource, option
|
|
|
365
366
|
function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
366
367
|
if (pointerOptions.loader) {
|
|
367
368
|
return queue(() => {
|
|
369
|
+
const cwdRequire = module$1.createRequire(options.cwd || process.cwd());
|
|
370
|
+
for (const m of utils.asArray(pointerOptions.require)) {
|
|
371
|
+
cwdRequire(m);
|
|
372
|
+
}
|
|
368
373
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
369
374
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
370
375
|
const loader = useCustomLoaderSync(pointerOptions.loader, options.cwd);
|
|
@@ -419,7 +424,7 @@ const filterKind = (content, filterKinds) => {
|
|
|
419
424
|
}
|
|
420
425
|
}
|
|
421
426
|
if (invalidDefinitions.length > 0) {
|
|
422
|
-
if (process
|
|
427
|
+
if (process.env['DEBUG']) {
|
|
423
428
|
for (const d of invalidDefinitions) {
|
|
424
429
|
console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
|
|
425
430
|
}
|
|
@@ -495,6 +500,7 @@ const CONCURRENCY_LIMIT$1 = 100;
|
|
|
495
500
|
* Asynchronously loads any GraphQL documents (i.e. executable documents like
|
|
496
501
|
* operations and fragments as well as type system definitions) from the
|
|
497
502
|
* provided pointers.
|
|
503
|
+
* loadTypedefs does not merge the typeDefs when `#import` is used ( https://github.com/ardatan/graphql-tools/issues/2980#issuecomment-1003692728 )
|
|
498
504
|
* @param pointerOrPointers Pointers to the sources to load the documents from
|
|
499
505
|
* @param options Additional options
|
|
500
506
|
*/
|
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) {
|
|
@@ -32,7 +35,7 @@ function normalizePointers(unnormalizedPointerOrPointers) {
|
|
|
32
35
|
|
|
33
36
|
function applyDefaultOptions(options) {
|
|
34
37
|
options.cache = options.cache || {};
|
|
35
|
-
options.cwd = options.cwd ||
|
|
38
|
+
options.cwd = options.cwd || cwd();
|
|
36
39
|
options.sort = 'sort' in options ? options.sort : true;
|
|
37
40
|
}
|
|
38
41
|
|
|
@@ -48,7 +51,7 @@ async function loadFile(pointer, options) {
|
|
|
48
51
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
49
52
|
}
|
|
50
53
|
catch (error) {
|
|
51
|
-
if (
|
|
54
|
+
if (env['DEBUG']) {
|
|
52
55
|
console.error(error);
|
|
53
56
|
}
|
|
54
57
|
if (error instanceof AggregateError) {
|
|
@@ -88,7 +91,7 @@ function loadFileSync(pointer, options) {
|
|
|
88
91
|
loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
|
|
89
92
|
}
|
|
90
93
|
catch (error) {
|
|
91
|
-
if (
|
|
94
|
+
if (env['DEBUG']) {
|
|
92
95
|
console.error(error);
|
|
93
96
|
}
|
|
94
97
|
if (error instanceof AggregateError) {
|
|
@@ -151,23 +154,20 @@ function useLimit(concurrency) {
|
|
|
151
154
|
return pLimit(concurrency);
|
|
152
155
|
}
|
|
153
156
|
|
|
154
|
-
|
|
157
|
+
function getCustomLoaderByPath(path, cwd) {
|
|
155
158
|
try {
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const requiredModule = await import(absoluteFilePath);
|
|
159
|
+
const requireFn = createRequire(join(cwd, 'noop.js'));
|
|
160
|
+
const requiredModule = requireFn(path);
|
|
159
161
|
if (requiredModule) {
|
|
160
|
-
if (requiredModule
|
|
161
|
-
return requiredModule
|
|
162
|
+
if (requiredModule.default && typeof requiredModule.default === 'function') {
|
|
163
|
+
return requiredModule.default;
|
|
162
164
|
}
|
|
163
165
|
if (typeof requiredModule === 'function') {
|
|
164
166
|
return requiredModule;
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
console.log(e);
|
|
170
|
-
}
|
|
170
|
+
catch (e) { }
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
async function useCustomLoader(loaderPointer, cwd) {
|
|
@@ -325,6 +325,7 @@ function collectDocumentString({ pointer, pointerOptions, options, addSource, qu
|
|
|
325
325
|
function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
326
326
|
if (pointerOptions.loader) {
|
|
327
327
|
return queue(async () => {
|
|
328
|
+
await Promise.all(asArray(pointerOptions.require).map(m => import(m)));
|
|
328
329
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
329
330
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
330
331
|
const loader = await useCustomLoader(pointerOptions.loader, options.cwd);
|
|
@@ -340,6 +341,10 @@ function collectCustomLoader({ pointer, pointerOptions, queue, addSource, option
|
|
|
340
341
|
function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
|
|
341
342
|
if (pointerOptions.loader) {
|
|
342
343
|
return queue(() => {
|
|
344
|
+
const cwdRequire = createRequire(options.cwd || cwd());
|
|
345
|
+
for (const m of asArray(pointerOptions.require)) {
|
|
346
|
+
cwdRequire(m);
|
|
347
|
+
}
|
|
343
348
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
344
349
|
// @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
|
|
345
350
|
const loader = useCustomLoaderSync(pointerOptions.loader, options.cwd);
|
|
@@ -394,7 +399,7 @@ const filterKind = (content, filterKinds) => {
|
|
|
394
399
|
}
|
|
395
400
|
}
|
|
396
401
|
if (invalidDefinitions.length > 0) {
|
|
397
|
-
if (
|
|
402
|
+
if (env['DEBUG']) {
|
|
398
403
|
for (const d of invalidDefinitions) {
|
|
399
404
|
console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
|
|
400
405
|
}
|
|
@@ -470,6 +475,7 @@ const CONCURRENCY_LIMIT$1 = 100;
|
|
|
470
475
|
* Asynchronously loads any GraphQL documents (i.e. executable documents like
|
|
471
476
|
* operations and fragments as well as type system definitions) from the
|
|
472
477
|
* provided pointers.
|
|
478
|
+
* loadTypedefs does not merge the typeDefs when `#import` is used ( https://github.com/ardatan/graphql-tools/issues/2980#issuecomment-1003692728 )
|
|
473
479
|
* @param pointerOrPointers Pointers to the sources to load the documents from
|
|
474
480
|
* @param options Additional options
|
|
475
481
|
*/
|
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",
|
|
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.6.0
|
|
10
|
+
"@graphql-tools/schema": "8.3.1",
|
|
11
|
+
"@graphql-tools/utils": "^8.6.0",
|
|
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