【问题标题】:Typescript mismatch between mongodb <Collection> and apollo-datasources-mongodb <Collection>mongodb <Collection> 和 apollo-datasources-mongodb <Collection> 之间的打字稿不匹配
【发布时间】:2022-08-19 02:20:38
【问题描述】:

apollo-datasources-mongodb 的打字稿演示不再有效。它会产生与我自己的代码相同的错误:

- - 错误 - -

类型参数 \'import(\"C:/Users/user/Code/development/server/node_modules/mongodb/mongodb\").Collection<import(\"C:/Users/user/Code/development/server/ node_modules/bson/bson\").Document>\' 不能分配给 \'import(\"C:/Users/user/Code/development/server/node_modules/apollo-datasource-mongodb/node_modules/@ 类型的参数types/mongodb/index\").Collection<import(\"C:/Users/user/Code/development/server/node_modules/bson/bson\").Document>\'. 类型 \'Collection\' 缺少类型 \'Collection\' 中的以下属性:geoHaystackSearch、group、parallelCollectionScan、reIndex、savet

--- 阿波罗服务器 ---

const server : ApolloServer = new ApolloServer({ schema : authorizedSchema
        , dataSources: () => ({  
            users: new Test( mongoClient.db(\"myapp\").collection(\"users\") ) // intellisense highlights the input to new Test as the error
        })
        , context: async ( { req } ) => { await verifyAccessToken( req ) }
        , csrfPrevention: true
    });

--- 依赖项 ---

\"dependencies\": {
    \"@apollo/client\": \"^3.6.9\",
    \"@azure/msal-common\": \"^7.1.0\",
    \"@graphql-tools/schema\": \"^8.5.0\",
    \"@graphql-tools/utils\": \"^8.8.0\",
    \"@types/express\": \"github:types/express\",
    \"@types/jsonwebtoken\": \"^8.5.8\",
    \"@types/node\": \"^18.0.3\",
    \"apollo-datasource-mongodb\": \"^0.5.4\",
    \"apollo-server\": \"^3.9.0\",
    \"apollo-server-core\": \"^3.9.0\",
    \"cookie-parser\": \"^1.4.6\",
    \"debug\": \"^4.3.4\",
    \"dotenv\": \"^16.0.1\",
    \"express\": \"^4.18.1\",
    \"express-jwt\": \"^7.7.5\",
    \"graphql\": \"^15.8.0\",
    \"graphql-tools\": \"^8.3.0\",
    \"http-errors\": \"^2.0.0\",
    \"jsonwebtoken\": \"^8.5.1\",
    \"jwks-rsa\": \"^2.1.4\",
    \"jws\": \"^4.0.0\",
    \"mongodb\": \"^4.8.1\",
    \"openid-client\": \"^5.1.8\",
    \"type-graphql\": \"^1.1.1\",
    \"typescript\": \"^4.7.4\"
  },

MongoClient 中的 <Collection> 和 apollo-datasources-mongodb 中的 <Collection> 似乎不匹配。

那就是 mongodb <Collection> 不适合 apollo-datasource-mongodb <Collection> 类型,对吧?

我错过了什么吗?

编辑:

我尝试将缺少的属性设置为可选来扩展 MongoDB 集合。这已经超越了关于 mongodb 类型的这些属性的错误,现在我得到另一个错误,即不同的属性是错误的。

    标签: mongodb react-apollo apollo-server


    【解决方案1】:

    请尝试将依赖项中的 apollo 服务器包更新到最新版本。

    "apollo-server": "^3.10.1",
    "apollo-server-core": "^3.10.1"
    

    【讨论】:

    • 完成,但错误仍然存​​在。我正在检查 apollo-datasources-mongodb 的较新版本,但已经有一段时间没有更新了。我是唯一有这个问题的人吗?该错误看起来应该会影响每个尝试键入其数据源的人
    猜你喜欢
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多