无法 运行 通过 tsc 构建 graphql 服务器
Can't run builded graphql server by tsc
我正在使用 typescript + graphql + node.js 服务器。 ts-node 中 运行 不是问题。
但在生产中,我想通过 tsc 构建到 js。另外,我正在使用路径别名。
首先,由于别名路径,我在 dist 中收到有关路径的错误。所以,我尝试通过 babel 捆绑 dist 文件。
package.json
"scripts": { ..
"build": "tsc && babel dist -d dist",
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"inlineSourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"baseUrl": ".",
"paths": {
"src/*" : ["src/*"]
},
"outDir": "dist",
"plugins": [
{
"transform": "typescript-transform-paths"
}
]
}
}
.babelrc
{
"compact": false,
"retainLines": true,
"minified": false,
"inputSourceMap": false,
"sourceMaps": false,
"plugins": [
[
"module-resolver",
{
"root": ["./dist"],
"alias": {
"src": "./dist"
}
}
]
]
}
然后,我得到了dist文件。但是,当我尝试
node dist/App.js
我收到一条类似
的错误消息
/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql/validation/validate.js:108
throw new Error(errors.map(function (error) {
^
Error: Unknown type "Query".
at assertValidSDL (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql/validation/validate.js:108:11)
at Object.buildASTSchema (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql/utilities/buildASTSchema.js:71:34)
at Object.buildSchemaFromTypeDefinitions (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:23:28)
at Object.makeExecutableSchema (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql-tools/dist/makeExecutableSchema.js:26:29)
at Object.<anonymous> (/Users/dany/workspace/paperly/projects/strum-server/dist/graphql/schema.js:11:27)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
at Module.require (internal/modules/cjs/loader.js:1080:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/dany/workspace/paperly/projects/strum-server/dist/App.js:28:34)
估计是graphql转js的问题
有什么问题?
确保将文件夹 typeDefs 中的文件导出到文件夹 dist
import path from 'path'
import { fileLoader, mergeTypes } from 'merge-graphql-schemas'
const typesArray = fileLoader(path.join(__dirname, './**'))
export default mergeTypes(typesArray, { all: true })
我正在使用 typescript + graphql + node.js 服务器。 ts-node 中 运行 不是问题。 但在生产中,我想通过 tsc 构建到 js。另外,我正在使用路径别名。
首先,由于别名路径,我在 dist 中收到有关路径的错误。所以,我尝试通过 babel 捆绑 dist 文件。
package.json
"scripts": { ..
"build": "tsc && babel dist -d dist",
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"inlineSourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"baseUrl": ".",
"paths": {
"src/*" : ["src/*"]
},
"outDir": "dist",
"plugins": [
{
"transform": "typescript-transform-paths"
}
]
}
}
.babelrc
{
"compact": false,
"retainLines": true,
"minified": false,
"inputSourceMap": false,
"sourceMaps": false,
"plugins": [
[
"module-resolver",
{
"root": ["./dist"],
"alias": {
"src": "./dist"
}
}
]
]
}
然后,我得到了dist文件。但是,当我尝试
node dist/App.js
我收到一条类似
的错误消息/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql/validation/validate.js:108
throw new Error(errors.map(function (error) {
^
Error: Unknown type "Query".
at assertValidSDL (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql/validation/validate.js:108:11)
at Object.buildASTSchema (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql/utilities/buildASTSchema.js:71:34)
at Object.buildSchemaFromTypeDefinitions (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql-tools/dist/generate/buildSchemaFromTypeDefinitions.js:23:28)
at Object.makeExecutableSchema (/Users/dany/workspace/paperly/projects/strum-server/node_modules/graphql-tools/dist/makeExecutableSchema.js:26:29)
at Object.<anonymous> (/Users/dany/workspace/paperly/projects/strum-server/dist/graphql/schema.js:11:27)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
at Module.require (internal/modules/cjs/loader.js:1080:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/dany/workspace/paperly/projects/strum-server/dist/App.js:28:34)
估计是graphql转js的问题
有什么问题?
确保将文件夹 typeDefs 中的文件导出到文件夹 dist
import path from 'path'
import { fileLoader, mergeTypes } from 'merge-graphql-schemas'
const typesArray = fileLoader(path.join(__dirname, './**'))
export default mergeTypes(typesArray, { all: true })