I was following the code first approach to defining a GraphQL interface in the Nestjs docs.
However, the resolveType() requires that you return a class instance and forces me to import the classes that implements the interface (I have the classes in different files); this creates circular depedencies amongst my classes and the interface files.
Example:
book.interface.ts:
import { ColoringBook } from './coloring-book.model.ts
import { TextBook } from './textbook.model.ts
@InterfaceType(resolveType(book) {
if (book.colors) {
return ColoringBook;
}
return Textbook;
})
abstract class Book {
// class members...
}
coloring-book.model.ts:
import { Book } from './book.interface.ts';
@ObjectType({ implements: Book})
class ColoringBook implements Book {
// class members...
}
textbook.model.ts:
import { Book } from './book.interface.ts';
@ObjectType({ implements: Book})
class Textbook implements Book {
// class members...
}
I've tried this like:
resolveType(book) {
if (book.colors) {
return forwardRef(() => ColoringBook);
}
return forwardRef(() => TextBook);
}
but that doesn't help as I still need to import the class and it doesn't actually resolve at runtime.
What would be a best practice way of avoiding this circular dependency short of consolidating everything to one file?