nestjs-query icon indicating copy to clipboard operation
nestjs-query copied to clipboard

RelationQueryService query should be async

Open tonytoth opened this issue 2 years ago • 2 comments

Hello guys, One thing I think it would be useful is that the RelationQueryService should support async for virtual relations. At the moment you can't use async response for the query method. e.g:


@QueryService(TodoItemReferenceDTO)
export class TodoItemService extends RelationQueryService<TodoItemReferenceDTO> {
  constructor(@InjectQueryService(SubTaskEntity) readonly subTaskService: QueryService<SubTaskEntity>) {
    super({
      // the name of the relation
      subTasks: {
        service: subTaskService,
        // a query factory that will take in the reference to create a query.
        async query: (todoItemReferenceDTO) => (
            // Do some database request or whatever
            return { filter: { todoItemId: { eq: todoItemReferenceDTO.id } } }
        ),
      },
    });
  }
}

tonytoth avatar Jan 31 '23 06:01 tonytoth

Good idea!

Just out of interest: what are you planning to do there that needs async?

TriPSs avatar Feb 05 '23 17:02 TriPSs

I was thinking to use this in a virtual relation but I need to touch the database first.

tonytoth avatar Feb 06 '23 07:02 tonytoth