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

Virtual Relation + Assembler doesn't work

Open mathieugeissler opened this issue 3 years ago • 1 comments

Describe the bug I have a virtual relation in my DTO

@ObjectType('Test')
@Relation('user', () => UserDto, {
  dtoName: 'UserDetails',
  relationName: 'user',
  nullable: true,
})
@QueryOptions({ defaultResultSize: 100 })
export class TestDto {
  @IDField(() => ID)
  id: string;
  @FilterableField({ nullable: true })
  status: number;
  @FilterableField(() => GraphQLJSONObject, { nullable: true })
  Details: TestDetailsDto;
}
@QueryService(TestEntity)
export class TestEntityRelationQueryService extends RelationQueryService<TestEntity> {
  constructor(
    @InjectQueryService(TestEntity)
    queryService: QueryService<TestEntity>,
    @InjectQueryService(UserEntity)
    usrQueryService: QueryService<UserEntity>,
  ) {
    super(queryService, {
      user: {
        service: usrQueryService,
        query(t) {
          return { filter: { id: { eq: t.Details.UserId } } };
        },
      },
    });
  }
}

It's working fine without assembler. But when I add assembler :

@Module({
  imports: [
    TypeOrmModule.forFeature([TestEntity, UserEntity]),
    NestjsQueryGraphQLModule.forFeature({
      imports: [
        NestjsQueryTypeOrmModule.forFeature([
          TestEntity,
          UserEntity,
        ]),
      ],
      assemblers: [TestAssembler],
      services: [
        TestEntityRelationQueryService,
      ],
      resolvers: [
        {
          DTOClass: TestDto,
          ServiceClass: TestEntityRelationQueryService,
          AssemblerClass: TestAssembler,
        },
        {
          DTOClass: UserDto,
          EntityClass: UserDto
        },
      ],
    }),
  ],
})
export class EntitiesModule {}

The virtual relation is not found (TestEntityRelationQueryService is not used at all)

Have you read the Contributing Guidelines?

Yes

To Reproduce Steps to reproduce the behavior:

  1. Create two entity with dto
  2. Add virtual relation in first dto to second dto
  3. Add assembler for first dto

Expected behavior It should use custom RelationQueryService when Assembler is define

Desktop (please complete the following information):

  • Node Version [e.g. 16.13.2]
  • Nestjs-query Version [e.g. v0.30.0]

mathieugeissler avatar Apr 01 '22 15:04 mathieugeissler

I think I met a similar error and I've found out that you either want to set a service class or assembler class for the resolver, but not both at once. Because if you define assembler class, service class isn't used then?

Image

Image

jtomaszewski avatar Jan 28 '25 09:01 jtomaszewski