Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
La data-source sezione definisce i dettagli di accesso al database. Definisce anche le opzioni di database.
Impostazioni origine dati
| Property | Description |
|---|---|
| data-source | Oggetto contenente le impostazioni di connettività del database |
| data-source.database-type | Database usato nel back-end: mssql, mysqlpostgresql, , cosmosdb_nosql,cosmosdb_postgresql |
| data-source.connection-string | Stringa di connessione per il tipo di database selezionato |
| data-source.options | Proprietà specifiche del database (ad esempio, opzioni per SQL Server, Cosmos DB e così via) |
| data-source.options.database | Nome del database Azure Cosmos DB per NoSQL (obbligatorio quando database-type = cosmosdb_nosql) |
| data-source.options.container | Nome del contenitore Azure Cosmos DB per NoSQL (obbligatorio quando database-type = cosmosdb_nosql) |
| data-source.options.schema | Percorso del file di schema GraphQL (obbligatorio quando database-type = cosmosdb_nosql) |
| data-source.options.set-session-context | Abilita l'invio di attestazioni JWT (JSON Web Token) come contesto di sessione (solo SQL Server) |
| data-source.health | Oggetto che configura i controlli di integrità per l'origine dati |
| data-source.health.enabled | Abilita l'endpoint di controllo integrità |
| data-source.health.name | Identificatore usato nel report sull'integrità |
| data-source.health.threshold-ms | Durata massima in millisecondi per la query di controllo integrità |
Format overview
{
"data-source": {
"database-type": <string>,
"connection-string": <string>,
"options": {
// mssql only
"set-session-context": <true> (default) | <false>,
// cosmosdb_nosql only
"database": <string>,
"container": <string>,
"schema": <string>
},
"health": {
"enabled": <true> (default) | <false>,
"name": <string>,
"threshold-ms": <integer; default: 1000>
}
},
"data-source-files": ["<string>"]
}
Data source
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
$root |
database-source |
object | ✔️ Yes | - |
Nested properties
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
data-source |
database-type |
enum | ✔️ Yes | None |
data-source |
connection-string |
string | ✔️ Yes | None |
data-source |
options |
object | ❌ No | None |
Property values
database-type |
Description | Min Version |
|---|---|---|
mssql |
SQL in Fabric | - |
mssql |
Database SQL di Microsoft Azure | - |
mssql |
Istanza gestita di SQL di Azure | - |
mssql |
SQL Server | 2016 |
dwsql |
Azure Synapse Analytics | - |
dwsql |
Fabric Warehouse | - |
dwsql |
Endpoint di Analisi SQL di Infrastruttura | - |
postgresql |
PostgreSQL | ver. 11 |
mysql |
MySQL | ver. 8 |
cosmosdb_nosql |
Azure Cosmos DB per il NoSQL | - |
cosmosdb_postgresql |
Azure Cosmos DB con PostgreSQL | - |
Format
{
"data-source": {
"database-type": <string>,
"connection-string": <string>,
"options": {
"<key-name>": <string>
}
}
}
Esempio: SQL di Azure e SQL Server
"data-source": {
"database-type": "mssql",
"connection-string": "Server=tcp:myserver.database.windows.net,1433;Initial Catalog=MyDatabase;User ID=MyUser;Password=MyPassword;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
"options": {
"set-session-context": true
}
}
Note
We use SqlClient for Azure SQL and SQL Server, which supports these connection strings variants.
Consumare SESSION_CONTEXT
Per SQL di Azure e SQL Server, Il generatore di API dati può includere le informazioni sulle attestazioni in SQL SESSION_CONTEXT.
CREATE PROC GetUser @userId INT AS
BEGIN
-- Use claims
IF SESSION_CONTEXT(N'user_role') = 'admin'
BEGIN
RAISERROR('Unauthorized access', 16, 1);
END
SELECT Id, Name, Age, IsAdmin
FROM Users
WHERE Id = @userId;
END;
Esempio: Azure Cosmos DB
"data-source": {
"database-type": "cosmosdb_nosql",
"connection-string": "@env('SQL_CONNECTION_STRING')",
"options": {
"database": "Your_CosmosDB_Database_Name",
"container": "Your_CosmosDB_Container_Name",
"schema": "Path_to_Your_GraphQL_Schema_File"
}
}
Note
Le "opzioni" specificate (database, containere schema) sono specifiche di Azure Cosmos DB.
Environment variables
Usare le variabili di ambiente per mantenere i segreti di testo normale all'esterno del file di configurazione.
Tip
Il generatore di API dati supporta entrambi i @env() file function.env](../reference-functions.md#env) and [.
"data-source": {
"database-type": "mssql",
"connection-string": "@env('SQL_CONNECTION_STRING')"
}
Connection resiliency
Il generatore di API dati usa il backoff esponenziale per ripetere le richieste di database dopo errori temporanei.
| Attempts | First | Second | Third | Fourth | Fifth |
|---|---|---|---|---|---|
| Seconds | 2s | 4s | 8s | 16s | 32s |
Identità del servizio gestito
Le identità del servizio gestito sono supportate con DefaultAzureCredential la libreria definita.Azure.Identity Altre informazioni sulle identità gestite in Microsoft Entra per SQL di Azure.
identità gestite User-Assigned (UAMI)
For User Assigned Managed Identity, append the Authentication and User Id properties to your connection string while substituting in your User Assigned Managed Identity's client id: Authentication=Active Directory Managed Identity; User Id=<UMI_CLIENT_ID>;.
identità gestita System-Assigned (SAMI)
For System Assigned Managed Identity, append the Authentication property and exclude the UserId and Password arguments from your connection string: Authentication=Active Directory Managed Identity;.
Integrità (origine dati)
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
data-source |
health |
object | No | – |
Il generatore di API dati supporta più file di configurazione, ognuno con la propria origine dati. Questo blocco di configurazione consente a ogni origine dati di avere una propria configurazione di integrità.
Nested properties
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
data-source.health |
enabled |
boolean | No | true |
data-source.health |
name |
string | No | database-type |
data-source.health |
threshold-ms |
integer | No | 1000 |
Check name
Poiché più file di configurazione possono puntare a origini dati dello stesso tipo, tali origini dati non possono essere distinte nel report sull'integrità. Usare name per assegnare un'etichetta univoca e identificabile usata solo nel report sull'integrità.
Check behavior
La query più semplice possibile, specifica del tipo di database, viene eseguita sull'origine dati specificata per verificare che la connessione possa essere aperta. Utilizzare la threshold-ms proprietà per configurare la durata massima accettabile (in millisecondi) per il completamento della query.
Format
{
"data-source": {
"health": {
"enabled": <true> (default) | <false>,
"name": <string>,
"threshold-ms": <integer; default: 1000>
}
}
}