【发布时间】:2020-10-02 23:51:25
【问题描述】:
我使用 graphql-js 而不是 SDL 来设计我的 graphql 服务器。为此,我创建了一个依赖于 graphql-js 的小型库。
因此,我使用 yarn (yarn add link:../lib) 将这个库链接到我的主项目中,以构建 graphql 对象和架构。
我的 package.json 文件如下所示
graphql-lib/package.json
{
"name": "graphql-lib",
"private": true,
"version": "0.1.0",
"description": "",
"main": "index.ts",
"dependencies": {
"graphql-iso-date": "^3.6.1"
},
"devDependencies": {
"@types/graphql-iso-date": "^3.4.0",
"@types/jest": "^25.2.3",
"@types/node": "^14.0.5",
"jest": "^26.0.1",
"ts-jest": "^26.1.0",
"typescript": "^3.9.3"
},
"peerDependencies": {
"graphql": "^15.1.0"
}
}
核心/package.json
{
"name": "@core/schema",
"private": true,
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"graphql-lib": "link:../lib",
"graphql": "^15.1.0",
"graphql-iso-date": "^3.6.1"
},
"devDependencies": {
"@types/graphql-iso-date": "^3.4.0",
"@types/jest": "^26.0.0"
}
}
使用 ts-jest 进行的graphql-lib 测试工作正常。
但是,当我测试我的主要项目时,我遇到了以下错误 -
Cannot use GraphQLScalarType "Float" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
node_modules 目录中的graphql 模块仅包含graphql-js 版本15.1.0。我已经删除并重新安装了两个包中的 node_modules。
我的理解是 graphql 应该有单个执行实例。我是否错过了在两个项目中都创建了 graphql 实例的东西?我可以使用 yarn 链接我的项目并维护单个 graphql 实例吗?
【问题讨论】:
-
能否在两个项目目录中运行
npm ls graphql并显示结果。 -
我正在使用纱线工作区。 npm ls 显示为空 > npm ls graphql @express/app@0.1.0 /mnt/veracrypt1/Project/express/app └── (empty) with yarn list // 对于 graphql-lib └─ graphql@15.1.0 //对于 main └─ graphql@15.1.0
标签: node.js graphql yarnpkg graphql-js yarn-workspaces