diff --git a/docs/mdsource/query-usage.source.md b/docs/mdsource/query-usage.source.md index 4e77b3664..345d53209 100644 --- a/docs/mdsource/query-usage.source.md +++ b/docs/mdsource/query-usage.source.md @@ -54,7 +54,31 @@ All where statements require a `path`. This is a full path to a, possible nested #### Supported Types -[String](https://docs.microsoft.com/en-us/dotnet/api/system.string), [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid), [Double](https://docs.microsoft.com/en-us/dotnet/api/system.double), [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean), [Float](https://docs.microsoft.com/en-us/dotnet/api/system.float), [Byte](https://docs.microsoft.com/en-us/dotnet/api/system.byte), [DateTime](https://docs.microsoft.com/en-us/dotnet/api/system.datetime), [DateTimeOffset](https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset), [Decimal](https://docs.microsoft.com/en-us/dotnet/api/system.decimal), [Int16](https://docs.microsoft.com/en-us/dotnet/api/system.int16), [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32), [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64), [UInt16](https://docs.microsoft.com/en-us/dotnet/api/system.uint16), [UInt32](https://docs.microsoft.com/en-us/dotnet/api/system.uint32), [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64), and [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum). +[String](https://docs.microsoft.com/en-us/dotnet/api/system.string), [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid), [Double](https://docs.microsoft.com/en-us/dotnet/api/system.double), [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean), [Float](https://docs.microsoft.com/en-us/dotnet/api/system.float), [Byte](https://docs.microsoft.com/en-us/dotnet/api/system.byte), [DateTime](https://docs.microsoft.com/en-us/dotnet/api/system.datetime), [DateOnly](https://docs.microsoft.com/en-us/dotnet/api/system.dateonly), [TimeOnly](https://docs.microsoft.com/en-us/dotnet/api/system.timeonly), [DateTimeOffset](https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset), [Decimal](https://docs.microsoft.com/en-us/dotnet/api/system.decimal), [Int16](https://docs.microsoft.com/en-us/dotnet/api/system.int16), [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32), [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64), [UInt16](https://docs.microsoft.com/en-us/dotnet/api/system.uint16), [UInt32](https://docs.microsoft.com/en-us/dotnet/api/system.uint32), [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64), and [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum). + + +##### TimeOnly query + +``` +{ + timeEntities (where: {path: 'Property', comparison: equal, value: '10:11 AM'}) + { + id + } +} +``` + + +##### DateOnly query + +``` +{ + dateEntities (where: {path: 'Property', comparison: equal, value: '2020-10-1'}) + { + id + } +} +``` #### Supported Comparisons diff --git a/docs/query-usage.md b/docs/query-usage.md index ba20f0d1f..727775fe7 100644 --- a/docs/query-usage.md +++ b/docs/query-usage.md @@ -61,7 +61,31 @@ All where statements require a `path`. This is a full path to a, possible nested #### Supported Types -[String](https://docs.microsoft.com/en-us/dotnet/api/system.string), [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid), [Double](https://docs.microsoft.com/en-us/dotnet/api/system.double), [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean), [Float](https://docs.microsoft.com/en-us/dotnet/api/system.float), [Byte](https://docs.microsoft.com/en-us/dotnet/api/system.byte), [DateTime](https://docs.microsoft.com/en-us/dotnet/api/system.datetime), [DateTimeOffset](https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset), [Decimal](https://docs.microsoft.com/en-us/dotnet/api/system.decimal), [Int16](https://docs.microsoft.com/en-us/dotnet/api/system.int16), [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32), [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64), [UInt16](https://docs.microsoft.com/en-us/dotnet/api/system.uint16), [UInt32](https://docs.microsoft.com/en-us/dotnet/api/system.uint32), [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64), and [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum). +[String](https://docs.microsoft.com/en-us/dotnet/api/system.string), [Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid), [Double](https://docs.microsoft.com/en-us/dotnet/api/system.double), [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean), [Float](https://docs.microsoft.com/en-us/dotnet/api/system.float), [Byte](https://docs.microsoft.com/en-us/dotnet/api/system.byte), [DateTime](https://docs.microsoft.com/en-us/dotnet/api/system.datetime), [DateOnly](https://docs.microsoft.com/en-us/dotnet/api/system.dateonly), [TimeOnly](https://docs.microsoft.com/en-us/dotnet/api/system.timeonly), [DateTimeOffset](https://docs.microsoft.com/en-us/dotnet/api/system.datetimeoffset), [Decimal](https://docs.microsoft.com/en-us/dotnet/api/system.decimal), [Int16](https://docs.microsoft.com/en-us/dotnet/api/system.int16), [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32), [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64), [UInt16](https://docs.microsoft.com/en-us/dotnet/api/system.uint16), [UInt32](https://docs.microsoft.com/en-us/dotnet/api/system.uint32), [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64), and [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum). + + +##### TimeOnly query + +``` +{ + timeEntities (where: {path: 'Property', comparison: equal, value: '10:11 AM'}) + { + id + } +} +``` + + +##### DateOnly query + +``` +{ + dateEntities (where: {path: 'Property', comparison: equal, value: '2020-10-1'}) + { + id + } +} +``` #### Supported Comparisons diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c70f70980..dc2bdf56d 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;NU5104;CS1573 - 21.2.0 + 21.3.0 1.0.0 EntityFrameworkCore, EntityFramework, GraphQL true diff --git a/src/GraphQL.EntityFramework/Where/ExpressionBuilder.cs b/src/GraphQL.EntityFramework/Where/ExpressionBuilder.cs index cabf35126..db28a92c4 100644 --- a/src/GraphQL.EntityFramework/Where/ExpressionBuilder.cs +++ b/src/GraphQL.EntityFramework/Where/ExpressionBuilder.cs @@ -119,7 +119,14 @@ static Expression ProcessList(string path, Comparison comparison, string?[]? val .MakeGenericType(listItemType) .GetMethods(BindingFlags.Public | BindingFlags.Static) .Single(m => m.Name == "BuildPredicate" && m.GetParameters().Length == 5) - .Invoke(new(), new object[] { listPath, comparison, values!, false, stringComparison! })!; + .Invoke(new(), new object[] + { + listPath, + comparison, + values!, + false, + stringComparison! + })!; // Generate a method info for the Any Enumerable Static Method var anyInfo = typeof(Enumerable) @@ -142,7 +149,7 @@ static Expression GetExpression(string path, Comparison comparison, string?[]? v { case Comparison.NotIn: WhereValidator.ValidateString(comparison, stringComparison); - expressionBody = NegateExpression(MakeStringListInComparison(values!, property, stringComparison)); // Ensure expression is negated + expressionBody = NegateExpression(MakeStringListInComparison(values!, property, stringComparison)); // Ensure expression is negated break; case Comparison.In: WhereValidator.ValidateString(comparison, stringComparison); @@ -162,7 +169,7 @@ static Expression GetExpression(string path, Comparison comparison, string?[]? v { case Comparison.NotIn: WhereValidator.ValidateObject(property.PropertyType, comparison, stringComparison); - expressionBody = NegateExpression(MakeObjectListInComparision(values!, property)); // Ensure expression is negated + expressionBody = NegateExpression(MakeObjectListInComparision(values!, property)); break; case Comparison.In: WhereValidator.ValidateObject(property.PropertyType, comparison, stringComparison); diff --git a/src/GraphQL.EntityFramework/Where/TypeConverter.cs b/src/GraphQL.EntityFramework/Where/TypeConverter.cs index b6b741de4..5d2675ef4 100644 --- a/src/GraphQL.EntityFramework/Where/TypeConverter.cs +++ b/src/GraphQL.EntityFramework/Where/TypeConverter.cs @@ -115,6 +115,24 @@ static IList ConvertStringsToListInternal(IEnumerable values, Type type) return values.Select(_ => (DateTime?)DateTime.Parse(_)).ToList(); } + if (type == typeof(Time)) + { + return values.Select(Time.Parse).ToList(); + } + if (type == typeof(Time?)) + { + return values.Select(_ => (Time?)Time.Parse(_)).ToList(); + } + + if (type == typeof(Date)) + { + return values.Select(_ => Date.ParseExact(_, "yyyy-MM-dd")).ToList(); + } + if (type == typeof(Date?)) + { + return values.Select(_ => (Date?)Date.ParseExact(_, "yyyy-MM-dd")).ToList(); + } + if (type == typeof(DateTimeOffset)) { return values.Select(DateTimeOffset.Parse).ToList(); @@ -151,6 +169,16 @@ static IList ConvertStringsToListInternal(IEnumerable values, Type type) return ValueConverter.ConvertTo(value); } + if (type == typeof(Date)) + { + return ValueConverter.ConvertTo(value); + } + + if (type == typeof(Time)) + { + return ValueConverter.ConvertTo