@graphql-tools/utils 10.6.0 → 10.6.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/cjs/helpers.js +17 -2
- package/esm/helpers.js +17 -2
- package/package.json +1 -1
package/cjs/helpers.js
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertSome = exports.isSome = exports.compareNodes = exports.nodeToString = exports.compareStrings = exports.isValidPath = exports.isDocumentString = exports.asArray = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
+
function isURL(str) {
|
|
6
|
+
try {
|
|
7
|
+
const url = new URL(str);
|
|
8
|
+
return !!url;
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
5
14
|
const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
|
|
6
15
|
exports.asArray = asArray;
|
|
7
16
|
const invalidDocRegex = /\.[a-z0-9]+$/i;
|
|
@@ -14,14 +23,20 @@ function isDocumentString(str) {
|
|
|
14
23
|
// this why checking the extension is fast enough
|
|
15
24
|
// and prevent from parsing the string in order to find out
|
|
16
25
|
// if the string is a SDL
|
|
17
|
-
if (invalidDocRegex.test(str)) {
|
|
26
|
+
if (invalidDocRegex.test(str) || isURL(str)) {
|
|
18
27
|
return false;
|
|
19
28
|
}
|
|
20
29
|
try {
|
|
21
30
|
(0, graphql_1.parse)(str);
|
|
22
31
|
return true;
|
|
23
32
|
}
|
|
24
|
-
catch (e) {
|
|
33
|
+
catch (e) {
|
|
34
|
+
if (!e.message.includes('EOF') &&
|
|
35
|
+
str.replace(/(\#[^*]*)/g, '').trim() !== '' &&
|
|
36
|
+
str.includes(' ')) {
|
|
37
|
+
throw new Error(`Failed to parse the GraphQL document. ${e.message}\n${str}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
25
40
|
return false;
|
|
26
41
|
}
|
|
27
42
|
exports.isDocumentString = isDocumentString;
|
package/esm/helpers.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { parse } from 'graphql';
|
|
2
|
+
function isURL(str) {
|
|
3
|
+
try {
|
|
4
|
+
const url = new URL(str);
|
|
5
|
+
return !!url;
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
2
11
|
export const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
|
|
3
12
|
const invalidDocRegex = /\.[a-z0-9]+$/i;
|
|
4
13
|
export function isDocumentString(str) {
|
|
@@ -10,14 +19,20 @@ export function isDocumentString(str) {
|
|
|
10
19
|
// this why checking the extension is fast enough
|
|
11
20
|
// and prevent from parsing the string in order to find out
|
|
12
21
|
// if the string is a SDL
|
|
13
|
-
if (invalidDocRegex.test(str)) {
|
|
22
|
+
if (invalidDocRegex.test(str) || isURL(str)) {
|
|
14
23
|
return false;
|
|
15
24
|
}
|
|
16
25
|
try {
|
|
17
26
|
parse(str);
|
|
18
27
|
return true;
|
|
19
28
|
}
|
|
20
|
-
catch (e) {
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (!e.message.includes('EOF') &&
|
|
31
|
+
str.replace(/(\#[^*]*)/g, '').trim() !== '' &&
|
|
32
|
+
str.includes(' ')) {
|
|
33
|
+
throw new Error(`Failed to parse the GraphQL document. ${e.message}\n${str}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
21
36
|
return false;
|
|
22
37
|
}
|
|
23
38
|
const invalidPathRegex = /[‘“!%^<>`\n]/;
|