Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
879 stars 179 forks source link

SWA : Response status code does not indicate success: 400 #2239

Open Shaun-t opened 4 months ago

Shaun-t commented 4 months ago

What happened?

Hi, I'm tying to expose a table (azure SQL) using DAB. followed the documentation closely and I'm getting

_

Response status code does not indicate success: 400 (Bad Request)

_

when I make the Post call : https://white-plant-xxxxxx.5.azurestaticapps.net/data-api/graphql/Mytable

azure SQL is being access using SWA managed identity and all the permission are granted. when I profile SQL I see the connection from SWA, however I still get the 400 error message

image

image

here is how I defined staticwebapp.database.config.json

{ "$schema": "https://github.com/Azure/data-api-builder/releases/download/v0.9.7/dab.draft.schema.json", "data-source": { "database-type": "mssql", "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": ["https://xxxxx.5.azurestaticapps.net/"], "allow-credentials": false }, "authentication": { "provider": "StaticWebApps" }, "mode": "production" } }, "entities": { "Mytable": { "source": { "object": "dbo.test", "type": "table" }, "graphql": { "enabled": true, "type": { "singular": "Mytable", "plural": "Mytables" } }, "rest": { "enabled": true }, "permissions": [ { "role": "anonymous", "actions": [ { "action": "*" } ] } ] } } }

Version

1.1.7+74ea6c5f37f8629fd7f8b13fc56027bf0bf0a93a

What database are you using?

Azure SQL

What hosting model are you using?

Static Web Apps (SWA)

Which API approach are you accessing DAB through?

REST

Relevant log output

{"Message":"{\u0022Message\u0022:\u0022Response status code does not indicate success: 400 (Bad Request).\u0022,\u0022ActivityId\u0022:\u0022e9510a6f-d5f2-43ec-aebc-1acf9a72f1db\u0022}","ActivityId":"e9510a6f-d5f2-43ec-aebc-1acf9a72f1db"}

Code of Conduct

Shaun-t commented 4 months ago

update : after more digging noticed that the table required Primary key. however after introducing PK now I'm getting

{"error":{"code":"BadRequest","message":"Invalid request body. Missing field in body: IDs.","status":400}}

I profiled and noticed that SWA is running the following

exec sp_executesql N'SELECT ifsc.column_name from sys.columns as sc INNER JOIN information_schema.columns as ifsc ON (sc.is_computed = 1 or ifsc.data_type = ''timestamp'') AND sc.object_id = object_id(@param0+''.''+@param1) and ifsc.table_name = @param1 AND ifsc.table_schema = @param0 and ifsc.column_name = sc.name;',N'@param0 nvarchar(3),@param1 nvarchar(4)',@param0=N'dbo',@param1=N'test'

seantleonard commented 4 months ago

To help with repro, can you provide example table schema and contents of your POST request body?

Request should be:

POST  https://white-plant-xxxxxx.5.azurestaticapps.net/data-api/graphql/Mytable

with JSON request body:

{
 "primaryKeyName": "Value",
 "requiredField": "RequiredFieldValue"
}