@graphql-tools/graphql-file-loader 7.3.16 → 7.4.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/{index.js → cjs/index.js} +36 -40
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +9 -12
- package/package.json +35 -14
- /package/{index.d.ts → typings/index.d.ts} +0 -0
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const unixify = _interopDefault(require('unixify'));
|
|
14
|
-
|
|
15
|
-
const { readFile, access } = fs.promises;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLFileLoader = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const process_1 = require("process");
|
|
9
|
+
const import_1 = require("@graphql-tools/import");
|
|
10
|
+
const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
11
|
+
const unixify_1 = tslib_1.__importDefault(require("unixify"));
|
|
12
|
+
const { readFile, access } = fs_1.promises;
|
|
16
13
|
const FILE_EXTENSIONS = ['.gql', '.gqls', '.graphql', '.graphqls'];
|
|
17
14
|
function isGraphQLImportFile(rawSDL) {
|
|
18
15
|
const trimmedRawSDL = rawSDL.trim();
|
|
@@ -47,9 +44,9 @@ const buildIgnoreGlob = (path) => `!${path}`;
|
|
|
47
44
|
*/
|
|
48
45
|
class GraphQLFileLoader {
|
|
49
46
|
async canLoad(pointer, options) {
|
|
50
|
-
if (
|
|
47
|
+
if ((0, utils_1.isValidPath)(pointer)) {
|
|
51
48
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
52
|
-
const normalizedFilePath =
|
|
49
|
+
const normalizedFilePath = (0, path_1.isAbsolute)(pointer) ? pointer : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), pointer);
|
|
53
50
|
try {
|
|
54
51
|
await access(normalizedFilePath);
|
|
55
52
|
return true;
|
|
@@ -62,52 +59,52 @@ class GraphQLFileLoader {
|
|
|
62
59
|
return false;
|
|
63
60
|
}
|
|
64
61
|
canLoadSync(pointer, options) {
|
|
65
|
-
if (
|
|
62
|
+
if ((0, utils_1.isValidPath)(pointer)) {
|
|
66
63
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
67
|
-
const normalizedFilePath =
|
|
68
|
-
return
|
|
64
|
+
const normalizedFilePath = (0, path_1.isAbsolute)(pointer) ? pointer : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), pointer);
|
|
65
|
+
return (0, fs_1.existsSync)(normalizedFilePath);
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
return false;
|
|
72
69
|
}
|
|
73
70
|
_buildGlobs(glob, options) {
|
|
74
|
-
const ignores =
|
|
75
|
-
const globs = [
|
|
71
|
+
const ignores = (0, utils_1.asArray)(options.ignore || []);
|
|
72
|
+
const globs = [(0, unixify_1.default)(glob), ...ignores.map(v => buildIgnoreGlob((0, unixify_1.default)(v)))];
|
|
76
73
|
return globs;
|
|
77
74
|
}
|
|
78
75
|
async resolveGlobs(glob, options) {
|
|
79
76
|
if (!glob.includes('*') &&
|
|
80
77
|
(await this.canLoad(glob, options)) &&
|
|
81
|
-
!
|
|
78
|
+
!(0, utils_1.asArray)(options.ignore || []).length &&
|
|
82
79
|
!options['includeSources'])
|
|
83
80
|
return [glob]; // bypass globby when no glob character, can be loaded, no ignores and source not requested. Fixes problem with pkg and passes ci tests
|
|
84
81
|
const globs = this._buildGlobs(glob, options);
|
|
85
|
-
const result = await
|
|
82
|
+
const result = await (0, globby_1.default)(globs, createGlobbyOptions(options));
|
|
86
83
|
return result;
|
|
87
84
|
}
|
|
88
85
|
resolveGlobsSync(glob, options) {
|
|
89
86
|
if (!glob.includes('*') &&
|
|
90
87
|
this.canLoadSync(glob, options) &&
|
|
91
|
-
!
|
|
88
|
+
!(0, utils_1.asArray)(options.ignore || []).length &&
|
|
92
89
|
!options['includeSources'])
|
|
93
90
|
return [glob]; // bypass globby when no glob character, can be loaded, no ignores and source not requested. Fixes problem with pkg and passes ci tests
|
|
94
91
|
const globs = this._buildGlobs(glob, options);
|
|
95
|
-
const result =
|
|
92
|
+
const result = globby_1.default.sync(globs, createGlobbyOptions(options));
|
|
96
93
|
return result;
|
|
97
94
|
}
|
|
98
95
|
async load(pointer, options) {
|
|
99
96
|
const resolvedPaths = await this.resolveGlobs(pointer, options);
|
|
100
97
|
const finalResult = [];
|
|
101
98
|
const errors = [];
|
|
102
|
-
await Promise.all(resolvedPaths.map(async (path
|
|
103
|
-
if (await this.canLoad(path
|
|
99
|
+
await Promise.all(resolvedPaths.map(async (path) => {
|
|
100
|
+
if (await this.canLoad(path, options)) {
|
|
104
101
|
try {
|
|
105
|
-
const normalizedFilePath =
|
|
102
|
+
const normalizedFilePath = (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), path);
|
|
106
103
|
const rawSDL = await readFile(normalizedFilePath, { encoding: 'utf8' });
|
|
107
104
|
finalResult.push(this.handleFileContent(rawSDL, normalizedFilePath, options));
|
|
108
105
|
}
|
|
109
106
|
catch (e) {
|
|
110
|
-
if (
|
|
107
|
+
if (process_1.env['DEBUG']) {
|
|
111
108
|
console.error(e);
|
|
112
109
|
}
|
|
113
110
|
errors.push(e);
|
|
@@ -118,7 +115,7 @@ class GraphQLFileLoader {
|
|
|
118
115
|
if (errors.length === 1) {
|
|
119
116
|
throw errors[0];
|
|
120
117
|
}
|
|
121
|
-
throw new
|
|
118
|
+
throw new utils_1.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
|
|
122
119
|
}
|
|
123
120
|
return finalResult;
|
|
124
121
|
}
|
|
@@ -126,15 +123,15 @@ class GraphQLFileLoader {
|
|
|
126
123
|
const resolvedPaths = this.resolveGlobsSync(pointer, options);
|
|
127
124
|
const finalResult = [];
|
|
128
125
|
const errors = [];
|
|
129
|
-
for (const path
|
|
130
|
-
if (this.canLoadSync(path
|
|
126
|
+
for (const path of resolvedPaths) {
|
|
127
|
+
if (this.canLoadSync(path, options)) {
|
|
131
128
|
try {
|
|
132
|
-
const normalizedFilePath =
|
|
133
|
-
const rawSDL =
|
|
129
|
+
const normalizedFilePath = (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), path);
|
|
130
|
+
const rawSDL = (0, fs_1.readFileSync)(normalizedFilePath, { encoding: 'utf8' });
|
|
134
131
|
finalResult.push(this.handleFileContent(rawSDL, normalizedFilePath, options));
|
|
135
132
|
}
|
|
136
133
|
catch (e) {
|
|
137
|
-
if (
|
|
134
|
+
if (process_1.env['DEBUG']) {
|
|
138
135
|
console.error(e);
|
|
139
136
|
}
|
|
140
137
|
errors.push(e);
|
|
@@ -145,20 +142,19 @@ class GraphQLFileLoader {
|
|
|
145
142
|
if (errors.length === 1) {
|
|
146
143
|
throw errors[0];
|
|
147
144
|
}
|
|
148
|
-
throw new
|
|
145
|
+
throw new utils_1.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
|
|
149
146
|
}
|
|
150
147
|
return finalResult;
|
|
151
148
|
}
|
|
152
149
|
handleFileContent(rawSDL, pointer, options) {
|
|
153
150
|
if (!options.skipGraphQLImport && isGraphQLImportFile(rawSDL)) {
|
|
154
|
-
const document =
|
|
151
|
+
const document = (0, import_1.processImport)(pointer, options.cwd);
|
|
155
152
|
return {
|
|
156
153
|
location: pointer,
|
|
157
154
|
document,
|
|
158
155
|
};
|
|
159
156
|
}
|
|
160
|
-
return
|
|
157
|
+
return (0, utils_1.parseGraphQLSDL)(pointer, rawSDL, options);
|
|
161
158
|
}
|
|
162
159
|
}
|
|
163
|
-
|
|
164
160
|
exports.GraphQLFileLoader = GraphQLFileLoader;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { isValidPath, asArray, AggregateError,
|
|
1
|
+
import { isValidPath, parseGraphQLSDL, asArray, AggregateError, } from '@graphql-tools/utils';
|
|
2
2
|
import { isAbsolute, resolve } from 'path';
|
|
3
|
-
import {
|
|
4
|
-
import { cwd, env } from 'process';
|
|
3
|
+
import { readFileSync, promises as fsPromises, existsSync } from 'fs';
|
|
4
|
+
import { cwd as processCwd, env } from 'process';
|
|
5
5
|
import { processImport } from '@graphql-tools/import';
|
|
6
6
|
import globby from 'globby';
|
|
7
7
|
import unixify from 'unixify';
|
|
8
|
-
|
|
9
|
-
const { readFile, access } = promises;
|
|
8
|
+
const { readFile, access } = fsPromises;
|
|
10
9
|
const FILE_EXTENSIONS = ['.gql', '.gqls', '.graphql', '.graphqls'];
|
|
11
10
|
function isGraphQLImportFile(rawSDL) {
|
|
12
11
|
const trimmedRawSDL = rawSDL.trim();
|
|
@@ -39,11 +38,11 @@ const buildIgnoreGlob = (path) => `!${path}`;
|
|
|
39
38
|
* });
|
|
40
39
|
* ```
|
|
41
40
|
*/
|
|
42
|
-
class GraphQLFileLoader {
|
|
41
|
+
export class GraphQLFileLoader {
|
|
43
42
|
async canLoad(pointer, options) {
|
|
44
43
|
if (isValidPath(pointer)) {
|
|
45
44
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
46
|
-
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd ||
|
|
45
|
+
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || processCwd(), pointer);
|
|
47
46
|
try {
|
|
48
47
|
await access(normalizedFilePath);
|
|
49
48
|
return true;
|
|
@@ -58,7 +57,7 @@ class GraphQLFileLoader {
|
|
|
58
57
|
canLoadSync(pointer, options) {
|
|
59
58
|
if (isValidPath(pointer)) {
|
|
60
59
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
61
|
-
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd ||
|
|
60
|
+
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || processCwd(), pointer);
|
|
62
61
|
return existsSync(normalizedFilePath);
|
|
63
62
|
}
|
|
64
63
|
}
|
|
@@ -96,7 +95,7 @@ class GraphQLFileLoader {
|
|
|
96
95
|
await Promise.all(resolvedPaths.map(async (path) => {
|
|
97
96
|
if (await this.canLoad(path, options)) {
|
|
98
97
|
try {
|
|
99
|
-
const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd ||
|
|
98
|
+
const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd || processCwd(), path);
|
|
100
99
|
const rawSDL = await readFile(normalizedFilePath, { encoding: 'utf8' });
|
|
101
100
|
finalResult.push(this.handleFileContent(rawSDL, normalizedFilePath, options));
|
|
102
101
|
}
|
|
@@ -123,7 +122,7 @@ class GraphQLFileLoader {
|
|
|
123
122
|
for (const path of resolvedPaths) {
|
|
124
123
|
if (this.canLoadSync(path, options)) {
|
|
125
124
|
try {
|
|
126
|
-
const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd ||
|
|
125
|
+
const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd || processCwd(), path);
|
|
127
126
|
const rawSDL = readFileSync(normalizedFilePath, { encoding: 'utf8' });
|
|
128
127
|
finalResult.push(this.handleFileContent(rawSDL, normalizedFilePath, options));
|
|
129
128
|
}
|
|
@@ -154,5 +153,3 @@ class GraphQLFileLoader {
|
|
|
154
153
|
return parseGraphQLSDL(pointer, rawSDL, options);
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
|
-
|
|
158
|
-
export { GraphQLFileLoader };
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/graphql-file-loader",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.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/import": "6.
|
|
11
|
-
"@graphql-tools/utils": "8.
|
|
10
|
+
"@graphql-tools/import": "6.7.0-alpha-b76ec274.0",
|
|
11
|
+
"@graphql-tools/utils": "8.8.0-alpha-b76ec274.0",
|
|
12
12
|
"globby": "^11.0.3",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"unixify": "^1.0.0",
|
|
14
|
+
"tslib": "^2.4.0"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -20,21 +20,42 @@
|
|
|
20
20
|
},
|
|
21
21
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
22
22
|
"license": "MIT",
|
|
23
|
-
"main": "index.js",
|
|
24
|
-
"module": "index.
|
|
25
|
-
"typings": "index.d.ts",
|
|
23
|
+
"main": "cjs/index.js",
|
|
24
|
+
"module": "esm/index.js",
|
|
25
|
+
"typings": "typings/index.d.ts",
|
|
26
26
|
"typescript": {
|
|
27
|
-
"definition": "index.d.ts"
|
|
27
|
+
"definition": "typings/index.d.ts"
|
|
28
28
|
},
|
|
29
|
+
"type": "module",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./typings/index.d.ts",
|
|
42
|
+
"default": "./esm/index.js"
|
|
43
|
+
}
|
|
33
44
|
},
|
|
34
45
|
"./*": {
|
|
35
|
-
"require":
|
|
36
|
-
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./typings/*.d.ts",
|
|
48
|
+
"default": "./cjs/*.js"
|
|
49
|
+
},
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./typings/*.d.ts",
|
|
52
|
+
"default": "./esm/*.js"
|
|
53
|
+
},
|
|
54
|
+
"default": {
|
|
55
|
+
"types": "./typings/*.d.ts",
|
|
56
|
+
"default": "./esm/*.js"
|
|
57
|
+
}
|
|
37
58
|
},
|
|
38
59
|
"./package.json": "./package.json"
|
|
39
60
|
}
|
|
40
|
-
}
|
|
61
|
+
}
|
|
File without changes
|