Replies: 5 comments 1 reply
-
Yes and in the doc-reference : the sample uses |
Beta Was this translation helpful? Give feedback.
-
Workarround in TSQL/ Azure SQL, use OPENJSON: create procedure SampleNullableTest(
@supplierId int = 0,
@extrargs nvarchar(MAX)
) as
begin
declare @catalogId int = isnull((select top 1 catalogId from OPENJSON(@extrargs, '$') with ( catalogId int)),
null)
select @supplierId as couldBeNullEvenIfDefaultValue, @catalogId as catalogIdNullableFromDataAPI
end
GO
exec dbo.SampleNullable @supplierId =10, @extrargs='{"catalogId" : 11}'
-- output
-- couldBeNullEvenIfDefaultValue=11
-- catalogIdNullableFromDabCall=10
GO
exec dbo.SampleNullable @supplierId =null, @extrargs='{}'
-- output
-- couldBeNullEvenIfDefaultValue=null
-- catalogIdNullableFromDabCall=null
GO |
Beta Was this translation helpful? Give feedback.
-
the entity definition: "SampleNullableTest": {
"source": {
"object": "dbo.SampleNullableTest",
"type": "stored-procedure",
"parameters": {
"supplierId": 0,
"extrargs": "{}"
}
},
"graphql": {
"enabled": true,
"operation": "mutation",
"type": {
"singular": "UpsertCatalog",
"plural": "UpsertCatalogs"
}
},
"permissions": [
{
"role": "authenticated",
"actions": [
{
"action": "execute"
}
]
}
]
}, call return this.qlclient.mutate<{ executecreateSupplier: { supplierId: string }[] }>({
mutation: gql`
mutation SampleNullableTest($supplierId: Int!, $payload: String!) {
executeSampleNullableTest(supplierId: $supplierId, payload: $payload) {
catalogId
}
}`,
variables: {
supplierId : 10,
extrargs : $extrargs
}
}
) define extrargs as you need :
|
Beta Was this translation helpful? Give feedback.
-
I tried something new today. |
Beta Was this translation helpful? Give feedback.
-
I opened a PR to attempt to address this issue. As a result, no need to define all params in request, nor define 'null' default values in the dab config. With the code changes, DAB would still check whether you are supplying correct param names and datatypes, but defers to the database to determine whether all required parameters were supplied with values. This should mitigate dab crashing at startup or during request time and having to come up with workaround (sorry about that!) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a stored procedure with optional parameters that takes null as the default value. Example:
As DAB is not able to detect those parameters today (and because of #1748?), I have to duplicate those parameters in the config file to avoid the
Invalid request. Missing required procedure parameters
when using the REST endpoint without some optional parameters.According to the DAB config file schema definition, a parameter can be a boolean, a string or a number but can't be null:
I tried to use null anyway in my config file but got the error below with dab validate:
When using the CLI to declare the stored proc, null is converted in "null" in the config file:
dab add MyStoredProc --source dbo.MyStoredProc --source.type "stored-procedure" --source.params "OptionalParam1:null,OptionalParam2:null,OptionalParam3:null,OptionalParam4:null" --permissions "anonymous:execute" --rest.methods "get" --graphql.operation "query"
And with "null" as the default value, I am getting the following error at runtime which is logic:
How to define null as the default value of a stored procedure parameter?
Beta Was this translation helpful? Give feedback.
All reactions