Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript mismatch between mongodb <Collection> and apollo-datasources-mongodb <Collection> #106

Open
JRedded opened this issue Aug 17, 2022 · 3 comments

Comments

@JRedded
Copy link

JRedded commented Aug 17, 2022

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' is missing the following properties from type 'Collection': 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?

@JRedded
Copy link
Author

JRedded commented Aug 18, 2022

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 does not match with Collection. If this is not a mature project, I will go back to Redux.

@lorensr
Copy link
Member

lorensr commented Aug 18, 2022

My guess is different versions of mongodb or @types/mongodb? Here are the versions this package uses:

"@types/mongodb": "^3.5.27",
"apollo-datasource": "^0.3.1",
"apollo-server-caching": "^0.3.1",
"apollo-server-errors": "^2.4.1",
"bson": "^4.1.0",
"dataloader": "^1.4.0"
},
"peerDependencies": {
"mongoose": "*"
},
"devDependencies": {
"@babel/cli": "^7.10.3",
"@babel/core": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"babel-jest": "^24.9.0",
"graphql": "^14.6.0",
"jest": "^24.9.0",
"mongodb": "^3.5.9",

The type defs were an external contribution, and we don't have a demo or test for them, but I'd welcome a PR.

@OneCricketeer
Copy link

MongoDB includes its own types now. There is an NPM warning when adding @types/mongodb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants