GraphQLGuide / apollo-datasource-mongodb

Apollo data source for MongoDB
MIT License
285 stars 64 forks source link

Circular dependency - TypeScript context type #107

Closed RemyMachado closed 2 years ago

RemyMachado commented 2 years ago

I'm stuck in a loop!

I'm trying to define the Context type present in my DataSource, but this one includes the different DataSources.

Context -> dataSources -> DataSource[] and for each DataSource: DataSource -> Context

the context:

type Context: {
   bearerToken?: string,
   dataSources: {
     users: UsersDataSource // DataSource is included here
   }
},

the DataSource:

export default class UsersDataSource extends MongoDataSource<UserDocument, Context> { // Context is included here
  ...
}

Have you already tackled this problem? ESLint: Dependency cycle detected.(import/no-cycle)

RemyMachado commented 2 years ago

I fixed the problem using import type instead of import

import type { Context } from 'my/types

More info here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export