构建 GraphQL 服务器:从架构到应用的全流程实现
1. 创建 GraphQL 架构
在数据库代码就绪后,我们将着手编写 GraphQL 服务器。为简化代码编写过程,我们选择使用 type-graphql 。首先,通过以下命令安装相关依赖:
npm install type-graphql @types/graphql reflect-metadata --save
同时,将 tsconfig 文件配置如下:
{
"compileOnSave": false,
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"lib": ["es2016", "esnext.asynciterable", "dom"],
"outDir": "./dist",
"noImplicitAny": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
这里使用 ES2016 是因为 type-graphql 用到了 ES7 的特性,而 ES7 对应 ES2016。
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



