Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
800de2b
Add support for timespan
Aniruddh25 Mar 31, 2023
827ba69
Merge origin/main
Aniruddh25 May 4, 2023
0f12bd1
remove unused using
Aniruddh25 May 5, 2023
7367244
Add a case for TimeSpanType in ResolverMiddleware
Aniruddh25 May 5, 2023
221baad
enclose name in []
Aniruddh25 May 5, 2023
d210db2
Support timespan as stored procedure parameter
Aniruddh25 May 6, 2023
296511f
Parse with invariant culture and assume UTC
Aniruddh25 May 6, 2023
8c23ffe
StoredProc default paramvalue
Aniruddh25 May 6, 2023
b000168
TimeSpan Iso8601 format is PT23H59M59.999999S
Aniruddh25 May 7, 2023
1c35eb5
fixing tests
May 8, 2023
f9ab1d5
fixing MsSql tests
May 8, 2023
25c86a1
Merge remote changes
Aniruddh25 May 9, 2023
1dd0f47
Add timespan test in supported types
Aniruddh25 May 9, 2023
cd9ec5a
Fix timespan_types column name
Aniruddh25 May 9, 2023
efb3007
Merge branch 'main' into supportTimeSpan
abhishekkumams May 10, 2023
e80ef05
Fix comparison of timespan data type
Aniruddh25 May 11, 2023
1aa7b65
Missing else
Aniruddh25 May 11, 2023
d32a767
resolving merge conflicts
Jul 5, 2023
d5d97fd
adding timespan type
Jul 6, 2023
bb581ff
resolving merge conflicts
Jul 6, 2023
09e85b3
fix formatting
Jul 6, 2023
9923fc8
Merge branch 'main' into supportTimeSpan
Aniruddh25 Jul 12, 2023
3c4eba3
handling nullable types
Jul 17, 2023
507802e
resolving nits
Jul 17, 2023
eafb08e
Merge branch 'main' of https://github.com/Azure/data-api-builder into…
Jul 17, 2023
d852138
fixing sql type
Jul 18, 2023
b84874f
Add TimeOnly format for HotChocolate
Jul 20, 2023
9e1a93c
fix formatting
Jul 20, 2023
84e11e6
Update dab-config.MsSql.json
abhishekkumams Jul 20, 2023
5549e02
Merge branches 'supportTimeSpan' and 'supportTimeSpan' of https://git…
Jul 20, 2023
d8d8f26
Merge branch 'main' of https://github.com/Azure/data-api-builder into…
Jul 20, 2023
38a9e24
fix test
Jul 20, 2023
718941b
fixing mysql tests
Jul 20, 2023
910c2d7
fixing tests
Jul 21, 2023
5e01c3c
fix formatting
Jul 21, 2023
fc0be04
fixing tests
Jul 24, 2023
ebd7725
fixing tests
Jul 24, 2023
0d0b263
fixing tests
Jul 24, 2023
33edfaa
using Hotchocolate.Types.NodaTime
Jul 25, 2023
907723b
resolving conflicts
Jul 25, 2023
9883d87
fix formatting
Jul 26, 2023
a3e968e
fixing tests
Jul 26, 2023
de93200
adding tests
Jul 26, 2023
1840105
adding tests for different time format
Jul 26, 2023
0d0e1a3
Merge branch 'main' of https://github.com/Azure/data-api-builder into…
Jul 27, 2023
4a19378
using max dateTime in the test to check no overflow issue
Jul 27, 2023
a6fa28f
fixing PGSQL tests
Jul 27, 2023
a9c396d
fixing tests
Jul 27, 2023
bdb5fcc
fixing mysql tests
Jul 27, 2023
a38db0e
adding more tests
Jul 27, 2023
dec4d15
nit fixes
Jul 31, 2023
127af62
nit fix
Jul 31, 2023
7ff72b8
nit fix
Jul 31, 2023
2b55cd4
updating test
Jul 31, 2023
7694c60
Merge branch 'main' into supportTimeSpan
abhishekkumams Jul 31, 2023
a05134b
added OData tests as well
Aug 1, 2023
de2f48a
Update src/Service.Tests/SqlTests/GraphQLSupportedTypesTests/GraphQLS…
abhishekkumams Aug 4, 2023
9676493
Update src/Service.Tests/SqlTests/GraphQLSupportedTypesTests/GraphQLS…
abhishekkumams Aug 4, 2023
ecec68e
fix formatting and adding tests
Aug 4, 2023
0d27f42
resolving merge conflicts
Aug 4, 2023
30a1336
fixing tests
Aug 4, 2023
f126b83
Update src/Core/Services/TypeHelper.cs
abhishekkumams Aug 14, 2023
bd462fa
Handling datetime types
ayush3797 Aug 16, 2023
c849591
uncommitted changes
ayush3797 Aug 16, 2023
0869689
handling datetime
ayush3797 Aug 16, 2023
a4fbfed
reverting a change
ayush3797 Aug 16, 2023
55124cf
Merge with supportTimespan changes
ayush3797 Aug 16, 2023
bc5abb4
tests for datetime2
ayush3797 Aug 16, 2023
5b4a99c
Moving datetime2 tests to Mssql file
ayush3797 Aug 16, 2023
7ef116b
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Aug 17, 2023
46477e0
resolving conflicts
ayush3797 Aug 17, 2023
b6dc981
Merge branch 'dev/agarwalayush/bugWithHandlingTimeDataTypes' of https…
ayush3797 Aug 17, 2023
6783bdd
removing unintended change
ayush3797 Aug 17, 2023
77e9220
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Aug 21, 2023
f8e184e
undoing changes from time pr
ayush3797 Aug 21, 2023
976f4e7
build fix
ayush3797 Aug 21, 2023
4de8f1e
filter tests for datetime types specific to msssql
ayush3797 Aug 21, 2023
5ab415e
get by pk for REST
ayush3797 Aug 21, 2023
077a265
moving tests to one place
ayush3797 Aug 21, 2023
fce32e0
fixing snapshots
ayush3797 Aug 21, 2023
8dd5b60
updating configs
ayush3797 Aug 21, 2023
452f7f9
adding tests
ayush3797 Aug 21, 2023
7e56126
adding tests
ayush3797 Aug 21, 2023
59dba5c
some cleanup
ayush3797 Aug 21, 2023
49d415e
adding more tests
ayush3797 Aug 21, 2023
1eea2dd
removing dup code
ayush3797 Aug 22, 2023
c259d69
adding back tests
ayush3797 Aug 22, 2023
cc6c616
adding more tests
ayush3797 Aug 22, 2023
f982e2d
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Aug 24, 2023
7ebf6ba
Addressing review + allowing z notation
ayush3797 Aug 24, 2023
f29c8c9
formatting fix
ayush3797 Aug 24, 2023
f9f5ee2
updating parsing logic
ayush3797 Oct 10, 2023
955033c
merge with main
ayush3797 Oct 10, 2023
9e3d009
formatting fix
ayush3797 Oct 10, 2023
d7f6c87
formatting fix
ayush3797 Oct 10, 2023
c61e91a
Adding conditional to populate dbtype for datetime/datetimeoffset typ…
ayush3797 Oct 30, 2023
c688226
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Oct 30, 2023
93794d5
adding test for z notation insertions
ayush3797 Nov 1, 2023
d72e69e
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Nov 16, 2023
661e271
addressing review
ayush3797 Nov 16, 2023
8dc9b41
Addressing review/ renaming class
ayush3797 Nov 16, 2023
2ac6608
added more tests
ayush3797 Nov 16, 2023
9cd00cf
renaming class/fixing build failure due to extended new() declaration
ayush3797 Nov 29, 2023
9b5f379
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Nov 29, 2023
3d42007
moving back constant/correct test displaynames
ayush3797 Dec 5, 2023
3322c6e
Moving mssql specific code to its class
ayush3797 Dec 5, 2023
b527f17
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Dec 5, 2023
89b93ed
fixing build failures
ayush3797 Dec 5, 2023
b3f0f07
ignoring datetime test for dwsql for now
ayush3797 Dec 5, 2023
1f4802b
Merge branch 'main' into dev/agarwalayush/bugWithHandlingTimeDataTypes
ayush3797 Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config-generators/mssql-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add Broker --config "dab-config.MsSql.json" --source brokers --permissions "anon
add WebsiteUser --config "dab-config.MsSql.json" --source website_users --permissions "anonymous:create,read,delete,update"
add SupportedType --config "dab-config.MsSql.json" --source type_table --permissions "anonymous:create,read,delete,update"
add stocks_price --config "dab-config.MsSql.json" --source stocks_price --permissions "authenticated:create,read,update,delete"
update stocks_price --config "dab-config.MsSql.json" --permissions "anonymous:read"
update stocks_price --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_ColumnForbidden:read" --fields.exclude "price"
update stocks_price --config "dab-config.MsSql.json" --permissions "TestNestedFilterFieldIsNull_EntityReadForbidden:create"
add Tree --config "dab-config.MsSql.json" --source trees --permissions "anonymous:create,read,update,delete"
Expand Down
2 changes: 1 addition & 1 deletion config-generators/mysql-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ update BookWebsitePlacement --config "dab-config.MySql.json" --permissions "auth
update BookWebsitePlacement --config "dab-config.MySql.json" --permissions "authenticated:delete" --fields.include "*" --policy-database "@claims.userId eq @item.id"
update Author --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true
update WebsiteUser --config "dab-config.MySql.json" --permissions "authenticated:create,read,delete,update" --rest false --graphql "websiteUser:websiteUsers"
update stocks_price --config "dab-config.MySql.json" --permissions "authenticated:create,read,delete,update" --rest false
Comment thread
ayush3797 marked this conversation as resolved.
update stocks_price --config "dab-config.MySql.json" --permissions "authenticated:create,read,delete,update" --rest true
Comment thread
ayush3797 marked this conversation as resolved.
update Comic --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship myseries --target.entity series --cardinality one
update series --config "dab-config.MySql.json" --relationship comics --target.entity Comic --cardinality many
update Broker --config "dab-config.MySql.json" --permissions "authenticated:create,update,read,delete" --graphql false
Expand Down
1 change: 1 addition & 0 deletions config-generators/postgresql-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add Broker --config "dab-config.PostgreSql.json" --source brokers --permissions
add WebsiteUser --config "dab-config.PostgreSql.json" --source website_users --permissions "anonymous:create,read,delete,update"
add SupportedType --config "dab-config.PostgreSql.json" --source type_table --permissions "anonymous:create,read,delete,update"
add stocks_price --config "dab-config.PostgreSql.json" --source stocks_price --permissions "authenticated:create,read,update,delete"
update stocks_price --config "dab-config.PostgreSql.json" --permissions "anonymous:read"
update stocks_price --config "dab-config.PostgreSql.json" --permissions "TestNestedFilterFieldIsNull_ColumnForbidden:read" --fields.exclude "price"
update stocks_price --config "dab-config.PostgreSql.json" --permissions "TestNestedFilterFieldIsNull_EntityReadForbidden:create"
add Tree --config "dab-config.PostgreSql.json" --source trees --permissions "anonymous:create,read,update,delete"
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Models/GraphQLFilterParsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public static Predicate Parse(
new PredicateOperand(column),
op,
new PredicateOperand(processLiteral ? $"{processLiterals(value, column.ColumnName)}" : value.ToString()))
));
));
}

return GQLFilterParser.MakeChainPredicate(predicates, PredicateOperation.AND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ protected static object ParseParamAsSystemType(string param, Type systemType)
"Double" => double.Parse(param),
"Decimal" => decimal.Parse(param),
"Boolean" => bool.Parse(param),
"DateTime" => DateTimeOffset.Parse(param, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal),
"DateTime" => DateTimeOffset.Parse(param, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal).DateTime,
"DateTimeOffset" => DateTimeOffset.Parse(param, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal),
"Date" => DateOnly.Parse(param),
"Guid" => Guid.Parse(param),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public void AddPaginationPredicate(IEnumerable<PaginationColumn> afterJsonValues
{
column.TableAlias = SourceAlias;
column.ParamName = column.Value is not null ?
MakeDbConnectionParam(GetParamAsSystemType(column.Value!.ToString()!, column.ColumnName, GetColumnSystemType(column.ColumnName))) :
MakeDbConnectionParam(GetParamAsSystemType(column.Value!.ToString()!, column.ColumnName, GetColumnSystemType(column.ColumnName)), column.ColumnName) :
MakeDbConnectionParam(null, column.ColumnName);
}

Expand Down
156 changes: 156 additions & 0 deletions src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
// Licensed under the MIT License.

using System.Data;
using System.Data.Common;
using System.Net;
using System.Text.Json;
using System.Text.Json.Nodes;
using Azure.DataApiBuilder.Config.DatabasePrimitives;
using Azure.DataApiBuilder.Config.ObjectModel;
using Azure.DataApiBuilder.Core.Configurations;
using Azure.DataApiBuilder.Core.Models;
using Azure.DataApiBuilder.Core.Resolvers;
using Azure.DataApiBuilder.Core.Resolvers.Factories;
using Azure.DataApiBuilder.Service.Exceptions;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using static Azure.DataApiBuilder.Service.GraphQLBuilder.GraphQLNaming;

namespace Azure.DataApiBuilder.Core.Services
{
Expand Down Expand Up @@ -80,5 +85,156 @@ public override async Task PopulateTriggerMetadataForTable(string entityName, st
}
}
}

/// <inheritdoc/>
protected override void PopulateColumnDefinitionWithHasDefaultAndDbType(
SourceDefinition sourceDefinition,
DataTable allColumnsInTable)
{
foreach (DataRow columnInfo in allColumnsInTable.Rows)
{
string columnName = (string)columnInfo["COLUMN_NAME"];
bool hasDefault =
Type.GetTypeCode(columnInfo["COLUMN_DEFAULT"].GetType()) != TypeCode.DBNull;
if (sourceDefinition.Columns.TryGetValue(columnName, out ColumnDefinition? columnDefinition))
{
columnDefinition.HasDefault = hasDefault;
Comment thread
ayush3797 marked this conversation as resolved.

if (hasDefault)
{
columnDefinition.DefaultValue = columnInfo["COLUMN_DEFAULT"];
}

columnDefinition.DbType = TypeHelper.GetDbTypeFromSystemType(columnDefinition.SystemType);
if (columnDefinition.SystemType == typeof(DateTime) || columnDefinition.SystemType == typeof(DateTimeOffset))
{
// MsSql types like date,smalldatetime,datetime,datetime2 are mapped to the same .NET type of DateTime.
// Thus to determine the actual dbtype, we use the underlying MsSql type instead of the .NET type.
DbType dbType;
string sqlType = (string)columnInfo["DATA_TYPE"];
if (TryResolveDbType(sqlType, out dbType))
{
columnDefinition.DbType = dbType;
}
}
}
}
}

/// <inheritdoc/>
protected override async Task FillSchemaForStoredProcedureAsync(
Entity procedureEntity,
string entityName,
string schemaName,
string storedProcedureSourceName,
StoredProcedureDefinition storedProcedureDefinition)
{
using DbConnection conn = new SqlConnection();
Comment thread
ayush3797 marked this conversation as resolved.
conn.ConnectionString = ConnectionString;
await QueryExecutor.SetManagedIdentityAccessTokenIfAnyAsync(conn, _dataSourceName);
await conn.OpenAsync();

string[] procedureRestrictions = new string[NUMBER_OF_RESTRICTIONS];

// To restrict the parameters for the current stored procedure, specify its name
procedureRestrictions[0] = conn.Database;
procedureRestrictions[1] = schemaName;
procedureRestrictions[2] = storedProcedureSourceName;

DataTable procedureMetadata = await conn.GetSchemaAsync(collectionName: "Procedures", restrictionValues: procedureRestrictions);

// Stored procedure does not exist in DB schema
if (procedureMetadata.Rows.Count == 0)
{
throw new DataApiBuilderException(
message: $"No stored procedure definition found for the given database object {storedProcedureSourceName}",
statusCode: HttpStatusCode.ServiceUnavailable,
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
}

// Each row in the procedureParams DataTable corresponds to a single parameter
DataTable parameterMetadata = await conn.GetSchemaAsync(collectionName: "ProcedureParameters", restrictionValues: procedureRestrictions);

// For each row/parameter, add an entry to StoredProcedureDefinition.Parameters dictionary
foreach (DataRow row in parameterMetadata.Rows)
{
// row["DATA_TYPE"] has value type string so a direct cast to System.Type is not supported.
Comment thread
ayush3797 marked this conversation as resolved.
// See https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings
string sqlType = (string)row["DATA_TYPE"];
Type systemType = SqlToCLRType(sqlType);
ParameterDefinition paramDefinition = new()
{
SystemType = systemType,
DbType = TypeHelper.GetDbTypeFromSystemType(systemType)
};

if (paramDefinition.SystemType == typeof(DateTime) || paramDefinition.SystemType == typeof(DateTimeOffset))
{
// MsSql types like date,smalldatetime,datetime,datetime2 are mapped to the same .NET type of DateTime.
// Thus to determine the actual dbtype, we use the underlying MsSql type instead of the .NET type.
DbType dbType;
if (TryResolveDbType(sqlType, out dbType))
{
paramDefinition.DbType = dbType;
}
}

// Add to parameters dictionary without the leading @ sign
storedProcedureDefinition.Parameters.TryAdd(((string)row["PARAMETER_NAME"])[1..], paramDefinition);
}

// Loop through parameters specified in config, throw error if not found in schema
// else set runtime config defined default values.
// Note: we defer type checking of parameters specified in config until request time
Dictionary<string, object>? configParameters = procedureEntity.Source.Parameters;
Comment thread
ayush3797 marked this conversation as resolved.
if (configParameters is not null)
{
foreach ((string configParamKey, object configParamValue) in configParameters)
{
if (!storedProcedureDefinition.Parameters.TryGetValue(configParamKey, out ParameterDefinition? parameterDefinition))
{
throw new DataApiBuilderException(
message: $"Could not find parameter \"{configParamKey}\" specified in config for procedure \"{schemaName}.{storedProcedureSourceName}\"",
statusCode: HttpStatusCode.ServiceUnavailable,
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
}
else
{
parameterDefinition.HasConfigDefault = true;
parameterDefinition.ConfigDefaultValue = configParamValue?.ToString();
}
}
}

// Generating exposed stored-procedure query/mutation name and adding to the dictionary mapping it to its entity name.
GraphQLStoredProcedureExposedNameToEntityNameMap.TryAdd(GenerateStoredProcedureGraphQLFieldName(entityName, procedureEntity), entityName);
}

/// <summary>
/// Takes a string version of a sql date/time type and returns its corresponding DbType.
/// </summary>
/// <param name="sqlDbTypeName">Name of the sqlDbType.<</param>
/// <param name="dbType">DbType of the parameter corresponding to its sqlDbTypeName.</param>
/// <returns>Returns true when the given sqlDbTypeName datetime type is supported by DAB and resolve it to its corresponding DbType, else false.</returns>
private bool TryResolveDbType(string sqlDbTypeName, out DbType dbType)
{
if (Enum.TryParse(sqlDbTypeName, ignoreCase: true, out SqlDbType sqlDbType))
{
// For MsSql, all the date time types i.e. date, smalldatetime, datetime, datetime2 map to System.DateTime system type.
// Hence we cannot directly determine the DbType from the system type.
// However, to make sure that the database correctly interprets these datatypes, it is necessary to correctly
// populate the DbTypes.
return TypeHelper.TryGetDbTypeFromSqlDbDateTimeType(sqlDbType, out dbType);
}
else
{
// This code should never be hit because every sqlDbTypeName must have a corresponding sqlDbType.
// However, when a new data type is introduced in MsSql which maps to .NET type of DateTime, this code block
// will be hit. Returning false instead of throwing an exception in that case prevents the engine from crashing.
_logger.LogWarning("Could not determine DbType for SqlDb type of {sqlDbTypeName}", sqlDbTypeName);
dbType = 0;
return false;
}
}
}
}
34 changes: 18 additions & 16 deletions src/Core/Services/MetadataProviders/SqlMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class SqlMetadataProvider<ConnectionT, DataAdapterT, CommandT> :

protected IQueryExecutor QueryExecutor { get; }

private const int NUMBER_OF_RESTRICTIONS = 4;
protected const int NUMBER_OF_RESTRICTIONS = 4;

protected string ConnectionString { get; init; }

Expand Down Expand Up @@ -320,7 +320,7 @@ private void LogPrimaryKeys()
/// <summary>
/// Verify that the stored procedure exists in the database schema, then populate its database object parameters accordingly
/// </summary>
private async Task FillSchemaForStoredProcedureAsync(
protected virtual async Task FillSchemaForStoredProcedureAsync(
Entity procedureEntity,
string entityName,
string schemaName,
Expand Down Expand Up @@ -374,15 +374,16 @@ private async Task FillSchemaForStoredProcedureAsync(
{
// row["DATA_TYPE"] has value type string so a direct cast to System.Type is not supported.
// See https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings
Type systemType = SqlToCLRType((string)row["DATA_TYPE"]);
string sqlType = (string)row["DATA_TYPE"];
Type systemType = SqlToCLRType(sqlType);
ParameterDefinition paramDefinition = new()
{
SystemType = systemType,
DbType = TypeHelper.GetDbTypeFromSystemType(systemType)
};

// Add to parameters dictionary without the leading @ sign
storedProcedureDefinition.Parameters.TryAdd(((string)row["PARAMETER_NAME"])[1..],
new()
{
SystemType = systemType,
DbType = TypeHelper.GetDbTypeFromSystemType(systemType)
}
);
storedProcedureDefinition.Parameters.TryAdd(((string)row["PARAMETER_NAME"])[1..], paramDefinition);
Comment thread
ayush3797 marked this conversation as resolved.
}

// Loop through parameters specified in config, throw error if not found in schema
Expand Down Expand Up @@ -1097,13 +1098,11 @@ private async Task PopulateSourceDefinitionAsync(
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
}

Type systemTypeOfColumn = (Type)columnInfoFromAdapter["DataType"];
ColumnDefinition column = new()
{
IsNullable = (bool)columnInfoFromAdapter["AllowDBNull"],
IsAutoGenerated = (bool)columnInfoFromAdapter["IsAutoIncrement"],
SystemType = systemTypeOfColumn,
DbType = TypeHelper.GetDbTypeFromSystemType(systemTypeOfColumn),
SystemType = (Type)columnInfoFromAdapter["DataType"],
// An auto-increment column is also considered as a read-only column. For other types of read-only columns,
// the flag is populated later via PopulateColumnDefinitionsWithReadOnlyFlag() method.
IsReadOnly = (bool)columnInfoFromAdapter["IsAutoIncrement"]
Expand All @@ -1117,7 +1116,8 @@ private async Task PopulateSourceDefinitionAsync(
}

DataTable columnsInTable = await GetColumnsAsync(schemaName, tableName);
PopulateColumnDefinitionWithHasDefault(

PopulateColumnDefinitionWithHasDefaultAndDbType(
sourceDefinition,
columnsInTable);

Expand Down Expand Up @@ -1400,9 +1400,9 @@ protected virtual async Task<DataTable> GetColumnsAsync(
}

/// <summary>
/// Populates the column definition with HasDefault property.
/// Helper method to populate the column definition with HasDefault and DbType properties.
/// </summary>
private static void PopulateColumnDefinitionWithHasDefault(
protected virtual void PopulateColumnDefinitionWithHasDefaultAndDbType(
SourceDefinition sourceDefinition,
DataTable allColumnsInTable)
{
Expand All @@ -1419,6 +1419,8 @@ private static void PopulateColumnDefinitionWithHasDefault(
{
columnDefinition.DefaultValue = columnInfo["COLUMN_DEFAULT"];
}

columnDefinition.DbType = TypeHelper.GetDbTypeFromSystemType(columnDefinition.SystemType);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Services/ResolverMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using NodaTime.Text;
using static Azure.DataApiBuilder.Service.GraphQLBuilder.GraphQLTypes.SupportedTypes;
using static Azure.DataApiBuilder.Service.GraphQLBuilder.GraphQLTypes.SupportedHotChocolateTypes;

namespace Azure.DataApiBuilder.Core.Services
{
Expand Down
Loading