Exemple de configuration du générateur d’API de données
Cet exemple de configuration illustre un scénario de bout en bout. Ce scénario utilise Azure SQL Database comme base de données de stockage et Azure Static Web Apps comme hôte.
Cet exemple est dérivé des tables et des données fournies dans l’exemple de script SQL de bibliothèque.
{
"$schema": "https://github.com/Azure/data-api-builder/releases/download/v0.10.23/dab.draft.schema.json",
"data-source": {
"database-type": "mssql",
"connection-string": "@env('my-connection-string')",
"options": {
"set-session-context": false
}
},
"runtime": {
"rest": {
"enabled": true,
"path": "/api",
"request-body-strict": false
},
"graphql": {
"enabled": true,
"path": "/graphql",
"allow-introspection": true
},
"host": {
"cors": {
"origins": [],
"allow-credentials": false
},
"authentication": {
"provider": "StaticWebApps"
},
"mode": "development"
}
},
"entities": {
"authors": {
"source": {
"object": "[dbo].[authors]",
"type": "table",
"key-fields": [ "id" ]
},
"graphql": {
"enabled": true,
"type": {
"singular": "authors",
"plural": "authors"
}
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "*",
"fields": {
"exclude": [ "middle_name" ],
"include": [
"id",
"first_name",
"last_name"
]
}
}
]
}
],
"mappings": { "id": "key" },
"relationships": {
"books": {
"cardinality": "many",
"target.entity": "books",
"source.fields": [],
"target.fields": [],
"linking.object": "dbo.books_authors",
"linking.source.fields": [ "author_id" ],
"linking.target.fields": [ "book_id" ]
}
}
},
"series": {
"source": {
"object": "[dbo].[series]",
"type": "table",
"key-fields": [ "id" ]
},
"graphql": {
"enabled": true,
"type": {
"singular": "series",
"plural": "series"
}
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "*"
}
]
}
],
"relationships": {
"books": {
"cardinality": "many",
"target.entity": "books",
"source.fields": [ "id" ],
"target.fields": [ "series_id" ],
"linking.source.fields": [],
"linking.target.fields": []
}
}
},
"books": {
"source": {
"object": "[dbo].[books]",
"type": "table",
"key-fields": [ "id" ]
},
"graphql": {
"enabled": true,
"type": {
"singular": "books",
"plural": "books"
}
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "*"
}
]
}
],
"relationships": {
"series": {
"cardinality": "one",
"target.entity": "series",
"source.fields": [ "series_id" ],
"target.fields": [ "id" ],
"linking.source.fields": [],
"linking.target.fields": []
},
"authors": {
"cardinality": "many",
"target.entity": "authors",
"source.fields": [],
"target.fields": [],
"linking.object": "dbo.books_authors",
"linking.source.fields": [ "book_id" ],
"linking.target.fields": [ "author_id" ]
}
}
},
"books_authors": {
"source": {
"object": "[dbo].[books_authors]",
"type": "table",
"key-fields": [
"book_id",
"author_id"
]
},
"graphql": {
"enabled": false,
"type": {
"singular": "books_authors",
"plural": "books_authors"
}
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "*"
}
]
}
]
}
}
}