Skip to content

Document N+1 mitigation techniques in the book #444

Closed
@MikailBag

Description

@MikailBag

Is your feature request related to a problem? Please describe.
Now, resolver signature looks like:
fn field(&self, /*args*/).
This can easily lead to N + 1 DB query problem. (Or even N**K if query has K levels of depth). To avoid this problem, special libraries should be used, that somehow accumulate queries and merge them into one.

Describe the solution you'd like
(Idea itself is very simple. It is possible that is was already discussed and rejected, but I didn't find such an issue). I propose to allow batched resolvers. Signature now looks smth like:
fn field(self: &[Self], ctx:&Ctx, args: ...)
Now, from N**K requests we go to K (each level will be processed with one resolver execution and one db request).
Describe alternatives you've considered
Alternative: do nothing.
However, I believe batched resolvers provide good enough performance with high flexibility.

Metadata

Metadata

Assignees

Labels

featureNew feature or requestk::documentationRelated to project documentation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions