jasci
06/10/2021, 8:51 AM// Option 1 - Separate Query
export const Story = {
tags: (_args, parent) =>
db.tag.findMany({ where: { story: { id: parent.id } } })
};
// Option 2 - Fluent API
export const Story = {
tags: (_args, parent) =>
db.story.findUnique({ where: { id: parent.id } }).tags()
};
But also docs states that findUnique queries are batched and it improves performance, so my thought was to use Fluent api if the separate query uses findMany like in the example above, but if we were to query single tag instead of tags (findUnique in both separate and fluent api queries) it’s better to use separate query. But regarding this issues people say that 1 query always outperform multiple queries, if that’s the case I don’t see any use cases where Fluent API is preferred.
When would Fluent API be a better choice ?
Thank you.Dominic Hadfield
06/10/2021, 9:01 AMjasci
06/10/2021, 9:09 AMfindMany in a standalone query I’d better use findUnique with Fluent API ?
It means in the original question Option 2 is the way to go ? Cause it seems that it’s slower, no ?Dominic Hadfield
06/10/2021, 9:58 AMgetTagsByStory, you will pass the story id in the args and then in the resolver you can do either I guess. Im not sure what the difference in speed is. The only place that you must use the data loader is when resolving tags on the story object