question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDataSource Typescript issues

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jblevins1991commented, Mar 27, 2020

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

0reactions
lorensrcommented, Mar 27, 2020

Thanks @jblevins1991 for reporting and researching and @9at8 for fixing! 🤗 Fix published in 0.2.5

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found