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 error when iniatilising data source #54

Open
dan-cooke opened this issue Apr 6, 2021 · 5 comments
Open

Typescript error when iniatilising data source #54

dan-cooke opened this issue Apr 6, 2021 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@dan-cooke
Copy link

dan-cooke commented Apr 6, 2021

I am encountering the following error when attempting to follow the documentation

Argument of type 'Collection<Profile | UpdateQuery<Profile>>' is not assignable to parameter of type 'Collection<Profile>'.
  Types of property 'aggregate' are incompatible.

Here is my ApolloServer iniatilisation

 const client = await connectToDb();

  const schema = makeExecutableSchema({
    typeDefs: [DIRECTIVES, typeDefs],
    resolvers,
  });
  const apolloServer = new ApolloServer({
    schema,
    introspection: true,
    formatError: (error) => {
      console.error(error);
      return error;
    },
    playground: {
      endpoint: `/dev/graphql`,
    },
    dataSources: () => ({
      profiles: new Profiles(client.db().collection(`profiles`)),
    }),
  });

The line that throws the error is

 profiles: new Profiles(client.db().collection(`profiles`)),

My Profiles data source looks as follows:

import { Profile } from 'generated/mongodbTypes'
export default class Profiles extends MongoDataSource<Profile, any> { }

I am importing the following Profile type generated from my GraphQL schema by Graphql codegen

export type Profile = {
  __typename?: 'Profile';
  _id: Scalars['ObjectID'];
  user_id: Scalars['String'];
  portfolios?: Maybe<Array<Portfolio>>;
};

The weird thing is this worked on my other project before switching over to a fresh project - same code from what I can tell.

Edit:

I forgot to post versions, apologies

apollo-datasource-mongodb 0.3.0
node: 15.11.0
typescript: 4.2.3

@lorensr
Copy link
Member

lorensr commented Apr 6, 2021

The weird thing is this worked on my other project before switching over to a fresh project - same code from what I can tell.

Was it the same version of this lib in the other project?

Types of property 'aggregate' are incompatible.

So there are two Collection.aggregates, and their types are different?

Sorry, I haven't learned typescript yet, so I won't be much help, but happy to merge a PR if someone fixes this ☺️

@dan-cooke
Copy link
Author

@lorensr thanks for the reply!

Both projects are using the exact same version. I have just disabled ts checking for this line while I wait for a fix.

@9at8
Copy link
Collaborator

9at8 commented Apr 7, 2021

@dan-cooke can you post which versions of @types/mongodb do you have from your yarn.lock or package-lock.json?

@dan-cooke
Copy link
Author

dan-cooke commented Apr 7, 2021

@9at8 resolved 0.3.0 for both projects

I updated my original post with Typescript and node versions as well! thanks

@lorensr lorensr added the help wanted Extra attention is needed label Jun 12, 2021
@paolommj
Copy link

I have the same error and it's caused by mongodb having released its own types that conflict with those from @type/mongodb

Argument of type
 'import("[...]/node_modules/mongodb/mongodb").Collection<import("[...]/src/generated/schema").ActorDbObject>'
 is not assignable to parameter of type 
 'import("[...]/node_modules/apollo-datasource-mongodb/node_modules/@types/mongodb/index").Collection<import("[...]/src/generated/schema").ActorDbObject>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants