Graphql: Dataloader or another method to resolve n+1 problem

Created on 17 Dec 2018  路  9Comments  路  Source: nestjs/graphql

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


I want to use dataloader to resolve n+1 problem , I has seen the issue, but I had no idea.

Expected behavior


@kamilmysliwiec say will publish a small chapter in the docs about integration with DataLoader, but I haven't found it.....
Does anyone had resolve n+1 problem??

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.4.0
Nest graphql version: 5.4.0
apollo-server-express version: 2.3.1


For Tooling issues:
- Node version: 11.3.0
- Platform:  Windows

Others:

Most helpful comment

I have implemented the dataloader in a project for the critical queries. I can share the code if you are interested. It uses interceptors and uses the context to provide the dataloaders. However, I think my implementation is far from ideal since it breaks most of nest and graphql semantics. It forces me to predict how resolvers will be executed in the queries that typically hit my server, which defeats the purpose of having a graphql api.
I would like to (and I am willing to contribute with my experience) implement it natively into @nestjs/graphql with decorators or even by default. In my opinion, solving the n+1 problem is something that is needed in every graphql server, I cannot think of a use case where I would want to leave that out intentionally.

All 9 comments

@zerox12311 You can set it in context when you are using the GrapqhlModule or you can also generate it inside a middeware and generate it on every request.
Good luck with it!

I have implemented the dataloader in a project for the critical queries. I can share the code if you are interested. It uses interceptors and uses the context to provide the dataloaders. However, I think my implementation is far from ideal since it breaks most of nest and graphql semantics. It forces me to predict how resolvers will be executed in the queries that typically hit my server, which defeats the purpose of having a graphql api.
I would like to (and I am willing to contribute with my experience) implement it natively into @nestjs/graphql with decorators or even by default. In my opinion, solving the n+1 problem is something that is needed in every graphql server, I cannot think of a use case where I would want to leave that out intentionally.

Duplicate of #20

I have implemented the dataloader in a project for the critical queries. I can share the code if you are interested. It uses interceptors and uses the context to provide the dataloaders. However, I think my implementation is far from ideal since it breaks most of nest and graphql semantics. It forces me to predict how resolvers will be executed in the queries that typically hit my server, which defeats the purpose of having a graphql api.
I would like to (and I am willing to contribute with my experience) implement it natively into @nestjs/graphql with decorators or even by default. In my opinion, solving the n+1 problem is something that is needed in every graphql server, I cannot think of a use case where I would want to leave that out intentionally.

@biels Yes! I am interested in it!
Can you share you code ?

@biels
Can you share me your code that implemented data loader with graphQLModule?

@biels
Can you share me your code that implemented data loader with graphQLModule?

Would also love to see that

@biels
Could share it to me too ?

@biels Can you share your code? please

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings