-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cherry pick] Resolve
uniqueidentifier
database type from `dab-conf…
…ig.json` (#2075) 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 <anmunde@microsoft.com>
- Loading branch information
1 parent
36c3791
commit 8590aef
Showing
4 changed files
with
63 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters