1.0.1 • Published 1 year ago
@zhr6525/hsm-mw v1.0.1
prisma集成moleculer
背景
基于prisma和graphql,创建moleculer服务,可被moleculer的apollo-server网关发现并调用。
依赖
node
:16.x以上moleculer
:^0.14.29graphql
: ^16.6.0"@graphql-tools/graphql-file-loader
: ^7.5.17"@graphql-tools/load
: ^7.8.14"
使用说明
import MW from "@zhr6525/hsm-mw";
import config from "./moleculer.config";
interface result {
code: number; // 成功返回0
errorMsg?: any; // 错误信息
}
// config:自定义moleculer配置
// schema:使用nexus的makeSchema生成,同创建ApolloServer的schema
// prisma:prismaClient
const mwServer = new MW(config, schema, prisma);
let res: result = await mwServer.start(
path.join(__dirname, "../schema.graphql"), // .graphql文件路径
"dbServer" // 服务名,具有唯一性
);
if (res.code) {
console.error(res.errorMsg);
}
具体moleculer配置可参考官方文档