Faz parte do material de GraphQL que eu montei a partir das minhas entrevistas. Abaixo, a resposta em inglês e, quando existe, a pegadinha mais comum.
GraphQL lets clients select fields from a typed schema, often through one endpoint. REST-style APIs usually expose multiple resource endpoints, but they can also support field selection, expansions, and batch requests.
GraphQL can reduce response over-fetching and client round trips when a screen needs a related graph. One GraphQL HTTP request can still trigger many backend queries. It does not automatically solve N+1.
Trade-offs:
- HTTP/CDN caching needs care. Queries can use GET with suitable cache policy, often using persisted IDs. Include variables and authorization in cache decisions.
- Unbounded nesting, list sizes, or aliases can make a query expensive. Use cost limits, pagination, timeouts, and authorization at the data boundary.
- Schema, resolvers, and tooling add maintenance. File transfers often use a separate upload flow.
Choose based on client needs and operational constraints. GraphQL can help varied clients traverse related data. A resource API may be simpler for a small fixed contract. Neither is universally faster or safer.
Ler é o primeiro passo. No app, essa pergunta vira flashcard com repetição espaçada, e o módulo tem quiz e simulado para testar o que ficou.
Treinar essa pergunta no app