3.1 Fondamenti GraphQL

GraphQL1) permette query dati flessibili e precise.

Cos'è GraphQL?

GraphQL2) è un linguaggio di query per API e un runtime per l'esecuzione di queste query. A differenza di REST3) i client possono richiedere esattamente i dati di cui hanno bisogno.

Endpoint

POST /api/v1/dsn/{dbName}/graphql
Content-Type: application/json

Query Semplice

{
  "query": "{ customers { id name country } }"
}

Con Parametri

{
  "query": "{ customers(first: 10, filter: \"Country eq 'DE'\") { id name } }"
}

Recuperare Schema

GET /api/v1/dsn/demo/graphql/schema

Restituisce lo schema GraphQL in formato SDL4).

Vantaggi rispetto a REST

Aspetto REST GraphQL
Endpoint Molti (per risorsa) Uno
Over-fetching Frequente Mai
Under-fetching Frequente (N+1) Mai
Type safety Opzionale Integrata
Documentazione Esterna (OpenAPI5)) Integrata (Introspection)

Fonti

1)
Specifica GraphQL: https://spec.graphql.org/
2)
GraphQL Foundation: https://graphql.org/
4)
Schema Definition Language: https://graphql.org/learn/schema/
5)
OpenAPI Specification: https://www.openapis.org/
Zuletzt geändert: il 30/01/2026 alle 01:31