MongoDataSource Typescript issues
See original GitHub issueI started a Typescript project with Apollo Server and have implemented this module the way the documentation expects. I have a data source as shown below as well as my index.ts file that implements the apollo server.
import { MongoDataSource } from "apollo-datasource-mongodb";
export default class Authors extends MongoDataSource {
getAuthorById(id: string) {
return this.findOneById(id);
}
};
const client = new MongoClient("super secret mongo server");
client.connect();
const server = new ApolloServer({
typeDefs,
resolvers,
playground: true,
dataSources: () => ({
users: new Authors(client.db().collection("authors")),
posts: new Posts(client.db().collection("posts")),
}),
});
I get the following Typescript errors:
index.ts
- Expected 0 arguments, but got 1. ts(2554)
This error is when I attempt to pass client.db().collection("authors")
to the Authors constructor. This also happens for Posts.
author.ts
- Property “findOneById” does not exist on type ‘Authors’. ts(2339)
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (2 by maintainers)
Top Results From Across the Web
Typescript mismatch between mongodb <Collection> and ...
The typescript demo for apollo-datasources-mongodb no longer works. It generates the same error that my own code is generating:.
Read more >apollo-datasource-mongodb - npm
apollo-datasource-mongodb. TypeScript icon, indicating that this package has built-in type declarations. 0.5.4 • Public • Published 9 months ...
Read more >Apollo-mongodb-datasource NPM - npm.io
MongoDataSource. An Apollo GraphQL Datasource using MongoDB. Why. While there already is a somewhat good MongoDB DataSource package available ...
Read more >Data sources - Apollo GraphQL Docs
... SQL databases (via Knex.js). MongoDataSource, Community, MongoDB ... If you're using TypeScript, make sure to import the RequestOptions type: TypeScript.
Read more >apollo-datasource-mongodb examples - CodeSandbox
nenjotsu/apollo-server-tsApollo GraphQL Server with TypeScript and Webpack HMR ... github.com/GraphQLGuide/apollo-datasource-mongodb/issues.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is from the TypeScript web site https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
Note that the “typings” field is synonymous with “types”, and could be used as well.
Also note that if your package.json includes the “files” property the “types” property will be ignored. In that case you need to pass your main declaration file to the “files” property as well.
Also note that if your main declaration file is named index.d.ts and lives at the root of the package (next to index.js) you do not need to mark the “types” property, though it is advisable to do so
Thanks @jblevins1991 for reporting and researching and @9at8 for fixing! 🤗 Fix published in
0.2.5