arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

Batching requests for GraphQL server resolvers queries #810

Closed Nargonath closed 2 months ago

Nargonath commented 3 months ago

We're building a GraphQL server with NestJS commucating with ArangoDB. We use ArangoDB cloud. Our GraphQL schemas have multipe types and some are nested. We want to use sub-resolvers to fetch the nested types but we're going to hit the n+1 queries problem. Some database services like Prisma use a dedicated ORM to solve that problem where they batch queries together and send only one request to the server preventing the overhead of multiplying the request to the DB server. Does ArangoJS have similar capabilities we can leverage? I skimmed through the documentation but I couldn't anything in that regard.

For now we built our own GraphQL query parser which outputs AQL queries but it gets more and more complicated as we add joins capabilities, edge handling, dynamic object building, etc.

pluma4345 commented 2 months ago

It depends on how you're using ArangoDB. You can use collection.documents([x,y,z]) if you want to fetch multiple specific documents from the same collection directly in one request without AQL.

We don't maintain an integration for Prisma or GraphQL. If you need something more powerful, I think generating AQL queries ad hoc is probably the best approach. Note that queries generated with the aql template helper can be nested within each other and joined with the join helper in the arangojs/aql sub-module.