3 ms·
How to avoid N+1 query ? You don't join SQL.
by revskill 3y ago
How to avoid N+1 query ? You don't join SQL.
- x86x87 3y agobrave to assume they are avoiding this problem :/
- lolive 3y agoI am not sure I understand that n+1 select issue with graphQL. On my project, we generate SPARQL queries [to simplify, it is not so different from a GraphQL query] and we send it to a SQL translator that then sends that SQL to a Spark cluster. It is reasonably efficient, and extremely flexible. Of course, this is a single database use case, but I don’t see any n+1 select involved here. And I do not understand how single database graphQL servers cannot work exactly the same.
- ptramo 3y agoThe most common practice is to turn N+1 into 1+1 using dataloaders (https://github.com/graphql/dataloader https://github.com/graphql/dataloader for JS, there are equivalents for most implementations). The N resolvers invoke a single batched loader which receives a list of keys and returns a list of values.