Azure / Azure/data-api-builder

[Bug]: Issue adding Stored Procedures (Azure Cosmos DB / NoSQL / GraphQL)

Open
#1,915 4 comments 0 reactions 1 assignee Claimed by @sajeetharan View on GitHub
bug cosmos nosql triage
Dominant language
C#
Stars
1.5k
Forks
370
Avg merge
3d 17h
Merged PRs (30d)
8

Description

### What happened?

Following the instructions [here](https://learn.microsoft.com/en-us/azure/data-api-builder/views-and-stored-procedures#graphql-support-for-stored-procedures), we've run into issues registering a stored procedure with DAB.

Within Azure Cosmos DB, NoSQL, there's a container called "Persons"
Attached to the container is a Stored Process called "DefaultStoredProc"

We've the following command to register the Stored Proc:

```bash
dab add DefaultStoredProc --source Persons.DefaultStoredProc --source.type "stored-procedure" --source.params "searchType:s" --permissions "anonymous:execute" --rest.methods "get" --graphql.operation "query" -c "[locationOfConfigFile].json"
```

That command populates the config file with the below:
```json
"DefaultStoredProc": {
"source": {
"object": "Persons.DefaultStoredProc",
"type": "stored-procedure",
"parameters": {
"searchType": "s"
}
},
"graphql": {
"enabled": true,
"operation": "query",
"type": {
"singular": "DefaultStoredProc",
"plural": "DefaultStoredProcs"
}
},
"rest": {
"enabled": false,
"methods": [
"post"
]
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "execute"
}
]
}
]
}
```

Nothing is created in the schema.gql file.

When we run this, using `dab start` (or `swa start`) we get the following error - `System.Collections.Generic.KeyNotFoundException: The given key 'DefaultStoredProc' was not present in the dictionary.`

Any and all advice greatly appreciated!

TY, Rich

### Version

0.9.7

### What database are you using?

CosmosDB NoSQL

### What hosting model are you using?

Local (including CLI)

### Which API approach are you accessing DAB through?

GraphQL

### Relevant log output

```Text
$ dab start -c .\staticwebapp.database.config.json

Information: Microsoft.DataApiBuilder 0.9.7+e560142426d1c080b9fd7b7fabff51a276f6bf61
Information: User provided config file: .\staticwebapp.database.config.json
Loading config file from .\staticwebapp.database.config.json.
Information: Loaded config file: .\staticwebapp.database.config.json
Information: Setting default minimum LogLevel: Error for Production mode.
Starting the runtime engine...
Loading config file from .\staticwebapp.database.config.json.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
User profile is available. Using 'C:\Users\jacks\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
fail: Azure.DataApiBuilder.Service.Startup[0]
Unable to complete runtime initialization. Refer to exception for error details.
System.Collections.Generic.KeyNotFoundException: The given key 'DefaultStoredProc' was not present in the dictionary.
at Azure.DataApiBuilder.Core.Configurations.RuntimeConfigValidator.ValidateStoredProceduresInConfig(RuntimeConfig runtimeConfig, ISqlMetadataProvider sqlMetadataProvider)
at Azure.DataApiBuilder.Service.Startup.PerformOnConfigChangeAsync(IApplicationBuilder app)
fail: Azure.DataApiBuilder.Service.Startup[0]
Could not initialize the engine with the runtime config file: .\staticwebapp.database.config.json
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
Unable to launch the Data API builder engine.
Error: Failed to start the engine.
```

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.