Will GraphQL and nested resources make unnecessary calls?

I read the GraphQL specifications and could not find a way to avoid 1 + N * number_of_nested calls, did I miss something?

i.e. the request has a client type that has nested orders and addresses; if there are 10 clients, it will make 1 call for 10 clients + 10 calls for each client. order + 10 calls for each client .addresses.

Is there any way to avoid this? Not that it is not the same as caching the UUID of something, they are all different values, and if you point GraphQL to a database that can create joins, it would be nice to it because you could make 3 queries for any number of customers.

I ask this because I wanted to integrate GraphQL with an API that could insert embedded resources efficiently, and if there was a way to solve the entire graph before solving it, it would be nice to try to attach some attached files with just one call.

Or am I mistaken, and GraphQL is intended for use only with microservices?

+4
source share
2 answers

This is one of the difficulties of the GraphQL resolver architecture. You must avoid tons of network latency by performing many I / O operations on each converter. SQL DBMS applications often encounter the N + 1 problem. To get around this, you need to use some dosing and / or caching methods.

Node.js , , :

+1

, GraphQL SQL. , , N + 1 SELECT . GraphQL :

  • AFAIK, Ruby Active Record , bullet .
  • JavaScript DataLoader, promises. .
  • Elixir Python , , GraphQL , , .
  • F # Elixir, , , , GraphQL .
  • (.. PostGraph) GraphQL. GQL- .
+1

Source: https://habr.com/ru/post/1672549/


All Articles