@graphql-tools/utils 8.9.1 → 8.10.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/extractExtensionsFromSchema.js +63 -0
- package/cjs/index.js +1 -0
- package/esm/extractExtensionsFromSchema.js +59 -0
- package/esm/index.js +1 -0
- package/package.json +1 -1
- package/typings/extractExtensionsFromSchema.d.cts +3 -0
- package/typings/extractExtensionsFromSchema.d.ts +3 -0
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractExtensionsFromSchema = void 0;
|
|
4
|
+
const mapSchema_js_1 = require("./mapSchema.js");
|
|
5
|
+
const Interfaces_js_1 = require("./Interfaces.js");
|
|
6
|
+
function extractExtensionsFromSchema(schema) {
|
|
7
|
+
const result = {
|
|
8
|
+
schemaExtensions: schema.extensions || {},
|
|
9
|
+
types: {},
|
|
10
|
+
};
|
|
11
|
+
(0, mapSchema_js_1.mapSchema)(schema, {
|
|
12
|
+
[Interfaces_js_1.MapperKind.OBJECT_TYPE]: type => {
|
|
13
|
+
result.types[type.name] = { fields: {}, type: 'object', extensions: type.extensions || {} };
|
|
14
|
+
return type;
|
|
15
|
+
},
|
|
16
|
+
[Interfaces_js_1.MapperKind.INTERFACE_TYPE]: type => {
|
|
17
|
+
result.types[type.name] = { fields: {}, type: 'interface', extensions: type.extensions || {} };
|
|
18
|
+
return type;
|
|
19
|
+
},
|
|
20
|
+
[Interfaces_js_1.MapperKind.FIELD]: (field, fieldName, typeName) => {
|
|
21
|
+
result.types[typeName].fields[fieldName] = {
|
|
22
|
+
arguments: {},
|
|
23
|
+
extensions: field.extensions || {},
|
|
24
|
+
};
|
|
25
|
+
const args = field.args;
|
|
26
|
+
if (args != null) {
|
|
27
|
+
for (const argName in args) {
|
|
28
|
+
result.types[typeName].fields[fieldName].arguments[argName] =
|
|
29
|
+
args[argName].extensions || {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return field;
|
|
33
|
+
},
|
|
34
|
+
[Interfaces_js_1.MapperKind.ENUM_TYPE]: type => {
|
|
35
|
+
result.types[type.name] = { values: {}, type: 'enum', extensions: type.extensions || {} };
|
|
36
|
+
return type;
|
|
37
|
+
},
|
|
38
|
+
[Interfaces_js_1.MapperKind.ENUM_VALUE]: (value, typeName, _schema, valueName) => {
|
|
39
|
+
result.types[typeName].values[valueName] = value.extensions || {};
|
|
40
|
+
return value;
|
|
41
|
+
},
|
|
42
|
+
[Interfaces_js_1.MapperKind.SCALAR_TYPE]: type => {
|
|
43
|
+
result.types[type.name] = { type: 'scalar', extensions: type.extensions || {} };
|
|
44
|
+
return type;
|
|
45
|
+
},
|
|
46
|
+
[Interfaces_js_1.MapperKind.UNION_TYPE]: type => {
|
|
47
|
+
result.types[type.name] = { type: 'union', extensions: type.extensions || {} };
|
|
48
|
+
return type;
|
|
49
|
+
},
|
|
50
|
+
[Interfaces_js_1.MapperKind.INPUT_OBJECT_TYPE]: type => {
|
|
51
|
+
result.types[type.name] = { fields: {}, type: 'input', extensions: type.extensions || {} };
|
|
52
|
+
return type;
|
|
53
|
+
},
|
|
54
|
+
[Interfaces_js_1.MapperKind.INPUT_OBJECT_FIELD]: (field, fieldName, typeName) => {
|
|
55
|
+
result.types[typeName].fields[fieldName] = {
|
|
56
|
+
extensions: field.extensions || {},
|
|
57
|
+
};
|
|
58
|
+
return field;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
exports.extractExtensionsFromSchema = extractExtensionsFromSchema;
|
package/cjs/index.js
CHANGED
|
@@ -51,3 +51,4 @@ tslib_1.__exportStar(require("./inspect.js"), exports);
|
|
|
51
51
|
tslib_1.__exportStar(require("./memoize.js"), exports);
|
|
52
52
|
tslib_1.__exportStar(require("./fixSchemaAst.js"), exports);
|
|
53
53
|
tslib_1.__exportStar(require("./getOperationASTFromRequest.js"), exports);
|
|
54
|
+
tslib_1.__exportStar(require("./extractExtensionsFromSchema.js"), exports);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { mapSchema } from './mapSchema.js';
|
|
2
|
+
import { MapperKind } from './Interfaces.js';
|
|
3
|
+
export function extractExtensionsFromSchema(schema) {
|
|
4
|
+
const result = {
|
|
5
|
+
schemaExtensions: schema.extensions || {},
|
|
6
|
+
types: {},
|
|
7
|
+
};
|
|
8
|
+
mapSchema(schema, {
|
|
9
|
+
[MapperKind.OBJECT_TYPE]: type => {
|
|
10
|
+
result.types[type.name] = { fields: {}, type: 'object', extensions: type.extensions || {} };
|
|
11
|
+
return type;
|
|
12
|
+
},
|
|
13
|
+
[MapperKind.INTERFACE_TYPE]: type => {
|
|
14
|
+
result.types[type.name] = { fields: {}, type: 'interface', extensions: type.extensions || {} };
|
|
15
|
+
return type;
|
|
16
|
+
},
|
|
17
|
+
[MapperKind.FIELD]: (field, fieldName, typeName) => {
|
|
18
|
+
result.types[typeName].fields[fieldName] = {
|
|
19
|
+
arguments: {},
|
|
20
|
+
extensions: field.extensions || {},
|
|
21
|
+
};
|
|
22
|
+
const args = field.args;
|
|
23
|
+
if (args != null) {
|
|
24
|
+
for (const argName in args) {
|
|
25
|
+
result.types[typeName].fields[fieldName].arguments[argName] =
|
|
26
|
+
args[argName].extensions || {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return field;
|
|
30
|
+
},
|
|
31
|
+
[MapperKind.ENUM_TYPE]: type => {
|
|
32
|
+
result.types[type.name] = { values: {}, type: 'enum', extensions: type.extensions || {} };
|
|
33
|
+
return type;
|
|
34
|
+
},
|
|
35
|
+
[MapperKind.ENUM_VALUE]: (value, typeName, _schema, valueName) => {
|
|
36
|
+
result.types[typeName].values[valueName] = value.extensions || {};
|
|
37
|
+
return value;
|
|
38
|
+
},
|
|
39
|
+
[MapperKind.SCALAR_TYPE]: type => {
|
|
40
|
+
result.types[type.name] = { type: 'scalar', extensions: type.extensions || {} };
|
|
41
|
+
return type;
|
|
42
|
+
},
|
|
43
|
+
[MapperKind.UNION_TYPE]: type => {
|
|
44
|
+
result.types[type.name] = { type: 'union', extensions: type.extensions || {} };
|
|
45
|
+
return type;
|
|
46
|
+
},
|
|
47
|
+
[MapperKind.INPUT_OBJECT_TYPE]: type => {
|
|
48
|
+
result.types[type.name] = { fields: {}, type: 'input', extensions: type.extensions || {} };
|
|
49
|
+
return type;
|
|
50
|
+
},
|
|
51
|
+
[MapperKind.INPUT_OBJECT_FIELD]: (field, fieldName, typeName) => {
|
|
52
|
+
result.types[typeName].fields[fieldName] = {
|
|
53
|
+
extensions: field.extensions || {},
|
|
54
|
+
};
|
|
55
|
+
return field;
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED