Skip to content

Typescript error when iniatilising data source #54

Open
@dan-cooke

Description

@dan-cooke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions