-
Notifications
You must be signed in to change notification settings - Fork 279
Resolve uniqueidentifier
database type from dab-config.json
defined stored proc parameter default values.
#2042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…resolve dabconfig provided default parameter value to resolve as a GraphQL/HotChocolate UUID and SystemType.Guid, which will allow startup to finish without error. Add unit test checking the affirmative and test to ensure db type string with dabconfig value looking like a GUID gets resolved as string
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion to include test cases with different UUID formats. Otherwise, looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the quick fix!
…dProcedureBuilder to align with usage and purpose of function. Reduces size of MEGA UTIL class. Also adds comment for BuiltInTypes hashset entry 'ID' to inform that it enables CosmosDB functionality as only cosmos tests failed when that entry was commented out. Also reorganizes the ConvertValueToGraphQLType() order of types in switch statements to align with GraphQLUtils.BuiltInTypes hashset.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
…that the message on console when an exception is caught is readable.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
…ed 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>
…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>
Why make this change?
And stored proc in tsql
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:
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:System.Guid
Guid
f58b7b58-62c9-4b97-ab60-75de70793f66
true
ConvertValueToGraphQLType(...)
did not have the conversion needed to create a UUID type.What is this change?
ConvertValueToGraphQLType(...)
add the conversion:ConvertValueToGraphQLType()
fromGraphQLUtils.cs
toGraphQLStoredProcedureBuilder.cs
to align with usage and purpose of function. Reduces size of MEGA UTIL class. Also adds comment forGraphQLUtils.BuiltInTypes
hashset entry 'ID' to inform that it enables CosmosDB functionality as only cosmos tests failed when that entry was commented out.How was this tested?
Sample Request(s)