Commit 8590aef
Full Title: Resolve `uniqueidentifier` database type from
`dab-config.json` defined stored proc parameter default values. (#2042)
## Why make this change?
- Closes #2027. DAB would not start up correctly when runtime config
took the following form:
```json
"entities": {
"SpUuidParam": {
"source": {
"object": "sp_uuid_param",
"type": "stored-procedure",
"parameters": {
"param1": "f58b7b58-62c9-4b97-ab60-75de70793f66"
}
},
"graphql": {
"enabled": true,
"operation": "Query",
"type": {
"singular": "SpUuidParam",
"plural": "SpUuidParams"
}
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [ "*" ]
},
{
"role": "authenticated",
"actions": [ "*" ]
}
]
}
```
And stored proc in tsql
```tsql
CREATE PROCEDURE [dbo].[sp_uuid_param] @param1 uniqueidentifier AS
SELECT @param1 AS [ReturnPayload]
```
DAB was lacking the ability to handle the stored procedure having an
input parameter with value type `uniqueidentifier`. When a default value
was defined in the config, that value would fail conversion to the UUID
type during GraphQL schema creation.
The call stack flows through:
```csharp
if (entity.Source.Parameters is not null && entity.Source.Parameters.TryGetValue(param, out object? value))
{
Tuple<string, IValueNode> defaultGraphQLValue = ConvertValueToGraphQLType(value.ToString()!, parameterDefinition: spdef.Parameters[param]);
defaultValueNode = defaultGraphQLValue.Item2;
}
```
where `ConvertValueToGraphQLType(...)` would attempt to convert the
config defined value to a GraphQL type based on the type inferred from
the parameter's SystemType (System.Guid). The parameter object has the
following properties when the parameter is passed to that function:
- SystemType -> `System.Guid`
- DbType -> `Guid`
- ConfigDefaultValue -> `f58b7b58-62c9-4b97-ab60-75de70793f66`
- HasConfigDefault -> `true`
`ConvertValueToGraphQLType(...)` did not have the conversion needed to
create a UUID type.
## What is this change?
- In the function called to process config defined default values for
stored procedure parameters, `ConvertValueToGraphQLType(...)` add the
conversion:
```csharp
UUID_TYPE => new(UUID_TYPE, new UuidType().ParseValue(Guid.Parse(defaultValueFromConfig))),
```
- Moved `ConvertValueToGraphQLType()` from `GraphQLUtils.cs` to
`GraphQLStoredProcedureBuilder.cs` to align with usage and purpose of
function. Reduces size of MEGA UTIL class. Also adds comment for
`GraphQLUtils.BuiltInTypes` hashset entry 'ID' to inform that it enables
CosmosDB functionality as only cosmos tests failed when that entry was
commented out.
- Reorganizes the ConvertValueToGraphQLType() order of types in switch
statements to align with GraphQLUtils.BuiltInTypes hashset. That way it
is easier to notice discrepancies in the two lists.
## How was this tested?
- [x] Integration Tests
## Sample Request(s)
- Use the db schema and entity config provided above. Startup will
succeed without conversion errors when attempting to create the GraphQL
schema.
Co-authored-by: Aniruddh Munde <[email protected]>
1 parent 36c3791 commit 8590aef
File tree
4 files changed
+63
-59
lines changed- src
- Service.GraphQLBuilder
- Service.Tests
- GraphQLBuilder/Sql
- SqlTests/GraphQLSupportedTypesTests
4 files changed
+63
-59
lines changedLines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
| 17 | + | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
| |||
122 | 129 | | |
123 | 130 | | |
124 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
125 | 180 | | |
126 | 181 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | | - | |
8 | 6 | | |
9 | 7 | | |
10 | | - | |
11 | 8 | | |
12 | 9 | | |
13 | | - | |
14 | 10 | | |
15 | 11 | | |
16 | 12 | | |
17 | | - | |
18 | | - | |
19 | 13 | | |
20 | 14 | | |
21 | 15 | | |
| |||
45 | 39 | | |
46 | 40 | | |
47 | 41 | | |
48 | | - | |
| 42 | + | |
49 | 43 | | |
50 | | - | |
| 44 | + | |
51 | 45 | | |
52 | 46 | | |
53 | 47 | | |
| |||
63 | 57 | | |
64 | 58 | | |
65 | 59 | | |
66 | | - | |
| 60 | + | |
67 | 61 | | |
68 | 62 | | |
69 | 63 | | |
| |||
224 | 218 | | |
225 | 219 | | |
226 | 220 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | 221 | | |
278 | 222 | | |
279 | 223 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
317 | 319 | | |
318 | 320 | | |
319 | 321 | | |
| |||
419 | 421 | | |
420 | 422 | | |
421 | 423 | | |
| 424 | + | |
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
| |||
0 commit comments