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

Eagerly load data from external service in a query and access it in @ResolveField from @Parent

Open thehappycoder opened this issue 4 years ago • 3 comments

Is it possible? I got external data in parents query resolve function, got parents from queryService, modified the result by adding some additional data (parents[i].child.someField = 'foobar')... But resolve field Child.someField cannot see it, it only sees the original Child entry without an additional field.

Alternative solution is to make a request to an external service every time Child.someField is resolved. I just want to avoid doing that for performance reasons.

thehappycoder avatar Jan 06 '21 09:01 thehappycoder

@thehappycoder you may have already found a work around for this but if not, would you mind providing an example?

doug-martin avatar Feb 07 '21 00:02 doug-martin

@doug-martin For example, I am querying project from my GraphQL server, and project has tasks. Projects reside in the local database. Tasks, however, exist in another system and can be loaded via API.

When I worked with graphql-js, it was possible to load tasks in project resolve function and return that project with these tasks from that resolve function to be later accessible in resolve function of tasks and resolve functions of each property of a task.

In nestjs-query, this approach doesn't work.

thehappycoder avatar Feb 15 '21 07:02 thehappycoder

@thehappycoder I think this can be achieved using the RelationQueryService I created that for Federation but I think it would also suit this as well. I'll add some documentation around the RelationQueryService.

It is not currently straight forward to wrap an additional service but you can do it using the NoOpQueryService and only implement the methods you need to fetch the relation. In this case just the query method.

doug-martin avatar Mar 17 '21 05:03 doug-martin