@graphql-mesh/mongoose 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/index.js +132 -0
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +47 -34
- package/package.json +26 -20
- package/typings/index.d.cts +11 -0
- package/typings/index.d.ts +11 -0
- package/index.d.ts +0 -9
- package/index.js +0 -118
package/cjs/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const graphql_1 = require("graphql");
|
|
4
|
+
const graphql_compose_1 = require("graphql-compose");
|
|
5
|
+
const graphql_compose_mongoose_1 = require("graphql-compose-mongoose");
|
|
6
|
+
const mongoose_1 = require("mongoose");
|
|
7
|
+
const utils_1 = require("@graphql-mesh/utils");
|
|
8
|
+
const modelQueryOperations = [
|
|
9
|
+
'findById',
|
|
10
|
+
'findByIds',
|
|
11
|
+
'findOne',
|
|
12
|
+
'findMany',
|
|
13
|
+
'count',
|
|
14
|
+
'connection',
|
|
15
|
+
'pagination',
|
|
16
|
+
'dataLoader',
|
|
17
|
+
'dataLoaderMany',
|
|
18
|
+
];
|
|
19
|
+
const modelMutationOperations = [
|
|
20
|
+
'createOne',
|
|
21
|
+
'createMany',
|
|
22
|
+
'updateById',
|
|
23
|
+
'updateOne',
|
|
24
|
+
'updateMany',
|
|
25
|
+
'removeById',
|
|
26
|
+
'removeOne',
|
|
27
|
+
'removeMany',
|
|
28
|
+
];
|
|
29
|
+
class MongooseHandler {
|
|
30
|
+
constructor({ name, config, baseDir, pubsub, importFn, logger, }) {
|
|
31
|
+
this.name = name;
|
|
32
|
+
this.config = config;
|
|
33
|
+
this.baseDir = baseDir;
|
|
34
|
+
this.pubsub = pubsub;
|
|
35
|
+
this.importFn = importFn;
|
|
36
|
+
this.logger = logger;
|
|
37
|
+
}
|
|
38
|
+
async getMeshSource() {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (this.config.connectionString) {
|
|
41
|
+
(0, mongoose_1.connect)(this.config.connectionString, {
|
|
42
|
+
useNewUrlParser: true,
|
|
43
|
+
useUnifiedTopology: true,
|
|
44
|
+
logger: {
|
|
45
|
+
className: this.name,
|
|
46
|
+
debug: this.logger.debug.bind(this.logger),
|
|
47
|
+
info: this.logger.info.bind(this.logger),
|
|
48
|
+
warn: this.logger.warn.bind(this.logger),
|
|
49
|
+
error: this.logger.error.bind(this.logger),
|
|
50
|
+
isDebug() {
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
isError() {
|
|
54
|
+
return true;
|
|
55
|
+
},
|
|
56
|
+
isInfo() {
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
isWarn() {
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
loggerLevel: 'debug',
|
|
64
|
+
}).catch(e => this.logger.error(e));
|
|
65
|
+
const id = this.pubsub.subscribe('destroy', () => {
|
|
66
|
+
(0, mongoose_1.disconnect)()
|
|
67
|
+
.catch(e => this.logger.error(e))
|
|
68
|
+
.finally(() => this.pubsub.unsubscribe(id));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const schemaComposer = new graphql_compose_1.SchemaComposer();
|
|
72
|
+
const typeMergingOptions = {};
|
|
73
|
+
await Promise.all([
|
|
74
|
+
Promise.all(((_a = this.config.models) === null || _a === void 0 ? void 0 : _a.map(async (modelConfig) => {
|
|
75
|
+
const model = await (0, utils_1.loadFromModuleExportExpression)(modelConfig.path, {
|
|
76
|
+
defaultExportName: modelConfig.name,
|
|
77
|
+
cwd: this.baseDir,
|
|
78
|
+
importFn: this.importFn,
|
|
79
|
+
});
|
|
80
|
+
if (!model) {
|
|
81
|
+
throw new Error(`Model ${modelConfig.name} cannot be imported ${modelConfig.path}!`);
|
|
82
|
+
}
|
|
83
|
+
const modelTC = (0, graphql_compose_mongoose_1.composeWithMongoose)(model, modelConfig.options);
|
|
84
|
+
await Promise.all([
|
|
85
|
+
Promise.all(modelQueryOperations.map(async (queryOperation) => schemaComposer.Query.addFields({
|
|
86
|
+
[`${modelConfig.name}_${queryOperation}`]: modelTC.getResolver(queryOperation),
|
|
87
|
+
}))),
|
|
88
|
+
Promise.all(modelMutationOperations.map(async (mutationOperation) => schemaComposer.Mutation.addFields({
|
|
89
|
+
[`${modelConfig.name}_${mutationOperation}`]: modelTC.getResolver(mutationOperation),
|
|
90
|
+
}))),
|
|
91
|
+
]);
|
|
92
|
+
const typeName = modelTC.getTypeName();
|
|
93
|
+
typeMergingOptions[typeName] = {
|
|
94
|
+
selectionSet: `{ id }`,
|
|
95
|
+
key: ({ id }) => id,
|
|
96
|
+
argsFromKeys: ids => ({ ids }),
|
|
97
|
+
fieldName: `${typeName}_dataLoaderMany`,
|
|
98
|
+
};
|
|
99
|
+
})) || []),
|
|
100
|
+
Promise.all(((_b = this.config.discriminators) === null || _b === void 0 ? void 0 : _b.map(async (discriminatorConfig) => {
|
|
101
|
+
const discriminator = await (0, utils_1.loadFromModuleExportExpression)(discriminatorConfig.path, {
|
|
102
|
+
defaultExportName: discriminatorConfig.name,
|
|
103
|
+
cwd: this.baseDir,
|
|
104
|
+
importFn: this.importFn,
|
|
105
|
+
});
|
|
106
|
+
const discriminatorTC = (0, graphql_compose_mongoose_1.composeWithMongooseDiscriminators)(discriminator, discriminatorConfig.options);
|
|
107
|
+
await Promise.all([
|
|
108
|
+
Promise.all(modelQueryOperations.map(async (queryOperation) => schemaComposer.Query.addFields({
|
|
109
|
+
[`${discriminatorConfig.name}_${queryOperation}`]: discriminatorTC.getResolver(queryOperation),
|
|
110
|
+
}))),
|
|
111
|
+
Promise.all(modelMutationOperations.map(async (mutationOperation) => schemaComposer.Mutation.addFields({
|
|
112
|
+
[`${discriminatorConfig.name}_${mutationOperation}`]: discriminatorTC.getResolver(mutationOperation),
|
|
113
|
+
}))),
|
|
114
|
+
]);
|
|
115
|
+
const typeName = discriminatorTC.getTypeName();
|
|
116
|
+
typeMergingOptions[typeName] = {
|
|
117
|
+
selectionSet: `{ id }`,
|
|
118
|
+
key: ({ id }) => id,
|
|
119
|
+
argsFromKeys: ids => ({ ids }),
|
|
120
|
+
fieldName: `${typeName}_dataLoaderMany`,
|
|
121
|
+
};
|
|
122
|
+
})) || []),
|
|
123
|
+
]);
|
|
124
|
+
// graphql-compose doesn't add @defer and @stream to the schema
|
|
125
|
+
graphql_1.specifiedDirectives.forEach(directive => schemaComposer.addDirective(directive));
|
|
126
|
+
const schema = schemaComposer.buildSchema();
|
|
127
|
+
return {
|
|
128
|
+
schema,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.default = MongooseHandler;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { specifiedDirectives } from 'graphql';
|
|
2
2
|
import { SchemaComposer } from 'graphql-compose';
|
|
3
|
+
import { composeWithMongoose, composeWithMongooseDiscriminators } from 'graphql-compose-mongoose';
|
|
3
4
|
import { connect, disconnect } from 'mongoose';
|
|
4
5
|
import { loadFromModuleExportExpression } from '@graphql-mesh/utils';
|
|
5
|
-
import { specifiedDirectives } from 'graphql';
|
|
6
|
-
import { stitchingDirectives } from '@graphql-tools/stitching-directives';
|
|
7
|
-
|
|
8
6
|
const modelQueryOperations = [
|
|
9
7
|
'findById',
|
|
10
8
|
'findByIds',
|
|
@@ -26,12 +24,14 @@ const modelMutationOperations = [
|
|
|
26
24
|
'removeOne',
|
|
27
25
|
'removeMany',
|
|
28
26
|
];
|
|
29
|
-
class MongooseHandler {
|
|
30
|
-
constructor({ config, baseDir, pubsub, importFn }) {
|
|
27
|
+
export default class MongooseHandler {
|
|
28
|
+
constructor({ name, config, baseDir, pubsub, importFn, logger, }) {
|
|
29
|
+
this.name = name;
|
|
31
30
|
this.config = config;
|
|
32
31
|
this.baseDir = baseDir;
|
|
33
32
|
this.pubsub = pubsub;
|
|
34
33
|
this.importFn = importFn;
|
|
34
|
+
this.logger = logger;
|
|
35
35
|
}
|
|
36
36
|
async getMeshSource() {
|
|
37
37
|
var _a, _b;
|
|
@@ -39,10 +39,35 @@ class MongooseHandler {
|
|
|
39
39
|
connect(this.config.connectionString, {
|
|
40
40
|
useNewUrlParser: true,
|
|
41
41
|
useUnifiedTopology: true,
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
logger: {
|
|
43
|
+
className: this.name,
|
|
44
|
+
debug: this.logger.debug.bind(this.logger),
|
|
45
|
+
info: this.logger.info.bind(this.logger),
|
|
46
|
+
warn: this.logger.warn.bind(this.logger),
|
|
47
|
+
error: this.logger.error.bind(this.logger),
|
|
48
|
+
isDebug() {
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
isError() {
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
isInfo() {
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
isWarn() {
|
|
58
|
+
return true;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
loggerLevel: 'debug',
|
|
62
|
+
}).catch(e => this.logger.error(e));
|
|
63
|
+
const id = this.pubsub.subscribe('destroy', () => {
|
|
64
|
+
disconnect()
|
|
65
|
+
.catch(e => this.logger.error(e))
|
|
66
|
+
.finally(() => this.pubsub.unsubscribe(id));
|
|
67
|
+
});
|
|
44
68
|
}
|
|
45
69
|
const schemaComposer = new SchemaComposer();
|
|
70
|
+
const typeMergingOptions = {};
|
|
46
71
|
await Promise.all([
|
|
47
72
|
Promise.all(((_a = this.config.models) === null || _a === void 0 ? void 0 : _a.map(async (modelConfig) => {
|
|
48
73
|
const model = await loadFromModuleExportExpression(modelConfig.path, {
|
|
@@ -62,16 +87,13 @@ class MongooseHandler {
|
|
|
62
87
|
[`${modelConfig.name}_${mutationOperation}`]: modelTC.getResolver(mutationOperation),
|
|
63
88
|
}))),
|
|
64
89
|
]);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
modelTC.setFieldDirectiveByName(`${modelConfig.name}_dataLoaderMany`, 'merge');
|
|
74
|
-
}
|
|
90
|
+
const typeName = modelTC.getTypeName();
|
|
91
|
+
typeMergingOptions[typeName] = {
|
|
92
|
+
selectionSet: `{ id }`,
|
|
93
|
+
key: ({ id }) => id,
|
|
94
|
+
argsFromKeys: ids => ({ ids }),
|
|
95
|
+
fieldName: `${typeName}_dataLoaderMany`,
|
|
96
|
+
};
|
|
75
97
|
})) || []),
|
|
76
98
|
Promise.all(((_b = this.config.discriminators) === null || _b === void 0 ? void 0 : _b.map(async (discriminatorConfig) => {
|
|
77
99
|
const discriminator = await loadFromModuleExportExpression(discriminatorConfig.path, {
|
|
@@ -88,29 +110,20 @@ class MongooseHandler {
|
|
|
88
110
|
[`${discriminatorConfig.name}_${mutationOperation}`]: discriminatorTC.getResolver(mutationOperation),
|
|
89
111
|
}))),
|
|
90
112
|
]);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
discriminatorTC.setFieldDirectiveByName(`${discriminatorConfig.name}_dataLoaderMany`, 'merge');
|
|
100
|
-
}
|
|
113
|
+
const typeName = discriminatorTC.getTypeName();
|
|
114
|
+
typeMergingOptions[typeName] = {
|
|
115
|
+
selectionSet: `{ id }`,
|
|
116
|
+
key: ({ id }) => id,
|
|
117
|
+
argsFromKeys: ids => ({ ids }),
|
|
118
|
+
fieldName: `${typeName}_dataLoaderMany`,
|
|
119
|
+
};
|
|
101
120
|
})) || []),
|
|
102
121
|
]);
|
|
103
122
|
// graphql-compose doesn't add @defer and @stream to the schema
|
|
104
123
|
specifiedDirectives.forEach(directive => schemaComposer.addDirective(directive));
|
|
105
|
-
if (this.config.autoTypeMerging) {
|
|
106
|
-
const defaultStitchingDirectives = stitchingDirectives();
|
|
107
|
-
defaultStitchingDirectives.allStitchingDirectives.forEach(directive => schemaComposer.addDirective(directive));
|
|
108
|
-
}
|
|
109
124
|
const schema = schemaComposer.buildSchema();
|
|
110
125
|
return {
|
|
111
126
|
schema,
|
|
112
127
|
};
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
|
-
|
|
116
|
-
export default MongooseHandler;
|
package/package.json
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/mongoose",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/types": "0.
|
|
7
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
6
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
7
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
8
|
"graphql": "*",
|
|
9
|
-
"mongoose": "*"
|
|
9
|
+
"mongoose": "*",
|
|
10
|
+
"tslib": "^2.4.0"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"
|
|
13
|
-
"graphql-compose": "9.0.8",
|
|
13
|
+
"graphql-compose": "9.0.10",
|
|
14
14
|
"graphql-compose-connection": "8.2.1",
|
|
15
|
-
"graphql-compose-mongoose": "9.
|
|
16
|
-
"graphql-compose-pagination": "8.3.0"
|
|
17
|
-
"tslib": "^2.4.0"
|
|
15
|
+
"graphql-compose-mongoose": "9.8.0",
|
|
16
|
+
"graphql-compose-pagination": "8.3.0"
|
|
18
17
|
},
|
|
19
18
|
"repository": {
|
|
20
19
|
"type": "git",
|
|
@@ -22,21 +21,28 @@
|
|
|
22
21
|
"directory": "packages/handlers/mongoose"
|
|
23
22
|
},
|
|
24
23
|
"license": "MIT",
|
|
25
|
-
"main": "index.js",
|
|
26
|
-
"module": "index.
|
|
27
|
-
"typings": "index.d.ts",
|
|
24
|
+
"main": "cjs/index.js",
|
|
25
|
+
"module": "esm/index.js",
|
|
26
|
+
"typings": "typings/index.d.ts",
|
|
28
27
|
"typescript": {
|
|
29
|
-
"definition": "index.d.ts"
|
|
28
|
+
"definition": "typings/index.d.ts"
|
|
30
29
|
},
|
|
30
|
+
"type": "module",
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
|
33
|
-
"require":
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./typings/index.d.cts",
|
|
35
|
+
"default": "./cjs/index.js"
|
|
36
|
+
},
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
},
|
|
41
|
+
"default": {
|
|
42
|
+
"types": "./typings/index.d.ts",
|
|
43
|
+
"default": "./esm/index.js"
|
|
44
|
+
}
|
|
39
45
|
},
|
|
40
46
|
"./package.json": "./package.json"
|
|
41
47
|
}
|
|
42
|
-
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
+
export default class MongooseHandler implements MeshHandler {
|
|
3
|
+
private config;
|
|
4
|
+
private baseDir;
|
|
5
|
+
private pubsub;
|
|
6
|
+
private importFn;
|
|
7
|
+
private logger;
|
|
8
|
+
private name;
|
|
9
|
+
constructor({ name, config, baseDir, pubsub, importFn, logger, }: MeshHandlerOptions<YamlConfig.MongooseHandler>);
|
|
10
|
+
getMeshSource(): Promise<MeshSource>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
+
export default class MongooseHandler implements MeshHandler {
|
|
3
|
+
private config;
|
|
4
|
+
private baseDir;
|
|
5
|
+
private pubsub;
|
|
6
|
+
private importFn;
|
|
7
|
+
private logger;
|
|
8
|
+
private name;
|
|
9
|
+
constructor({ name, config, baseDir, pubsub, importFn, logger, }: MeshHandlerOptions<YamlConfig.MongooseHandler>);
|
|
10
|
+
getMeshSource(): Promise<MeshSource>;
|
|
11
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { GetMeshSourceOptions, MeshHandler, MeshSource, YamlConfig } from '@graphql-mesh/types';
|
|
2
|
-
export default class MongooseHandler implements MeshHandler {
|
|
3
|
-
private config;
|
|
4
|
-
private baseDir;
|
|
5
|
-
private pubsub;
|
|
6
|
-
private importFn;
|
|
7
|
-
constructor({ config, baseDir, pubsub, importFn }: GetMeshSourceOptions<YamlConfig.MongooseHandler>);
|
|
8
|
-
getMeshSource(): Promise<MeshSource>;
|
|
9
|
-
}
|
package/index.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const graphqlComposeMongoose = require('graphql-compose-mongoose');
|
|
4
|
-
const graphqlCompose = require('graphql-compose');
|
|
5
|
-
const mongoose = require('mongoose');
|
|
6
|
-
const utils = require('@graphql-mesh/utils');
|
|
7
|
-
const graphql = require('graphql');
|
|
8
|
-
const stitchingDirectives = require('@graphql-tools/stitching-directives');
|
|
9
|
-
|
|
10
|
-
const modelQueryOperations = [
|
|
11
|
-
'findById',
|
|
12
|
-
'findByIds',
|
|
13
|
-
'findOne',
|
|
14
|
-
'findMany',
|
|
15
|
-
'count',
|
|
16
|
-
'connection',
|
|
17
|
-
'pagination',
|
|
18
|
-
'dataLoader',
|
|
19
|
-
'dataLoaderMany',
|
|
20
|
-
];
|
|
21
|
-
const modelMutationOperations = [
|
|
22
|
-
'createOne',
|
|
23
|
-
'createMany',
|
|
24
|
-
'updateById',
|
|
25
|
-
'updateOne',
|
|
26
|
-
'updateMany',
|
|
27
|
-
'removeById',
|
|
28
|
-
'removeOne',
|
|
29
|
-
'removeMany',
|
|
30
|
-
];
|
|
31
|
-
class MongooseHandler {
|
|
32
|
-
constructor({ config, baseDir, pubsub, importFn }) {
|
|
33
|
-
this.config = config;
|
|
34
|
-
this.baseDir = baseDir;
|
|
35
|
-
this.pubsub = pubsub;
|
|
36
|
-
this.importFn = importFn;
|
|
37
|
-
}
|
|
38
|
-
async getMeshSource() {
|
|
39
|
-
var _a, _b;
|
|
40
|
-
if (this.config.connectionString) {
|
|
41
|
-
mongoose.connect(this.config.connectionString, {
|
|
42
|
-
useNewUrlParser: true,
|
|
43
|
-
useUnifiedTopology: true,
|
|
44
|
-
}).catch(e => console.error(e));
|
|
45
|
-
await this.pubsub.subscribe('destroy', () => mongoose.disconnect());
|
|
46
|
-
}
|
|
47
|
-
const schemaComposer = new graphqlCompose.SchemaComposer();
|
|
48
|
-
await Promise.all([
|
|
49
|
-
Promise.all(((_a = this.config.models) === null || _a === void 0 ? void 0 : _a.map(async (modelConfig) => {
|
|
50
|
-
const model = await utils.loadFromModuleExportExpression(modelConfig.path, {
|
|
51
|
-
defaultExportName: modelConfig.name,
|
|
52
|
-
cwd: this.baseDir,
|
|
53
|
-
importFn: this.importFn,
|
|
54
|
-
});
|
|
55
|
-
if (!model) {
|
|
56
|
-
throw new Error(`Model ${modelConfig.name} cannot be imported ${modelConfig.path}!`);
|
|
57
|
-
}
|
|
58
|
-
const modelTC = graphqlComposeMongoose.composeWithMongoose(model, modelConfig.options);
|
|
59
|
-
await Promise.all([
|
|
60
|
-
Promise.all(modelQueryOperations.map(async (queryOperation) => schemaComposer.Query.addFields({
|
|
61
|
-
[`${modelConfig.name}_${queryOperation}`]: modelTC.getResolver(queryOperation),
|
|
62
|
-
}))),
|
|
63
|
-
Promise.all(modelMutationOperations.map(async (mutationOperation) => schemaComposer.Mutation.addFields({
|
|
64
|
-
[`${modelConfig.name}_${mutationOperation}`]: modelTC.getResolver(mutationOperation),
|
|
65
|
-
}))),
|
|
66
|
-
]);
|
|
67
|
-
if (this.config.autoTypeMerging) {
|
|
68
|
-
modelTC.setDirectiveByName('key', {
|
|
69
|
-
selectionSet: /* GraphQL */ `
|
|
70
|
-
{
|
|
71
|
-
id
|
|
72
|
-
}
|
|
73
|
-
`,
|
|
74
|
-
});
|
|
75
|
-
modelTC.setFieldDirectiveByName(`${modelConfig.name}_dataLoaderMany`, 'merge');
|
|
76
|
-
}
|
|
77
|
-
})) || []),
|
|
78
|
-
Promise.all(((_b = this.config.discriminators) === null || _b === void 0 ? void 0 : _b.map(async (discriminatorConfig) => {
|
|
79
|
-
const discriminator = await utils.loadFromModuleExportExpression(discriminatorConfig.path, {
|
|
80
|
-
defaultExportName: discriminatorConfig.name,
|
|
81
|
-
cwd: this.baseDir,
|
|
82
|
-
importFn: this.importFn,
|
|
83
|
-
});
|
|
84
|
-
const discriminatorTC = graphqlComposeMongoose.composeWithMongooseDiscriminators(discriminator, discriminatorConfig.options);
|
|
85
|
-
await Promise.all([
|
|
86
|
-
Promise.all(modelQueryOperations.map(async (queryOperation) => schemaComposer.Query.addFields({
|
|
87
|
-
[`${discriminatorConfig.name}_${queryOperation}`]: discriminatorTC.getResolver(queryOperation),
|
|
88
|
-
}))),
|
|
89
|
-
Promise.all(modelMutationOperations.map(async (mutationOperation) => schemaComposer.Mutation.addFields({
|
|
90
|
-
[`${discriminatorConfig.name}_${mutationOperation}`]: discriminatorTC.getResolver(mutationOperation),
|
|
91
|
-
}))),
|
|
92
|
-
]);
|
|
93
|
-
if (this.config.autoTypeMerging) {
|
|
94
|
-
discriminatorTC.setDirectiveByName('key', {
|
|
95
|
-
selectionSet: /* GraphQL */ `
|
|
96
|
-
{
|
|
97
|
-
id
|
|
98
|
-
}
|
|
99
|
-
`,
|
|
100
|
-
});
|
|
101
|
-
discriminatorTC.setFieldDirectiveByName(`${discriminatorConfig.name}_dataLoaderMany`, 'merge');
|
|
102
|
-
}
|
|
103
|
-
})) || []),
|
|
104
|
-
]);
|
|
105
|
-
// graphql-compose doesn't add @defer and @stream to the schema
|
|
106
|
-
graphql.specifiedDirectives.forEach(directive => schemaComposer.addDirective(directive));
|
|
107
|
-
if (this.config.autoTypeMerging) {
|
|
108
|
-
const defaultStitchingDirectives = stitchingDirectives.stitchingDirectives();
|
|
109
|
-
defaultStitchingDirectives.allStitchingDirectives.forEach(directive => schemaComposer.addDirective(directive));
|
|
110
|
-
}
|
|
111
|
-
const schema = schemaComposer.buildSchema();
|
|
112
|
-
return {
|
|
113
|
-
schema,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = MongooseHandler;
|