gpt4 book ai didi

javascript - 无法使用来自另一个模块或领域的 GraphQLSchema

转载 作者:行者123 更新时间:2023-12-05 04:58:42 26 4
gpt4 key购买 nike

我正在使用 type-graphql 构建无服务器后端和 apollo-server-lambda ,但是在对 graphql 端点发出大约第三次请求后,我收到错误

Error: Cannot use GraphQLSchema "[object GraphQLSchema]" 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.

我已经降级了type-graphql因为版本1.0.0需要 graphql@^15.3.0而其他一些依赖项需要 graphql <= 14

这是我的依赖

{
"dependencies": {
"@types/graphql": "14.5.0",
"apollo-server-lambda": "^2.17.0",
"aws-sdk": "^2.750.0",
"graphql": "^14.7.0",
"pg": "^8.3.3",
"reflect-metadata": "^0.1.13",
"source-map-support": "^0.5.19",
"type-graphql": "^0.17.0",
},
"devDependencies": {
"@types/aws-lambda": "^8.10.62",
"@types/aws-sdk": "^2.7.0",
"@types/jest": "^26.0.13",
"@types/node": "^14.10.0",
"apollo-server-testing": "^2.17.0",
"serverless": "^2.0.0",
"serverless-offline": "^6.7.0",
"serverless-webpack": "^5.3.4",
"ts-jest": "^26.3.0",
"ts-loader": "^8.0.3",
"typescript": "^4.0.2",
"webpack": "^4.44.1",
"webpack-node-externals": "^2.5.2"
},
"resolutions": {
"graphql": "^14.7.0",
},

npm ls graphql结果

dives-backend@1.0.0
├─┬ @types/graphql@14.5.0
│ └── graphql@14.7.0 deduped
└── graphql@14.7.0

index.ts

import "reflect-metadata"
import { buildSchemaSync } from "type-graphql"
import { HelloResolver } from "./src/resolvers/example"

const schema = buildSchemaSync({
resolvers: [HelloResolver],
validate: false,
})

const server = new ApolloServer({
schema,
playground: { endpoint: "/dev/graphql" },
})

export const handler = server.createHandler({
cors: {
origin: true,
credentials: true,
},
})

最佳答案

我遇到了类似的问题并在 typegraphql FAQ 中找到了建议.npm dedupe 帮我解决了这个问题。

关于javascript - 无法使用来自另一个模块或领域的 GraphQLSchema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63871545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com