@graphql-tools/load 7.6.0 → 7.7.0-alpha-b76ec274.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/cjs/documents.js +39 -0
- package/cjs/filter-document-kind.js +35 -0
- package/cjs/index.js +7 -0
- package/cjs/load-typedefs/collect-sources.js +195 -0
- package/cjs/load-typedefs/load-file.js +86 -0
- package/cjs/load-typedefs/options.js +10 -0
- package/cjs/load-typedefs/parse.js +62 -0
- package/cjs/load-typedefs.js +84 -0
- package/cjs/package.json +1 -0
- package/cjs/schema.js +86 -0
- package/cjs/utils/custom-loader.js +50 -0
- package/cjs/utils/helpers.js +42 -0
- package/cjs/utils/pointers.js +31 -0
- package/cjs/utils/queue.js +32 -0
- package/esm/documents.js +34 -0
- package/esm/filter-document-kind.js +31 -0
- package/esm/index.js +4 -0
- package/esm/load-typedefs/collect-sources.js +167 -0
- package/esm/load-typedefs/load-file.js +81 -0
- package/esm/load-typedefs/options.js +6 -0
- package/esm/load-typedefs/parse.js +58 -0
- package/esm/load-typedefs.js +79 -0
- package/esm/schema.js +81 -0
- package/esm/utils/custom-loader.js +44 -0
- package/esm/utils/helpers.js +35 -0
- package/esm/utils/pointers.js +27 -0
- package/esm/utils/queue.js +26 -0
- package/package.json +33 -12
- package/{documents.d.ts → typings/documents.d.ts} +1 -1
- package/{filter-document-kind.d.ts → typings/filter-document-kind.d.ts} +0 -0
- package/typings/index.d.ts +4 -0
- package/{load-typedefs → typings/load-typedefs}/collect-sources.d.ts +1 -1
- package/{load-typedefs → typings/load-typedefs}/load-file.d.ts +1 -1
- package/{load-typedefs → typings/load-typedefs}/options.d.ts +1 -1
- package/{load-typedefs → typings/load-typedefs}/parse.d.ts +0 -0
- package/{load-typedefs.d.ts → typings/load-typedefs.d.ts} +0 -0
- package/{schema.d.ts → typings/schema.d.ts} +1 -1
- package/{utils → typings/utils}/custom-loader.d.ts +0 -0
- package/{utils → typings/utils}/helpers.d.ts +0 -0
- package/{utils → typings/utils}/pointers.d.ts +1 -1
- package/{utils → typings/utils}/queue.d.ts +0 -0
- package/README.md +0 -8
- package/index.d.ts +0 -4
- package/index.js +0 -691
- package/index.mjs +0 -658
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { join as joinPaths } from 'path';
|
|
3
|
+
export function getCustomLoaderByPath(path, cwd) {
|
|
4
|
+
try {
|
|
5
|
+
const requireFn = createRequire(joinPaths(cwd, 'noop.js'));
|
|
6
|
+
const requiredModule = requireFn(path);
|
|
7
|
+
if (requiredModule) {
|
|
8
|
+
if (requiredModule.default && typeof requiredModule.default === 'function') {
|
|
9
|
+
return requiredModule.default;
|
|
10
|
+
}
|
|
11
|
+
if (typeof requiredModule === 'function') {
|
|
12
|
+
return requiredModule;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (e) { }
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export async function useCustomLoader(loaderPointer, cwd) {
|
|
20
|
+
let loader;
|
|
21
|
+
if (typeof loaderPointer === 'string') {
|
|
22
|
+
loader = await getCustomLoaderByPath(loaderPointer, cwd);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof loaderPointer === 'function') {
|
|
25
|
+
loader = loaderPointer;
|
|
26
|
+
}
|
|
27
|
+
if (typeof loader !== 'function') {
|
|
28
|
+
throw new Error(`Failed to load custom loader: ${loaderPointer}`);
|
|
29
|
+
}
|
|
30
|
+
return loader;
|
|
31
|
+
}
|
|
32
|
+
export function useCustomLoaderSync(loaderPointer, cwd) {
|
|
33
|
+
let loader;
|
|
34
|
+
if (typeof loaderPointer === 'string') {
|
|
35
|
+
loader = getCustomLoaderByPath(loaderPointer, cwd);
|
|
36
|
+
}
|
|
37
|
+
else if (typeof loaderPointer === 'function') {
|
|
38
|
+
loader = loaderPointer;
|
|
39
|
+
}
|
|
40
|
+
if (typeof loader !== 'function') {
|
|
41
|
+
throw new Error(`Failed to load custom loader: ${loaderPointer}`);
|
|
42
|
+
}
|
|
43
|
+
return loader;
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import pLimit from 'p-limit';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a string to 32bit integer
|
|
4
|
+
*/
|
|
5
|
+
export function stringToHash(str) {
|
|
6
|
+
let hash = 0;
|
|
7
|
+
if (str.length === 0) {
|
|
8
|
+
return hash;
|
|
9
|
+
}
|
|
10
|
+
let char;
|
|
11
|
+
for (let i = 0; i < str.length; i++) {
|
|
12
|
+
char = str.charCodeAt(i);
|
|
13
|
+
// tslint:disable-next-line: no-bitwise
|
|
14
|
+
hash = (hash << 5) - hash + char;
|
|
15
|
+
// tslint:disable-next-line: no-bitwise
|
|
16
|
+
hash = hash & hash;
|
|
17
|
+
}
|
|
18
|
+
return hash;
|
|
19
|
+
}
|
|
20
|
+
export function useStack(...fns) {
|
|
21
|
+
return (input) => {
|
|
22
|
+
function createNext(i) {
|
|
23
|
+
if (i >= fns.length) {
|
|
24
|
+
return () => { };
|
|
25
|
+
}
|
|
26
|
+
return function next() {
|
|
27
|
+
fns[i](input, createNext(i + 1));
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
fns[0](input, createNext(1));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function useLimit(concurrency) {
|
|
34
|
+
return pLimit(concurrency);
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { asArray } from '@graphql-tools/utils';
|
|
2
|
+
export function normalizePointers(unnormalizedPointerOrPointers) {
|
|
3
|
+
const ignore = [];
|
|
4
|
+
const pointerOptionMap = {};
|
|
5
|
+
const handlePointer = (rawPointer, options = {}) => {
|
|
6
|
+
if (rawPointer.startsWith('!')) {
|
|
7
|
+
ignore.push(rawPointer.replace('!', ''));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
pointerOptionMap[rawPointer] = options;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
for (const rawPointer of asArray(unnormalizedPointerOrPointers)) {
|
|
14
|
+
if (typeof rawPointer === 'string') {
|
|
15
|
+
handlePointer(rawPointer);
|
|
16
|
+
}
|
|
17
|
+
else if (typeof rawPointer === 'object') {
|
|
18
|
+
for (const [path, options] of Object.entries(rawPointer)) {
|
|
19
|
+
handlePointer(path, options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error(`Invalid pointer '${rawPointer}'.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { ignore, pointerOptionMap };
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import pLimit from 'p-limit';
|
|
2
|
+
export function useQueue(options) {
|
|
3
|
+
const queue = [];
|
|
4
|
+
const limit = (options === null || options === void 0 ? void 0 : options.concurrency) ? pLimit(options.concurrency) : async (fn) => fn();
|
|
5
|
+
return {
|
|
6
|
+
add(fn) {
|
|
7
|
+
queue.push(() => limit(fn));
|
|
8
|
+
},
|
|
9
|
+
runAll() {
|
|
10
|
+
return Promise.all(queue.map(fn => fn()));
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function useSyncQueue() {
|
|
15
|
+
const queue = [];
|
|
16
|
+
return {
|
|
17
|
+
add(fn) {
|
|
18
|
+
queue.push(fn);
|
|
19
|
+
},
|
|
20
|
+
runAll() {
|
|
21
|
+
for (const fn of queue) {
|
|
22
|
+
fn();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/load",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.0-alpha-b76ec274.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 || ^17.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/
|
|
11
|
-
"@graphql-tools/
|
|
10
|
+
"@graphql-tools/utils": "8.8.0-alpha-b76ec274.0",
|
|
11
|
+
"@graphql-tools/schema": "8.5.0-alpha-b76ec274.0",
|
|
12
12
|
"p-limit": "3.1.0",
|
|
13
13
|
"tslib": "^2.4.0"
|
|
14
14
|
},
|
|
@@ -19,21 +19,42 @@
|
|
|
19
19
|
},
|
|
20
20
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"main": "index.js",
|
|
23
|
-
"module": "index.
|
|
24
|
-
"typings": "index.d.ts",
|
|
22
|
+
"main": "cjs/index.js",
|
|
23
|
+
"module": "esm/index.js",
|
|
24
|
+
"typings": "typings/index.d.ts",
|
|
25
25
|
"typescript": {
|
|
26
|
-
"definition": "index.d.ts"
|
|
26
|
+
"definition": "typings/index.d.ts"
|
|
27
27
|
},
|
|
28
|
+
"type": "module",
|
|
28
29
|
"exports": {
|
|
29
30
|
".": {
|
|
30
|
-
"require":
|
|
31
|
-
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./typings/index.d.ts",
|
|
33
|
+
"default": "./cjs/index.js"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./typings/index.d.ts",
|
|
37
|
+
"default": "./esm/index.js"
|
|
38
|
+
},
|
|
39
|
+
"default": {
|
|
40
|
+
"types": "./typings/index.d.ts",
|
|
41
|
+
"default": "./esm/index.js"
|
|
42
|
+
}
|
|
32
43
|
},
|
|
33
44
|
"./*": {
|
|
34
|
-
"require":
|
|
35
|
-
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./typings/*.d.ts",
|
|
47
|
+
"default": "./cjs/*.js"
|
|
48
|
+
},
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./typings/*.d.ts",
|
|
51
|
+
"default": "./esm/*.js"
|
|
52
|
+
},
|
|
53
|
+
"default": {
|
|
54
|
+
"types": "./typings/*.d.ts",
|
|
55
|
+
"default": "./esm/*.js"
|
|
56
|
+
}
|
|
36
57
|
},
|
|
37
58
|
"./package.json": "./package.json"
|
|
38
59
|
}
|
|
39
|
-
}
|
|
60
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Source } from '@graphql-tools/utils';
|
|
2
2
|
import { Kind } from 'graphql';
|
|
3
|
-
import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs';
|
|
3
|
+
import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.js';
|
|
4
4
|
declare type KindList = Array<typeof Kind[keyof typeof Kind]>;
|
|
5
5
|
/**
|
|
6
6
|
* Kinds of AST nodes that are included in executable documents
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Source } from '@graphql-tools/utils';
|
|
2
|
-
import { LoadTypedefsOptions } from '../load-typedefs';
|
|
2
|
+
import { LoadTypedefsOptions } from '../load-typedefs.js';
|
|
3
3
|
export declare function collectSources<TOptions>({ pointerOptionMap, options, }: {
|
|
4
4
|
pointerOptionMap: {
|
|
5
5
|
[key: string]: any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Source } from '@graphql-tools/utils';
|
|
2
|
-
import { LoadTypedefsOptions } from '../load-typedefs';
|
|
2
|
+
import { LoadTypedefsOptions } from '../load-typedefs.js';
|
|
3
3
|
export declare function loadFile(pointer: string, options: LoadTypedefsOptions): Promise<Source[]>;
|
|
4
4
|
export declare function loadFileSync(pointer: string, options: LoadTypedefsOptions): Source[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LoadTypedefsOptions } from './../load-typedefs';
|
|
1
|
+
import { LoadTypedefsOptions } from './../load-typedefs.js';
|
|
2
2
|
export declare function applyDefaultOptions<T>(options: LoadTypedefsOptions<Partial<T>>): void;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs';
|
|
1
|
+
import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.js';
|
|
2
2
|
import { GraphQLSchema, BuildSchemaOptions } from 'graphql';
|
|
3
3
|
import { MergeSchemasConfig } from '@graphql-tools/schema';
|
|
4
4
|
export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<MergeSchemasConfig> & {
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UnnormalizedTypeDefPointer } from './../load-typedefs';
|
|
1
|
+
import { UnnormalizedTypeDefPointer } from './../load-typedefs.js';
|
|
2
2
|
export declare function normalizePointers(unnormalizedPointerOrPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[]): {
|
|
3
3
|
ignore: string[];
|
|
4
4
|
pointerOptionMap: Record<string, Record<string, any>>;
|
|
File without changes
|
package/README.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Check API Reference for more information about this package;
|
|
2
|
-
https://www.graphql-tools.com/docs/api/modules/load_src
|
|
3
|
-
|
|
4
|
-
You can also learn more about Apollo Links in Schema Loading in this chapter;
|
|
5
|
-
https://www.graphql-tools.com/docs/schema-loading
|
|
6
|
-
|
|
7
|
-
You can also learn more about Apollo Links in Documents Loading in this chapter;
|
|
8
|
-
https://www.graphql-tools.com/docs/documents-loading
|
package/index.d.ts
DELETED