@graphql-tools/json-file-loader 6.2.6-alpha-2350e731.0 → 6.2.6
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/es5/index.cjs.js +28 -11
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.esm.js +26 -9
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +2 -3
- package/index.cjs.js +18 -5
- package/index.cjs.js.map +1 -1
- package/index.esm.js +16 -3
- package/index.esm.js.map +1 -1
- package/package.json +2 -3
package/es5/index.cjs.js
CHANGED
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const tslib = require('tslib');
|
|
6
6
|
const utils = require('@graphql-tools/utils/es5');
|
|
7
7
|
const path = require('path');
|
|
8
|
-
const
|
|
8
|
+
const fs = require('fs');
|
|
9
9
|
const process = require('process');
|
|
10
10
|
|
|
11
|
+
var readFile = fs.promises.readFile, access = fs.promises.access;
|
|
11
12
|
var FILE_EXTENSIONS = ['.json'];
|
|
12
13
|
/**
|
|
13
14
|
* This loader loads documents and type definitions from JSON files.
|
|
@@ -40,15 +41,25 @@ var JsonFileLoader = /** @class */ (function () {
|
|
|
40
41
|
};
|
|
41
42
|
JsonFileLoader.prototype.canLoad = function (pointer, options) {
|
|
42
43
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var normalizedFilePath;
|
|
44
|
-
return tslib.__generator(this, function (
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
var normalizedFilePath, _a;
|
|
45
|
+
return tslib.__generator(this, function (_b) {
|
|
46
|
+
switch (_b.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
if (!utils.isValidPath(pointer)) return [3 /*break*/, 4];
|
|
49
|
+
if (!FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) return [3 /*break*/, 4];
|
|
47
50
|
normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
_b.label = 1;
|
|
52
|
+
case 1:
|
|
53
|
+
_b.trys.push([1, 3, , 4]);
|
|
54
|
+
return [4 /*yield*/, access(normalizedFilePath)];
|
|
55
|
+
case 2:
|
|
56
|
+
_b.sent();
|
|
57
|
+
return [2 /*return*/, true];
|
|
58
|
+
case 3:
|
|
59
|
+
_a = _b.sent();
|
|
60
|
+
return [2 /*return*/, false];
|
|
61
|
+
case 4: return [2 /*return*/, false];
|
|
50
62
|
}
|
|
51
|
-
return [2 /*return*/, false];
|
|
52
63
|
});
|
|
53
64
|
});
|
|
54
65
|
};
|
|
@@ -56,7 +67,13 @@ var JsonFileLoader = /** @class */ (function () {
|
|
|
56
67
|
if (utils.isValidPath(pointer)) {
|
|
57
68
|
if (FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) {
|
|
58
69
|
var normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
59
|
-
|
|
70
|
+
try {
|
|
71
|
+
fs.accessSync(normalizedFilePath);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch (_a) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
79
|
return false;
|
|
@@ -71,7 +88,7 @@ var JsonFileLoader = /** @class */ (function () {
|
|
|
71
88
|
_a.label = 1;
|
|
72
89
|
case 1:
|
|
73
90
|
_a.trys.push([1, 3, , 4]);
|
|
74
|
-
return [4 /*yield*/,
|
|
91
|
+
return [4 /*yield*/, readFile(normalizedFilePath, { encoding: 'utf8' })];
|
|
75
92
|
case 2:
|
|
76
93
|
jsonContent = _a.sent();
|
|
77
94
|
return [2 /*return*/, utils.parseGraphQLJSON(pointer, jsonContent, options)];
|
|
@@ -86,7 +103,7 @@ var JsonFileLoader = /** @class */ (function () {
|
|
|
86
103
|
JsonFileLoader.prototype.loadSync = function (pointer, options) {
|
|
87
104
|
var normalizedFilepath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
88
105
|
try {
|
|
89
|
-
var jsonContent =
|
|
106
|
+
var jsonContent = fs.readFileSync(normalizedFilepath, 'utf8');
|
|
90
107
|
return utils.parseGraphQLJSON(pointer, jsonContent, options);
|
|
91
108
|
}
|
|
92
109
|
catch (e) {
|
package/es5/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../../dist-es5/loaders/json-file/src/index.js"],"sourcesContent":["import { __awaiter, __generator } from \"tslib\";\nimport { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport {
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../../dist-es5/loaders/json-file/src/index.js"],"sourcesContent":["import { __awaiter, __generator } from \"tslib\";\nimport { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport { readFileSync, accessSync, promises as fsPromises } from 'fs';\nimport { cwd } from 'process';\nvar readFile = fsPromises.readFile, access = fsPromises.access;\nvar FILE_EXTENSIONS = ['.json'];\n/**\n * This loader loads documents and type definitions from JSON files.\n *\n * The JSON file can be the result of an introspection query made against a schema:\n *\n * ```js\n * const schema = await loadSchema('schema-introspection.json', {\n * loaders: [\n * new JsonFileLoader()\n * ]\n * });\n * ```\n *\n * Or it can be a `DocumentNode` object representing a GraphQL document or type definitions:\n *\n * ```js\n * const documents = await loadDocuments('queries/*.json', {\n * loaders: [\n * new GraphQLFileLoader()\n * ]\n * });\n * ```\n */\nvar JsonFileLoader = /** @class */ (function () {\n function JsonFileLoader() {\n }\n JsonFileLoader.prototype.loaderId = function () {\n return 'json-file';\n };\n JsonFileLoader.prototype.canLoad = function (pointer, options) {\n return __awaiter(this, void 0, void 0, function () {\n var normalizedFilePath, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (!isValidPath(pointer)) return [3 /*break*/, 4];\n if (!FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) return [3 /*break*/, 4];\n normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n _b.label = 1;\n case 1:\n _b.trys.push([1, 3, , 4]);\n return [4 /*yield*/, access(normalizedFilePath)];\n case 2:\n _b.sent();\n return [2 /*return*/, true];\n case 3:\n _a = _b.sent();\n return [2 /*return*/, false];\n case 4: return [2 /*return*/, false];\n }\n });\n });\n };\n JsonFileLoader.prototype.canLoadSync = function (pointer, options) {\n if (isValidPath(pointer)) {\n if (FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) {\n var normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n accessSync(normalizedFilePath);\n return true;\n }\n catch (_a) {\n return false;\n }\n }\n }\n return false;\n };\n JsonFileLoader.prototype.load = function (pointer, options) {\n return __awaiter(this, void 0, void 0, function () {\n var normalizedFilePath, jsonContent, e_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n _a.label = 1;\n case 1:\n _a.trys.push([1, 3, , 4]);\n return [4 /*yield*/, readFile(normalizedFilePath, { encoding: 'utf8' })];\n case 2:\n jsonContent = _a.sent();\n return [2 /*return*/, parseGraphQLJSON(pointer, jsonContent, options)];\n case 3:\n e_1 = _a.sent();\n throw new Error(\"Unable to read JSON file: \" + normalizedFilePath + \": \" + (e_1.message || /* istanbul ignore next */ e_1));\n case 4: return [2 /*return*/];\n }\n });\n });\n };\n JsonFileLoader.prototype.loadSync = function (pointer, options) {\n var normalizedFilepath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n var jsonContent = readFileSync(normalizedFilepath, 'utf8');\n return parseGraphQLJSON(pointer, jsonContent, options);\n }\n catch (e) {\n throw new Error(\"Unable to read JSON file: \" + normalizedFilepath + \": \" + (e.message || /* istanbul ignore next */ e));\n }\n };\n return JsonFileLoader;\n}());\nexport { JsonFileLoader };\n//# sourceMappingURL=index.js.map"],"names":["fsPromises","__awaiter","__generator","isValidPath","isAbsolute","resolve","cwd","accessSync","parseGraphQLJSON","readFileSync"],"mappings":";;;;;;;;;;AAKA,IAAI,QAAQ,GAAGA,WAAU,CAAC,QAAQ,EAAE,MAAM,GAAGA,WAAU,CAAC,MAAM,CAAC;AAC/D,IAAI,eAAe,GAAG,CAAC,OAAO,CAAC,CAAC;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACG,IAAC,cAAc,kBAAkB,YAAY;AAChD,IAAI,SAAS,cAAc,GAAG;AAC9B,KAAK;AACL,IAAI,cAAc,CAAC,SAAS,CAAC,QAAQ,GAAG,YAAY;AACpD,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,SAAS,CAAC,OAAO,GAAG,UAAU,OAAO,EAAE,OAAO,EAAE;AACnE,QAAQ,OAAOC,eAAS,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,YAAY;AAC3D,YAAY,IAAI,kBAAkB,EAAE,EAAE,CAAC;AACvC,YAAY,OAAOC,iBAAW,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE;AACnD,gBAAgB,QAAQ,EAAE,CAAC,KAAK;AAChC,oBAAoB,KAAK,CAAC;AAC1B,wBAAwB,IAAI,CAACC,iBAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;AAC3E,wBAAwB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,SAAS,EAAE,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,C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Absolute, resolve } from 'path';
|
|
4
|
-
import {
|
|
4
|
+
import { promises, accessSync, readFileSync } from 'fs';
|
|
5
5
|
import { cwd } from 'process';
|
|
6
6
|
|
|
7
|
+
var readFile = promises.readFile, access = promises.access;
|
|
7
8
|
var FILE_EXTENSIONS = ['.json'];
|
|
8
9
|
/**
|
|
9
10
|
* This loader loads documents and type definitions from JSON files.
|
|
@@ -36,15 +37,25 @@ var JsonFileLoader = /** @class */ (function () {
|
|
|
36
37
|
};
|
|
37
38
|
JsonFileLoader.prototype.canLoad = function (pointer, options) {
|
|
38
39
|
return __awaiter(this, void 0, void 0, function () {
|
|
39
|
-
var normalizedFilePath;
|
|
40
|
-
return __generator(this, function (
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var normalizedFilePath, _a;
|
|
41
|
+
return __generator(this, function (_b) {
|
|
42
|
+
switch (_b.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
if (!isValidPath(pointer)) return [3 /*break*/, 4];
|
|
45
|
+
if (!FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) return [3 /*break*/, 4];
|
|
43
46
|
normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
_b.label = 1;
|
|
48
|
+
case 1:
|
|
49
|
+
_b.trys.push([1, 3, , 4]);
|
|
50
|
+
return [4 /*yield*/, access(normalizedFilePath)];
|
|
51
|
+
case 2:
|
|
52
|
+
_b.sent();
|
|
53
|
+
return [2 /*return*/, true];
|
|
54
|
+
case 3:
|
|
55
|
+
_a = _b.sent();
|
|
56
|
+
return [2 /*return*/, false];
|
|
57
|
+
case 4: return [2 /*return*/, false];
|
|
46
58
|
}
|
|
47
|
-
return [2 /*return*/, false];
|
|
48
59
|
});
|
|
49
60
|
});
|
|
50
61
|
};
|
|
@@ -52,7 +63,13 @@ var JsonFileLoader = /** @class */ (function () {
|
|
|
52
63
|
if (isValidPath(pointer)) {
|
|
53
64
|
if (FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) {
|
|
54
65
|
var normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);
|
|
55
|
-
|
|
66
|
+
try {
|
|
67
|
+
accessSync(normalizedFilePath);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch (_a) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
56
73
|
}
|
|
57
74
|
}
|
|
58
75
|
return false;
|
package/es5/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../../dist-es5/loaders/json-file/src/index.js"],"sourcesContent":["import { __awaiter, __generator } from \"tslib\";\nimport { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport {
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../../dist-es5/loaders/json-file/src/index.js"],"sourcesContent":["import { __awaiter, __generator } from \"tslib\";\nimport { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport { readFileSync, accessSync, promises as fsPromises } from 'fs';\nimport { cwd } from 'process';\nvar readFile = fsPromises.readFile, access = fsPromises.access;\nvar FILE_EXTENSIONS = ['.json'];\n/**\n * This loader loads documents and type definitions from JSON files.\n *\n * The JSON file can be the result of an introspection query made against a schema:\n *\n * ```js\n * const schema = await loadSchema('schema-introspection.json', {\n * loaders: [\n * new JsonFileLoader()\n * ]\n * });\n * ```\n *\n * Or it can be a `DocumentNode` object representing a GraphQL document or type definitions:\n *\n * ```js\n * const documents = await loadDocuments('queries/*.json', {\n * loaders: [\n * new GraphQLFileLoader()\n * ]\n * });\n * ```\n */\nvar JsonFileLoader = /** @class */ (function () {\n function JsonFileLoader() {\n }\n JsonFileLoader.prototype.loaderId = function () {\n return 'json-file';\n };\n JsonFileLoader.prototype.canLoad = function (pointer, options) {\n return __awaiter(this, void 0, void 0, function () {\n var normalizedFilePath, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (!isValidPath(pointer)) return [3 /*break*/, 4];\n if (!FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) return [3 /*break*/, 4];\n normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n _b.label = 1;\n case 1:\n _b.trys.push([1, 3, , 4]);\n return [4 /*yield*/, access(normalizedFilePath)];\n case 2:\n _b.sent();\n return [2 /*return*/, true];\n case 3:\n _a = _b.sent();\n return [2 /*return*/, false];\n case 4: return [2 /*return*/, false];\n }\n });\n });\n };\n JsonFileLoader.prototype.canLoadSync = function (pointer, options) {\n if (isValidPath(pointer)) {\n if (FILE_EXTENSIONS.find(function (extension) { return pointer.endsWith(extension); })) {\n var normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n accessSync(normalizedFilePath);\n return true;\n }\n catch (_a) {\n return false;\n }\n }\n }\n return false;\n };\n JsonFileLoader.prototype.load = function (pointer, options) {\n return __awaiter(this, void 0, void 0, function () {\n var normalizedFilePath, jsonContent, e_1;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n _a.label = 1;\n case 1:\n _a.trys.push([1, 3, , 4]);\n return [4 /*yield*/, readFile(normalizedFilePath, { encoding: 'utf8' })];\n case 2:\n jsonContent = _a.sent();\n return [2 /*return*/, parseGraphQLJSON(pointer, jsonContent, options)];\n case 3:\n e_1 = _a.sent();\n throw new Error(\"Unable to read JSON file: \" + normalizedFilePath + \": \" + (e_1.message || /* istanbul ignore next */ e_1));\n case 4: return [2 /*return*/];\n }\n });\n });\n };\n JsonFileLoader.prototype.loadSync = function (pointer, options) {\n var normalizedFilepath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n var jsonContent = readFileSync(normalizedFilepath, 'utf8');\n return parseGraphQLJSON(pointer, jsonContent, options);\n }\n catch (e) {\n throw new Error(\"Unable to read JSON file: \" + normalizedFilepath + \": \" + (e.message || /* istanbul ignore next */ e));\n }\n };\n return JsonFileLoader;\n}());\nexport { JsonFileLoader };\n//# sourceMappingURL=index.js.map"],"names":["fsPromises"],"mappings":";;;;;;AAKA,IAAI,QAAQ,GAAGA,QAAU,CAAC,QAAQ,EAAE,MAAM,GAAGA,QAAU,CAAC,MAAM,CAAC;AAC/D,IAAI,eAAe,GAAG,CAAC,OAAO,CAAC,CAAC;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACG,IAAC,cAAc,kBAAkB,YAAY;AAChD,IAAI,SAAS,cAAc,GAAG;AAC9B,KAAK;AACL,IAAI,cAAc,CAAC,SAAS,CAAC,QAAQ,GAAG,YAAY;AACpD,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,SAAS,CAAC,OAAO,GAAG,UAAU,OAAO,EAAE,OAAO,EAAE;AACnE,QAAQ,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,YAAY;AAC3D,YAAY,IAAI,kBAAkB,EAAE,EAAE,CAAC;AACvC,YAAY,OAAO,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE;AACnD,gBAAgB,QAAQ,EAAE,CAAC,KAAK;AAChC,oBAAoB,KAAK,CAAC;AAC1B,wBAAwB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;AAC3E,wBAAwB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,SAAS,EAAE,EAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,C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AE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/F,oBAAoB,KAAK,CAAC;AAC1B,wBAAwB,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;AACxC,wBAAwB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,kBAAkB,GAAG,IAAI,IAAI,GAAG,CAAC,OAAO,+BAA+B,GAAG,CAAC,CAAC,CAAC;AACpJ,oBAAoB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,YAAY,CAAC;AAClD,iBAAiB;AACjB,aAAa,CAAC,CAAC;AACf,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,SAAS,CAAC,QAAQ,GAAG,UAAU,OAAO,EAAE,OAAO,EAAE;AACpE,QAAQ,IAAI,kBAAkB,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;AACxG,QAAQ,IAAI;AACZ,YAAY,IAAI,WAAW,GAAG,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AACvE,YAAY,OAAO,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACnE,SAAS;AACT,QAAQ,OAAO,CAAC,EAAE;AAClB,YAAY,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,kBAAkB,GAAG,IAAI,IAAI,CAAC,CAAC,OAAO,+BAA+B,CAAC,CAAC,CAAC,CAAC;AACpI,SAAS;AACT,KAAK,CAAC;AACN,IAAI,OAAO,cAAc,CAAC;AAC1B,CAAC,EAAE;;;;"}
|
package/es5/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/json-file-loader/es5",
|
|
3
|
-
"version": "6.2.6
|
|
3
|
+
"version": "6.2.6",
|
|
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"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "7.0.
|
|
11
|
-
"fs-extra": "9.0.1",
|
|
10
|
+
"@graphql-tools/utils": "^7.0.0",
|
|
12
11
|
"tslib": "~2.0.1"
|
|
13
12
|
},
|
|
14
13
|
"repository": "git@github.com:ardatan/graphql-tools.git",
|
package/index.cjs.js
CHANGED
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const utils = require('@graphql-tools/utils');
|
|
6
6
|
const path = require('path');
|
|
7
|
-
const
|
|
7
|
+
const fs = require('fs');
|
|
8
8
|
const process = require('process');
|
|
9
9
|
|
|
10
|
+
const { readFile, access } = fs.promises;
|
|
10
11
|
const FILE_EXTENSIONS = ['.json'];
|
|
11
12
|
/**
|
|
12
13
|
* This loader loads documents and type definitions from JSON files.
|
|
@@ -39,7 +40,13 @@ class JsonFileLoader {
|
|
|
39
40
|
if (utils.isValidPath(pointer)) {
|
|
40
41
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
41
42
|
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
42
|
-
|
|
43
|
+
try {
|
|
44
|
+
await access(normalizedFilePath);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
return false;
|
|
@@ -48,7 +55,13 @@ class JsonFileLoader {
|
|
|
48
55
|
if (utils.isValidPath(pointer)) {
|
|
49
56
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
50
57
|
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
51
|
-
|
|
58
|
+
try {
|
|
59
|
+
fs.accessSync(normalizedFilePath);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch (_a) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
return false;
|
|
@@ -56,7 +69,7 @@ class JsonFileLoader {
|
|
|
56
69
|
async load(pointer, options) {
|
|
57
70
|
const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
58
71
|
try {
|
|
59
|
-
const jsonContent = await
|
|
72
|
+
const jsonContent = await readFile(normalizedFilePath, { encoding: 'utf8' });
|
|
60
73
|
return utils.parseGraphQLJSON(pointer, jsonContent, options);
|
|
61
74
|
}
|
|
62
75
|
catch (e) {
|
|
@@ -66,7 +79,7 @@ class JsonFileLoader {
|
|
|
66
79
|
loadSync(pointer, options) {
|
|
67
80
|
const normalizedFilepath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
|
|
68
81
|
try {
|
|
69
|
-
const jsonContent =
|
|
82
|
+
const jsonContent = fs.readFileSync(normalizedFilepath, 'utf8');
|
|
70
83
|
return utils.parseGraphQLJSON(pointer, jsonContent, options);
|
|
71
84
|
}
|
|
72
85
|
catch (e) {
|
package/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../../dist/loaders/json-file/src/index.js"],"sourcesContent":["import { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport {
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../../dist/loaders/json-file/src/index.js"],"sourcesContent":["import { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport { readFileSync, accessSync, promises as fsPromises } from 'fs';\nimport { cwd } from 'process';\nconst { readFile, access } = fsPromises;\nconst FILE_EXTENSIONS = ['.json'];\n/**\n * This loader loads documents and type definitions from JSON files.\n *\n * The JSON file can be the result of an introspection query made against a schema:\n *\n * ```js\n * const schema = await loadSchema('schema-introspection.json', {\n * loaders: [\n * new JsonFileLoader()\n * ]\n * });\n * ```\n *\n * Or it can be a `DocumentNode` object representing a GraphQL document or type definitions:\n *\n * ```js\n * const documents = await loadDocuments('queries/*.json', {\n * loaders: [\n * new GraphQLFileLoader()\n * ]\n * });\n * ```\n */\nexport class JsonFileLoader {\n loaderId() {\n return 'json-file';\n }\n async canLoad(pointer, options) {\n if (isValidPath(pointer)) {\n if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {\n const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n await access(normalizedFilePath);\n return true;\n }\n catch (_a) {\n return false;\n }\n }\n }\n return false;\n }\n canLoadSync(pointer, options) {\n if (isValidPath(pointer)) {\n if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {\n const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n accessSync(normalizedFilePath);\n return true;\n }\n catch (_a) {\n return false;\n }\n }\n }\n return false;\n }\n async load(pointer, options) {\n const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n const jsonContent = await readFile(normalizedFilePath, { encoding: 'utf8' });\n return parseGraphQLJSON(pointer, jsonContent, options);\n }\n catch (e) {\n throw new Error(`Unable to read JSON file: ${normalizedFilePath}: ${e.message || /* istanbul ignore next */ e}`);\n }\n }\n loadSync(pointer, options) {\n const normalizedFilepath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n const jsonContent = readFileSync(normalizedFilepath, 'utf8');\n return parseGraphQLJSON(pointer, jsonContent, options);\n }\n catch (e) {\n throw new Error(`Unable to read JSON file: ${normalizedFilepath}: ${e.message || /* istanbul ignore next */ e}`);\n }\n }\n}\n//# sourceMappingURL=index.js.map"],"names":["fsPromises","isValidPath","isAbsolute","resolve","cwd","accessSync","parseGraphQLJSON","readFileSync"],"mappings":";;;;;;;;;AAIA,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAGA,WAAU,CAAC;AACxC,MAAM,eAAe,GAAG,CAAC,OAAO,CAAC,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,cAAc,CAAC;AAC5B,IAAI,QAAQ,GAAG;AACf,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE;AACpC,QAAQ,IAAIC,iBAAW,CAAC,OAAO,CAAC,EAAE;AAClC,YAAY,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE;AAChF,gBAAgB,MAAM,kBAAkB,GAAGC,eAAU,CAAC,OAAO,CAAC,GAAG,OAAO,GAAGC,YAAO,CAAC,OAAO,CAAC,GAAG,IAAIC,WAAG,EAAE,EAAE,OAAO,CAAC,CAAC;AAClH,gBAAgB,IAAI;AACpB,oBAAoB,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;AACrD,oBAAoB,OAAO,IAAI,CAAC;AAChC,iBAAiB;AACjB,gBAAgB,OAAO,EAAE,EAAE;AAC3B,oBAAoB,OAAO,KAAK,CAAC;AACjC,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE;AAClC,QAAQ,IAAIH,iBAAW,CAAC,OAAO,CAAC,EAAE;AAClC,YAAY,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,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AC,CAAC;AAC1G,QAAQ,IAAI;AACZ,YAAY,MAAM,WAAW,GAAGG,eAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AACzE,YAAY,OAAOD,sBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACnE,SAAS;AACT,QAAQ,OAAO,CAAC,EAAE;AAClB,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,+BAA+B,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,SAAS;AACT,KAAK;AACL;;;;"}
|
package/index.esm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isValidPath, parseGraphQLJSON } from '@graphql-tools/utils';
|
|
2
2
|
import { isAbsolute, resolve } from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { accessSync, readFileSync, promises } from 'fs';
|
|
4
4
|
import { cwd } from 'process';
|
|
5
5
|
|
|
6
|
+
const { readFile, access } = promises;
|
|
6
7
|
const FILE_EXTENSIONS = ['.json'];
|
|
7
8
|
/**
|
|
8
9
|
* This loader loads documents and type definitions from JSON files.
|
|
@@ -35,7 +36,13 @@ class JsonFileLoader {
|
|
|
35
36
|
if (isValidPath(pointer)) {
|
|
36
37
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
37
38
|
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);
|
|
38
|
-
|
|
39
|
+
try {
|
|
40
|
+
await access(normalizedFilePath);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
return false;
|
|
@@ -44,7 +51,13 @@ class JsonFileLoader {
|
|
|
44
51
|
if (isValidPath(pointer)) {
|
|
45
52
|
if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
|
|
46
53
|
const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);
|
|
47
|
-
|
|
54
|
+
try {
|
|
55
|
+
accessSync(normalizedFilePath);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (_a) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
return false;
|
package/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../../dist/loaders/json-file/src/index.js"],"sourcesContent":["import { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport {
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../../dist/loaders/json-file/src/index.js"],"sourcesContent":["import { parseGraphQLJSON, isValidPath, } from '@graphql-tools/utils';\nimport { isAbsolute, resolve } from 'path';\nimport { readFileSync, accessSync, promises as fsPromises } from 'fs';\nimport { cwd } from 'process';\nconst { readFile, access } = fsPromises;\nconst FILE_EXTENSIONS = ['.json'];\n/**\n * This loader loads documents and type definitions from JSON files.\n *\n * The JSON file can be the result of an introspection query made against a schema:\n *\n * ```js\n * const schema = await loadSchema('schema-introspection.json', {\n * loaders: [\n * new JsonFileLoader()\n * ]\n * });\n * ```\n *\n * Or it can be a `DocumentNode` object representing a GraphQL document or type definitions:\n *\n * ```js\n * const documents = await loadDocuments('queries/*.json', {\n * loaders: [\n * new GraphQLFileLoader()\n * ]\n * });\n * ```\n */\nexport class JsonFileLoader {\n loaderId() {\n return 'json-file';\n }\n async canLoad(pointer, options) {\n if (isValidPath(pointer)) {\n if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {\n const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n await access(normalizedFilePath);\n return true;\n }\n catch (_a) {\n return false;\n }\n }\n }\n return false;\n }\n canLoadSync(pointer, options) {\n if (isValidPath(pointer)) {\n if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {\n const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n accessSync(normalizedFilePath);\n return true;\n }\n catch (_a) {\n return false;\n }\n }\n }\n return false;\n }\n async load(pointer, options) {\n const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n const jsonContent = await readFile(normalizedFilePath, { encoding: 'utf8' });\n return parseGraphQLJSON(pointer, jsonContent, options);\n }\n catch (e) {\n throw new Error(`Unable to read JSON file: ${normalizedFilePath}: ${e.message || /* istanbul ignore next */ e}`);\n }\n }\n loadSync(pointer, options) {\n const normalizedFilepath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);\n try {\n const jsonContent = readFileSync(normalizedFilepath, 'utf8');\n return parseGraphQLJSON(pointer, jsonContent, options);\n }\n catch (e) {\n throw new Error(`Unable to read JSON file: ${normalizedFilepath}: ${e.message || /* istanbul ignore next */ e}`);\n }\n }\n}\n//# sourceMappingURL=index.js.map"],"names":["fsPromises"],"mappings":";;;;;AAIA,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAGA,QAAU,CAAC;AACxC,MAAM,eAAe,GAAG,CAAC,OAAO,CAAC,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,cAAc,CAAC;AAC5B,IAAI,QAAQ,GAAG;AACf,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE;AACpC,QAAQ,IAAI,WAAW,CAAC,OAAO,CAAC,EAAE;AAClC,YAAY,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,E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C1G,QAAQ,IAAI;AACZ,YAAY,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,kBAAkB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AACzF,YAAY,OAAO,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACnE,SAAS;AACT,QAAQ,OAAO,CAAC,EAAE;AAClB,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,+BAA+B,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,SAAS;AACT,KAAK;AACL,IAAI,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE;AAC/B,QAAQ,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;AAC1G,QAAQ,IAAI;AACZ,YAAY,MAAM,WAAW,GAAG,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AACzE,YAAY,OAAO,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AACnE,SAAS;AACT,QAAQ,OAAO,CAAC,EAAE;AAClB,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,+BAA+B,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7H,SAAS;AACT,KAAK;AACL;;;;"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/json-file-loader",
|
|
3
|
-
"version": "6.2.6
|
|
3
|
+
"version": "6.2.6",
|
|
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"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "7.0.
|
|
11
|
-
"fs-extra": "9.0.1",
|
|
10
|
+
"@graphql-tools/utils": "^7.0.0",
|
|
12
11
|
"tslib": "~2.0.1"
|
|
13
12
|
},
|
|
14
13
|
"repository": "git@github.com:ardatan/graphql-tools.git",
|