apollo-datasource-mongodb
apollo-datasource-mongodb copied to clipboard
Typescript mismatch between mongodb <Collection> and apollo-datasources-mongodb <Collection>
I replaced my UserAPI with the one in apollo-datasources-mongodb typescript section, and still got the same error.
---ERROR---
Argument of type 'import("C:/Users/969070/Code/pistachio_develpment/server/node_modules/mongodb/mongodb").Collection<import("C:/Users/969070/Code/pistachio_develpment/server/node_modules/bson/bson").Document>' is not assignable to parameter of type 'import("C:/Users/969070/Code/pistachio_develpment/server/node_modules/apollo-datasource-mongodb/node_modules/@types/mongodb/index").Collection<import("C:/Users/969070/Code/pistachio_develpment/server/node_modules/bson/bson").Document>'. Type 'Collection<Document>' is missing the following properties from type 'Collection<Document>': geoHaystackSearch, group, parallelCollectionScan, reIndex, savet --- ERROR ---
Argument of type 'Collection<Document>' is not assignable to parameter of type 'Collection<UserDocument>'. Type 'Collection<Document>' is missing the following properties from type > 'Collection<UserDocument>': geoHaystackSearch, group, parallelCollectionScan, reIndex, save
--- APOLLO SERVER ---
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 ---
"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"
},
It seems that there is a mismatch between the <Collection> from MongoClient and the <Collection> in apollo-datasources-mongodb.
That is the mongodb <Collection> not fitting with the apollo-datasource-mongodb <Collection> type, right?
Am I missing something?
Can somebody please take a moment to say this works in the demo app, and the problem is my deployment?
I have been working on this all day and cannot get any closer. I added the missing parameters to the apollo-datasource-mongodb type and a new error popped up that some other property did not match.
If the error is mine, I will find it, but that looks like the type meant for Collection<Document> does not match with Collection<Document>. If this is not a mature project, I will go back to Redux.
My guess is different versions of mongodb or @types/mongodb? Here are the versions this package uses:
https://github.com/GraphQLGuide/apollo-datasource-mongodb/blob/6eff2ac8075f553dbb1814199b893e425f2b3908/package.json#L20-L37
The type defs were an external contribution, and we don't have a demo or test for them, but I'd welcome a PR.
MongoDB includes its own types now. There is an NPM warning when adding @types/mongodb