直到我在 Wes Bos slack 频道上找到解决方案之前,我都遇到了这个错误。
以下内容对我有用,但您可能会因为其他原因收到该错误。
我不确定它为什么会起作用。
你可以看到它在工作here
cd backend
- 运行
npm install graphql-import
- 更新
package.json中的脚本:
"deploy": "prisma deploy --env-file variables.env&& npm run writeSchema",
"writeSchema": "node src/writeSchema.js"
注意:对于非 Windows 用户,请确保在 && 之前放置空格
- 创建
src/writeSchema.js:
const fs = require('fs');
const { importSchema } = require('graphql-import');
const text = importSchema("src/generated/prisma.graphql");
fs.writeFileSync("src/schema_prep.graphql", text)
- 更新
src/db.js:
const db = new Prisma({
typeDefs: __dirname + "/schema_prep.graphql",
...
});
- 更新
src/createServer.js:
return new GraphQLServer({
typeDefs: __dirname + '/schema.graphql',
...
});
- 更新
src/schema.graphql:
# import * from './schema_prep.graphql'
- 创建
now.json
{
"version": 2,
"name": "Project Name",
"builds": [
{ "src": "src/index.js", "use": "@now/node-server" }
],
"routes": [
{ "src": "/.*", "dest": "src/index.js" }
],
"env": {
"SOME_VARIABLE": "xxx",
...
}
}
- 运行
npm run deploy 以初始创建schema_prep.graphql。
- 运行
now
另一个回复是这样说的:
您不应混合使用 graphql 导入和 js/ts 导入。 graphql 文件上的语法将由 graphql-import 解释,并将被 ncc 忽略(读取 __dirname 内容并将文件移动到正确目录等的编译器)
在我的示例中,“schema_prep.graphql”已经使用生成的 graphql 文件中的导入进行了预处理。
希望这会有所帮助。