@graphql-mesh/utils 1.0.0-alpha-20230523154231-8c60b52d9 → 1.0.0-alpha-20230523154841-376b13623
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/apply-transforms.js +2 -2
- package/cjs/fileURLToPath.js +1 -1
- package/cjs/group-transforms.js +1 -1
- package/cjs/load-from-module-export-expression.js +1 -1
- package/cjs/logger.js +1 -1
- package/cjs/read-file-or-url.js +3 -4
- package/cjs/resolve-additional-resolvers.js +2 -2
- package/cjs/sanitize-name-for-graphql.js +1 -1
- package/esm/apply-transforms.js +2 -2
- package/esm/fileURLToPath.js +1 -1
- package/esm/group-transforms.js +1 -1
- package/esm/load-from-module-export-expression.js +1 -1
- package/esm/logger.js +1 -1
- package/esm/read-file-or-url.js +3 -4
- package/esm/resolve-additional-resolvers.js +2 -2
- package/esm/sanitize-name-for-graphql.js +1 -1
- package/package.json +7 -4
package/cjs/apply-transforms.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyResultTransforms = exports.applyRequestTransforms = exports.applySchemaTransforms = void 0;
|
|
4
4
|
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, transforms) {
|
|
5
|
-
if (transforms
|
|
5
|
+
if (transforms?.length) {
|
|
6
6
|
return transforms.reduce((schema, transform) => 'transformSchema' in transform
|
|
7
7
|
? transform.transformSchema(schema, subschemaConfig)
|
|
8
8
|
: schema, originalWrappingSchema);
|
|
@@ -13,7 +13,7 @@ exports.applySchemaTransforms = applySchemaTransforms;
|
|
|
13
13
|
function applyRequestTransforms(originalRequest, delegationContext, transformationContext, transforms) {
|
|
14
14
|
transformationContext.contextMap = transformationContext.contextMap || new WeakMap();
|
|
15
15
|
const contextMap = transformationContext.contextMap;
|
|
16
|
-
transforms
|
|
16
|
+
transforms?.forEach(transform => {
|
|
17
17
|
if (!contextMap.has(transform)) {
|
|
18
18
|
contextMap.set(transform, {
|
|
19
19
|
nextIndex: 0,
|
package/cjs/fileURLToPath.js
CHANGED
|
@@ -42,7 +42,7 @@ function fileUriToPath(uri) {
|
|
|
42
42
|
return host + path;
|
|
43
43
|
}
|
|
44
44
|
function fileURLToPath(url) {
|
|
45
|
-
if (url
|
|
45
|
+
if (url?.startsWith('file://')) {
|
|
46
46
|
return fileUriToPath(url);
|
|
47
47
|
}
|
|
48
48
|
return url || '';
|
package/cjs/group-transforms.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.groupTransforms = void 0;
|
|
|
4
4
|
function groupTransforms(transforms) {
|
|
5
5
|
const wrapTransforms = [];
|
|
6
6
|
const noWrapTransforms = [];
|
|
7
|
-
transforms
|
|
7
|
+
transforms?.forEach(transform => {
|
|
8
8
|
if (transform.noWrap) {
|
|
9
9
|
noWrapTransforms.push(transform);
|
|
10
10
|
}
|
|
@@ -18,7 +18,7 @@ async function tryImport(modulePath, cwd, importFn) {
|
|
|
18
18
|
try {
|
|
19
19
|
return await importFn(modulePath);
|
|
20
20
|
}
|
|
21
|
-
catch
|
|
21
|
+
catch {
|
|
22
22
|
if (!cross_helpers_1.path.isAbsolute(modulePath)) {
|
|
23
23
|
const absoluteModulePath = cross_helpers_1.path.isAbsolute(modulePath)
|
|
24
24
|
? modulePath
|
package/cjs/logger.js
CHANGED
|
@@ -41,7 +41,7 @@ class DefaultLogger {
|
|
|
41
41
|
}
|
|
42
42
|
return arg;
|
|
43
43
|
}
|
|
44
|
-
else if (typeof arg === 'object' &&
|
|
44
|
+
else if (typeof arg === 'object' && arg?.stack != null) {
|
|
45
45
|
return arg.stack;
|
|
46
46
|
}
|
|
47
47
|
return cross_helpers_1.util.inspect(arg);
|
package/cjs/read-file-or-url.js
CHANGED
|
@@ -104,13 +104,12 @@ async function readFile(fileExpression, { allowUnknownExtensions, cwd, fallbackF
|
|
|
104
104
|
}
|
|
105
105
|
exports.readFile = readFile;
|
|
106
106
|
async function readUrl(path, config) {
|
|
107
|
-
var _a, _b;
|
|
108
107
|
const { allowUnknownExtensions, fallbackFormat } = config || {};
|
|
109
108
|
config.headers = config.headers || {};
|
|
110
109
|
const response = await config.fetch(path, config);
|
|
111
|
-
const contentType =
|
|
110
|
+
const contentType = response.headers?.get('content-type') || '';
|
|
112
111
|
const responseText = await response.text();
|
|
113
|
-
|
|
112
|
+
config?.logger?.debug(`${path} returned `, responseText);
|
|
114
113
|
if (/json$/.test(path) ||
|
|
115
114
|
contentType.startsWith('application/json') ||
|
|
116
115
|
fallbackFormat === 'json') {
|
|
@@ -121,7 +120,7 @@ async function readUrl(path, config) {
|
|
|
121
120
|
contentType.includes('yaml') ||
|
|
122
121
|
contentType.includes('yml') ||
|
|
123
122
|
fallbackFormat === 'yaml') {
|
|
124
|
-
return loadYaml(path, responseText, config
|
|
123
|
+
return loadYaml(path, responseText, config?.logger);
|
|
125
124
|
}
|
|
126
125
|
else if (!allowUnknownExtensions) {
|
|
127
126
|
throw new Error(`Failed to parse JSON/YAML. Ensure URL '${path}' has ` +
|
|
@@ -28,7 +28,7 @@ function getTypeByPath(type, path) {
|
|
|
28
28
|
return getTypeByPath(type, path.slice(1));
|
|
29
29
|
}
|
|
30
30
|
const field = fieldMap[currentFieldName];
|
|
31
|
-
if (!
|
|
31
|
+
if (!field?.type) {
|
|
32
32
|
throw new Error(`${type}.${currentFieldName} is not a valid field.`);
|
|
33
33
|
}
|
|
34
34
|
return getTypeByPath(field.type, path.slice(1));
|
|
@@ -54,7 +54,7 @@ function generateSelectionSetFactory(schema, additionalResolver) {
|
|
|
54
54
|
const targetTypeFields = targetType.getFields();
|
|
55
55
|
const targetField = targetTypeFields[additionalResolver.targetFieldName];
|
|
56
56
|
const targetFieldType = (0, graphql_1.getNamedType)(targetField.type);
|
|
57
|
-
abstractResultTypeName = targetFieldType
|
|
57
|
+
abstractResultTypeName = targetFieldType?.name;
|
|
58
58
|
}
|
|
59
59
|
if (abstractResultTypeName !== resultFieldType.name) {
|
|
60
60
|
const abstractResultType = schema.getType(abstractResultTypeName);
|
|
@@ -43,7 +43,7 @@ function removeClosedBrackets(val) {
|
|
|
43
43
|
for (;;) {
|
|
44
44
|
// finds the first and shortest closed bracket match, starting from the left
|
|
45
45
|
const match = out.match(/\(.+?\)/);
|
|
46
|
-
const yesbrack = match
|
|
46
|
+
const yesbrack = match?.[0];
|
|
47
47
|
if (!yesbrack) {
|
|
48
48
|
break;
|
|
49
49
|
}
|
package/esm/apply-transforms.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema, transforms) {
|
|
2
|
-
if (transforms
|
|
2
|
+
if (transforms?.length) {
|
|
3
3
|
return transforms.reduce((schema, transform) => 'transformSchema' in transform
|
|
4
4
|
? transform.transformSchema(schema, subschemaConfig)
|
|
5
5
|
: schema, originalWrappingSchema);
|
|
@@ -9,7 +9,7 @@ export function applySchemaTransforms(originalWrappingSchema, subschemaConfig, t
|
|
|
9
9
|
export function applyRequestTransforms(originalRequest, delegationContext, transformationContext, transforms) {
|
|
10
10
|
transformationContext.contextMap = transformationContext.contextMap || new WeakMap();
|
|
11
11
|
const contextMap = transformationContext.contextMap;
|
|
12
|
-
transforms
|
|
12
|
+
transforms?.forEach(transform => {
|
|
13
13
|
if (!contextMap.has(transform)) {
|
|
14
14
|
contextMap.set(transform, {
|
|
15
15
|
nextIndex: 0,
|
package/esm/fileURLToPath.js
CHANGED
|
@@ -39,7 +39,7 @@ function fileUriToPath(uri) {
|
|
|
39
39
|
return host + path;
|
|
40
40
|
}
|
|
41
41
|
export function fileURLToPath(url) {
|
|
42
|
-
if (url
|
|
42
|
+
if (url?.startsWith('file://')) {
|
|
43
43
|
return fileUriToPath(url);
|
|
44
44
|
}
|
|
45
45
|
return url || '';
|
package/esm/group-transforms.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function groupTransforms(transforms) {
|
|
2
2
|
const wrapTransforms = [];
|
|
3
3
|
const noWrapTransforms = [];
|
|
4
|
-
transforms
|
|
4
|
+
transforms?.forEach(transform => {
|
|
5
5
|
if (transform.noWrap) {
|
|
6
6
|
noWrapTransforms.push(transform);
|
|
7
7
|
}
|
package/esm/logger.js
CHANGED
|
@@ -33,7 +33,7 @@ export class DefaultLogger {
|
|
|
33
33
|
}
|
|
34
34
|
return arg;
|
|
35
35
|
}
|
|
36
|
-
else if (typeof arg === 'object' &&
|
|
36
|
+
else if (typeof arg === 'object' && arg?.stack != null) {
|
|
37
37
|
return arg.stack;
|
|
38
38
|
}
|
|
39
39
|
return util.inspect(arg);
|
package/esm/read-file-or-url.js
CHANGED
|
@@ -97,13 +97,12 @@ export async function readFile(fileExpression, { allowUnknownExtensions, cwd, fa
|
|
|
97
97
|
return rawResult;
|
|
98
98
|
}
|
|
99
99
|
export async function readUrl(path, config) {
|
|
100
|
-
var _a, _b;
|
|
101
100
|
const { allowUnknownExtensions, fallbackFormat } = config || {};
|
|
102
101
|
config.headers = config.headers || {};
|
|
103
102
|
const response = await config.fetch(path, config);
|
|
104
|
-
const contentType =
|
|
103
|
+
const contentType = response.headers?.get('content-type') || '';
|
|
105
104
|
const responseText = await response.text();
|
|
106
|
-
|
|
105
|
+
config?.logger?.debug(`${path} returned `, responseText);
|
|
107
106
|
if (/json$/.test(path) ||
|
|
108
107
|
contentType.startsWith('application/json') ||
|
|
109
108
|
fallbackFormat === 'json') {
|
|
@@ -114,7 +113,7 @@ export async function readUrl(path, config) {
|
|
|
114
113
|
contentType.includes('yaml') ||
|
|
115
114
|
contentType.includes('yml') ||
|
|
116
115
|
fallbackFormat === 'yaml') {
|
|
117
|
-
return loadYaml(path, responseText, config
|
|
116
|
+
return loadYaml(path, responseText, config?.logger);
|
|
118
117
|
}
|
|
119
118
|
else if (!allowUnknownExtensions) {
|
|
120
119
|
throw new Error(`Failed to parse JSON/YAML. Ensure URL '${path}' has ` +
|
|
@@ -24,7 +24,7 @@ function getTypeByPath(type, path) {
|
|
|
24
24
|
return getTypeByPath(type, path.slice(1));
|
|
25
25
|
}
|
|
26
26
|
const field = fieldMap[currentFieldName];
|
|
27
|
-
if (!
|
|
27
|
+
if (!field?.type) {
|
|
28
28
|
throw new Error(`${type}.${currentFieldName} is not a valid field.`);
|
|
29
29
|
}
|
|
30
30
|
return getTypeByPath(field.type, path.slice(1));
|
|
@@ -50,7 +50,7 @@ function generateSelectionSetFactory(schema, additionalResolver) {
|
|
|
50
50
|
const targetTypeFields = targetType.getFields();
|
|
51
51
|
const targetField = targetTypeFields[additionalResolver.targetFieldName];
|
|
52
52
|
const targetFieldType = getNamedType(targetField.type);
|
|
53
|
-
abstractResultTypeName = targetFieldType
|
|
53
|
+
abstractResultTypeName = targetFieldType?.name;
|
|
54
54
|
}
|
|
55
55
|
if (abstractResultTypeName !== resultFieldType.name) {
|
|
56
56
|
const abstractResultType = schema.getType(abstractResultTypeName);
|
|
@@ -40,7 +40,7 @@ export function removeClosedBrackets(val) {
|
|
|
40
40
|
for (;;) {
|
|
41
41
|
// finds the first and shortest closed bracket match, starting from the left
|
|
42
42
|
const match = out.match(/\(.+?\)/);
|
|
43
|
-
const yesbrack = match
|
|
43
|
+
const yesbrack = match?.[0];
|
|
44
44
|
if (!yesbrack) {
|
|
45
45
|
break;
|
|
46
46
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/utils",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230523154841-376b13623",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "0.4.0-alpha-
|
|
7
|
-
"@graphql-mesh/types": "1.0.0-alpha-
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230523154841-376b13623",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230523154841-376b13623",
|
|
8
8
|
"@graphql-tools/utils": "^9.2.1 || ^10.0.0",
|
|
9
9
|
"graphql": "*",
|
|
10
10
|
"tslib": "^2.4.0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@graphql-mesh/string-interpolation": "0.5.0-alpha-
|
|
13
|
+
"@graphql-mesh/string-interpolation": "0.5.0-alpha-20230523154841-376b13623",
|
|
14
14
|
"@graphql-tools/delegate": "^10.0.0",
|
|
15
15
|
"dset": "^3.1.2",
|
|
16
16
|
"js-yaml": "^4.1.0",
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"directory": "packages/utils"
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=16.0.0"
|
|
29
|
+
},
|
|
27
30
|
"main": "cjs/index.js",
|
|
28
31
|
"module": "esm/index.js",
|
|
29
32
|
"typings": "typings/index.d.ts",
|