TriPSs / nestjs-query

Easy CRUD for GraphQL.
https://tripss.github.io/nestjs-query/
MIT License
157 stars 43 forks source link

One-to-many Relations is not visible in dto in other services via @ResolveField() #254

Closed detwait closed 5 months ago

detwait commented 6 months ago

Let say we have 2 microservices: users and complaints.

UserDto in user ms has @FilterableUnPagedRelation('roles', () => UserDto, { nullable: true })

In complaints ms we have ComplaintDto with id, userId and "user" field. User field is handled in the same resolver via @ResolveField('user', () => UserDto, { nullable: true }) (UserDto is stored in shared package and imported to both microservices)

Expected behavior To see in Complaint MS "roles" array in user schema. But it just see fields that was defined inside UserDto class itself.

How to get those "roles" field ? Define it inside UserDto explicitly as well as via FilterableUnPagedRelation() ? And how to solve it for @FilterableOffsetConnection() too ?

@TriPSs ?

GP4cK commented 6 months ago

I've never worked with microservices but maybe if you added a user resolver in your complaints module, you could make it work. Something like this:

// complaints.module.ts

@Module({
  imports: [
    NestjsQueryGraphQLModule.forFeature({
      imports: [/* ... */],
      resolvers: [
        {
          DTOClass: ComplaintDto,
          // ...
        },
        { // Add this
          DTOClass: UserDto,
          // Maybe also provide a ServiceClass?
        },
      ],
      services: [/* ... */],
    }),
  ],
  // ...
})
export class ComplaintModule {}

You would also get rid of your @ResolveField() for user.

Otherwise, microservices are also mentioned in the Assemblers section of the docs.

I hope that helps.

TriPSs commented 5 months ago

I also have never worked with microservices of NestJs, please try the suggestion of @GP4cK.

If still an issue you can re-open the ticket.