1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getResolversFromSchema = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | function getResolversFromSchema(schema,
|
6 | // Include default merged resolvers
|
7 | includeDefaultMergedResolver) {
|
8 | var _a, _b;
|
9 | const resolvers = Object.create(null);
|
10 | const typeMap = schema.getTypeMap();
|
11 | for (const typeName in typeMap) {
|
12 | if (!typeName.startsWith('__')) {
|
13 | const type = typeMap[typeName];
|
14 | if ((0, graphql_1.isScalarType)(type)) {
|
15 | if (!(0, graphql_1.isSpecifiedScalarType)(type)) {
|
16 | const config = type.toConfig();
|
17 | delete config.astNode;
|
18 | resolvers[typeName] = new graphql_1.GraphQLScalarType(config);
|
19 | }
|
20 | }
|
21 | else if ((0, graphql_1.isEnumType)(type)) {
|
22 | resolvers[typeName] = {};
|
23 | const values = type.getValues();
|
24 | for (const value of values) {
|
25 | resolvers[typeName][value.name] = value.value;
|
26 | }
|
27 | }
|
28 | else if ((0, graphql_1.isInterfaceType)(type)) {
|
29 | if (type.resolveType != null) {
|
30 | resolvers[typeName] = {
|
31 | __resolveType: type.resolveType,
|
32 | };
|
33 | }
|
34 | }
|
35 | else if ((0, graphql_1.isUnionType)(type)) {
|
36 | if (type.resolveType != null) {
|
37 | resolvers[typeName] = {
|
38 | __resolveType: type.resolveType,
|
39 | };
|
40 | }
|
41 | }
|
42 | else if ((0, graphql_1.isObjectType)(type)) {
|
43 | resolvers[typeName] = {};
|
44 | if (type.isTypeOf != null) {
|
45 | resolvers[typeName].__isTypeOf = type.isTypeOf;
|
46 | }
|
47 | const fields = type.getFields();
|
48 | for (const fieldName in fields) {
|
49 | const field = fields[fieldName];
|
50 | if (field.subscribe != null) {
|
51 | resolvers[typeName][fieldName] = resolvers[typeName][fieldName] || {};
|
52 | resolvers[typeName][fieldName].subscribe = field.subscribe;
|
53 | }
|
54 | if (field.resolve != null && ((_a = field.resolve) === null || _a === void 0 ? void 0 : _a.name) !== 'defaultFieldResolver') {
|
55 | switch ((_b = field.resolve) === null || _b === void 0 ? void 0 : _b.name) {
|
56 | case 'defaultMergedResolver':
|
57 | if (!includeDefaultMergedResolver) {
|
58 | continue;
|
59 | }
|
60 | break;
|
61 | case 'defaultFieldResolver':
|
62 | continue;
|
63 | }
|
64 | resolvers[typeName][fieldName] = resolvers[typeName][fieldName] || {};
|
65 | resolvers[typeName][fieldName].resolve = field.resolve;
|
66 | }
|
67 | }
|
68 | }
|
69 | }
|
70 | }
|
71 | return resolvers;
|
72 | }
|
73 | exports.getResolversFromSchema = getResolversFromSchema;
|