Hey guys, I have a problem for long time and I can still not figure out how to solve it:
Basically I have two Services one Service that has the Object StoreItem and the other one has the Object TradeItem. Both Services are running on a Apollo Federation Server.
@ObjectType()
@Directive('@key(fields: "tradeItem_id")')
@Entity()
export class StoreItem extends BaseEntity {
@Field(() => ID)
@Index()
@PrimaryGeneratedColumn('uuid')
_id: string;
@Field()
@Column('uuid')
tradeItem_id: string;
}
@ObjectType({ description: 'Trade Item' })
@Directive('@key(fields: "_id")')
@Entity()
export class TradeItem extends BaseEntity {
@Field(() => ID)
@PrimaryGeneratedColumn('uuid')
_id: string;
@Column()
isAvailable: boolean;
}
This is my Resolver on the TradeItem Service
@Resolver(of => StoreItem)
export class StoreItemResolver {
private logger = new Logger('StoreItemResolver');
constructor(private readonly tradeItemService: TradeItemService) {}
// Returns the TradeItem based in StoreItem
@ResolveField(() => TradeItem)
async tradeItem(
@Parent() storeItem: StoreItem,
@Context('tradeItemLoader')
tradeItemLoader: DataLoader<string, TradeItem>,
): Promise<TradeItem | Error> {
const id = storeItem.tradeItem_id as unknown;
return tradeItemLoader.load(id as string);
}
}
Example : What I want to do is, I want to return all StoreItems where isAvailable is true. I do not really know how to do this because the Object is build on the Federation Server.
So if I for example build a search like getAvailableStoreItems.
I have 5 StoreItems with 5 nested TradeItem where isAvailable is true. That is not a problem. He will return all StoreItems with the nested TradeItem.
The problem is if just 2 TradeItems are true he will return null. What I want is that he recognize that only 2 TradeItems are true therefore he has to filter out the other 3 StoreItems.
But I do not know where to implement this logic or how it works in general. Somehow it is just magic that the tradeItem object appears inside the StoreItem Object. I tried stuff in the ResolverField on the TradeItem Service. But no success. I use NestJS