As there's demand for that feature (#89 #47), here we come! 馃槃
I've been away from JS for a minute.... just saw this... can't wait to use it. :) . Hope it didn't make you cringe too much implementing it.. your implementation of it looks great!
Hi @MichalLytek,
I followed this pattern to write base resolver. When I wanted to use it in another project using type-graphql, i moved all the code to a new npm package. But I am getting the following error when running typescript compiler
Return type of exported function has or is using private name 'BaseResolverClass'.
Here's my code for reference
export function BaseResolver<T>(Entity: {
new (): T;
}) {
const entityName = Entity.name;
@injectable()
@Resolver({ isAbstract: true })
class BaseResolverClass {
repository: Repository<T>;
constructor(private dbConnection: Promise<Connection>) {
dbConnection
.then(connection => connection.getRepository(Entity))
.then(repository => {
this.repository = repository;
});
}
@Mutation(() => Entity, { name: `create${entityName}` })
async create(
@Arg('entry', type => Entity)
entry: DeepPartial<T>,
): Promise<T> {
const entity = new Entity();
Object.assign(entity, entry);
return await this.repository.save(entity);
}
@Query(returns => Entity, { name: `find${entityName}` })
async findOneById(
@Arg('id', type => Int)
id: number,
): Promise<T> {
return this.repository.findOneOrFail(id);
}
@Mutation(() => Entity, { name: `update${entityName}` })
async update(
@Arg('id', type => Int)
id: number,
@Arg('entry', type => Entity)
partialEntry: DeepPartial<T>,
): Promise<T> {
const foundEntity = await this.findOneById(id);
this.repository.merge(foundEntity, partialEntry);
return await this.repository.save(foundEntity);
}
}
return BaseResolverClass
}
This is because I am exporting declaration from this package to be used in my 2 projects. Is there any way to get around this?
@itsrimzz1
Yes, you have to redeclare the shape of the inner class, because their types are not explicit, so it can't generate proper *.d.ts typings.
Most helpful comment
I've been away from JS for a minute.... just saw this... can't wait to use it. :) . Hope it didn't make you cringe too much implementing it.. your implementation of it looks great!