Skip to content

Commit

Permalink
v8.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Abraham committed Jan 31, 2024
1 parent 61f7eb4 commit 55c1ea0
Show file tree
Hide file tree
Showing 83 changed files with 919 additions and 854 deletions.
3 changes: 2 additions & 1 deletion src/TypeCache.GraphQL/Data/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using GraphQL.Resolvers;
using GraphQL.Types;
using TypeCache.Extensions;
using TypeCache.GraphQL.Attributes;
using TypeCache.GraphQL.Extensions;
using TypeCache.GraphQL.Types;
Expand Down Expand Up @@ -67,7 +68,7 @@ public static ObjectGraphType CreateGraphType(string name, IGraphType dataGraphT
graphType.AddField(new()
{
Name = nameof(Connection<T>.TotalCount),
Type = typeof(GraphQLNumberType<int>),
Type = ScalarType.Int32.ToGraphType(),
Resolver = new FuncFieldResolver<Connection<T>, int?>(context => context.Source.TotalCount)
});

Expand Down
3 changes: 2 additions & 1 deletion src/TypeCache.GraphQL/Data/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using GraphQL.Resolvers;
using GraphQL.Types;
using TypeCache.Extensions;
using TypeCache.GraphQL.Attributes;
using TypeCache.GraphQL.Extensions;
using TypeCache.GraphQL.Types;
Expand All @@ -26,7 +27,7 @@ public static ObjectGraphType CreateGraphType(string name, IGraphType dataGraphT
graphType.AddField(new()
{
Name = nameof(Edge<T>.Cursor),
Type = typeof(GraphQLNumberType<int>),
Type = ScalarType.Int32.ToGraphType(),
Resolver = new FuncFieldResolver<Edge<T>, int>(context => context.Source.Cursor)
});
graphType.AddField(new()
Expand Down
63 changes: 32 additions & 31 deletions src/TypeCache.GraphQL/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ namespace TypeCache.GraphQL.Extensions;

public static class EnumExtensions
{
public static Type? ToGraphType(this ScalarType @this) => @this switch
{
ScalarType.Boolean => typeof(GraphQLBooleanType),
ScalarType.Byte => typeof(GraphQLNumberType<byte>),
ScalarType.Decimal => typeof(GraphQLNumberType<decimal>),
ScalarType.DateOnly => typeof(GraphQLStringType<DateOnly>),
ScalarType.DateTime => typeof(GraphQLStringType<DateTime>),
ScalarType.DateTimeOffset => typeof(GraphQLStringType<DateTimeOffset>),
ScalarType.Guid => typeof(GraphQLStringType<Guid>),
ScalarType.Half => typeof(GraphQLNumberType<Half>),
ScalarType.Int16 => typeof(GraphQLNumberType<short>),
ScalarType.Int32 or ScalarType.Index => typeof(GraphQLNumberType<int>),
ScalarType.Int64 => typeof(GraphQLNumberType<long>),
ScalarType.IntPtr => typeof(GraphQLNumberType<nint>),
ScalarType.Int128 => typeof(GraphQLNumberType<Int128>),
ScalarType.UInt128 => typeof(GraphQLNumberType<UInt128>),
ScalarType.BigInteger => typeof(GraphQLNumberType<BigInteger>),
ScalarType.UInt16 => typeof(GraphQLNumberType<ushort>),
ScalarType.UInt32 => typeof(GraphQLNumberType<uint>),
ScalarType.UInt64 => typeof(GraphQLNumberType<ulong>),
ScalarType.UIntPtr => typeof(GraphQLNumberType<UIntPtr>),
ScalarType.SByte => typeof(GraphQLNumberType<sbyte>),
ScalarType.Single => typeof(GraphQLNumberType<float>),
ScalarType.Double => typeof(GraphQLNumberType<char>),
ScalarType.Char => typeof(GraphQLStringType<char>),
ScalarType.String => typeof(GraphQLStringType),
ScalarType.TimeOnly => typeof(GraphQLStringType<TimeOnly>),
ScalarType.TimeSpan => typeof(GraphQLStringType<TimeSpan>),
ScalarType.Uri => typeof(GraphQLUriType),
_ => null
};
public static Type? ToGraphType(this ScalarType @this)
=> @this switch
{
ScalarType.Boolean => typeof(GraphQLScalarType<bool>),
ScalarType.Byte => typeof(GraphQLScalarType<byte>),
ScalarType.Int16 => typeof(GraphQLScalarType<short>),
ScalarType.Int32 or ScalarType.Index => typeof(GraphQLScalarType<int>),
ScalarType.Int64 => typeof(GraphQLScalarType<long>),
ScalarType.IntPtr => typeof(GraphQLScalarType<nint>),
ScalarType.Int128 => typeof(GraphQLScalarType<Int128>),
ScalarType.BigInteger => typeof(GraphQLScalarType<BigInteger>),
ScalarType.UInt16 => typeof(GraphQLScalarType<ushort>),
ScalarType.UInt32 => typeof(GraphQLScalarType<uint>),
ScalarType.UInt64 => typeof(GraphQLScalarType<ulong>),
ScalarType.UIntPtr => typeof(GraphQLScalarType<UIntPtr>),
ScalarType.UInt128 => typeof(GraphQLScalarType<UInt128>),
ScalarType.SByte => typeof(GraphQLScalarType<sbyte>),
ScalarType.Half => typeof(GraphQLScalarType<Half>),
ScalarType.Single => typeof(GraphQLScalarType<float>),
ScalarType.Double => typeof(GraphQLScalarType<char>),
ScalarType.Decimal => typeof(GraphQLScalarType<decimal>),
ScalarType.DateOnly => typeof(GraphQLScalarType<DateOnly>),
ScalarType.DateTime => typeof(GraphQLScalarType<DateTime>),
ScalarType.DateTimeOffset => typeof(GraphQLScalarType<DateTimeOffset>),
ScalarType.TimeOnly => typeof(GraphQLScalarType<TimeOnly>),
ScalarType.TimeSpan => typeof(GraphQLScalarType<TimeSpan>),
ScalarType.Guid => typeof(GraphQLScalarType<Guid>),
ScalarType.Char => typeof(GraphQLScalarType<char>),
ScalarType.String => typeof(GraphQLScalarType<string>),
ScalarType.Uri => typeof(GraphQLUriType),
_ => null
};
}
22 changes: 11 additions & 11 deletions src/TypeCache.GraphQL/Extensions/GraphQLExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ public static FieldType ToFieldType(this PropertyInfo @this)
arguments.Add("null", type, description: "Return this value instead of null.");

if (@this.PropertyType.IsAssignableTo<IFormattable>())
arguments.Add<GraphQLStringType>("format", description: "Use .NET format specifiers to format the data.");
arguments.Add<GraphQLScalarType<string>>("format", description: "Use .NET format specifiers to format the data.");

if (type.Is<GraphQLStringType<DateTime>>() || type.Is<NonNullGraphType<GraphQLStringType<DateTime>>>())
arguments.Add<GraphQLStringType>("timeZone", description: Invariant($"{typeof(TimeZoneInfo).Namespace}.{nameof(TimeZoneInfo)}.{nameof(TimeZoneInfo.ConvertTimeBySystemTimeZoneId)}(value, [..., ...] | [UTC, ...])"));
else if (type.Is<GraphQLStringType<DateTimeOffset>>() || type.Is<NonNullGraphType<GraphQLStringType<DateTimeOffset>>>())
arguments.Add<GraphQLStringType>("timeZone", description: Invariant($"{typeof(TimeZoneInfo).Namespace}.{nameof(TimeZoneInfo)}.{nameof(TimeZoneInfo.ConvertTimeBySystemTimeZoneId)}(value, ...)"));
else if (type.Is<GraphQLStringType>() || type.Is<NonNullGraphType<GraphQLStringType>>())
if (type.Is<GraphQLScalarType<DateTime>>() || type.Is<NonNullGraphType<GraphQLScalarType<DateTime>>>())
arguments.Add<GraphQLScalarType<string>>("timeZone", description: Invariant($"{typeof(TimeZoneInfo).Namespace}.{nameof(TimeZoneInfo)}.{nameof(TimeZoneInfo.ConvertTimeBySystemTimeZoneId)}(value, [..., ...] | [UTC, ...])"));
else if (type.Is<GraphQLScalarType<DateTimeOffset>>() || type.Is<NonNullGraphType<GraphQLScalarType<DateTimeOffset>>>())
arguments.Add<GraphQLScalarType<string>>("timeZone", description: Invariant($"{typeof(TimeZoneInfo).Namespace}.{nameof(TimeZoneInfo)}.{nameof(TimeZoneInfo.ConvertTimeBySystemTimeZoneId)}(value, ...)"));
else if (type.Is<GraphQLScalarType<string>>() || type.Is<NonNullGraphType<GraphQLScalarType<string>>>())
{
arguments.Add<GraphQLEnumType<StringCase>>("case", description: "Convert string value to upper or lower case.");
arguments.Add<GraphQLNumberType<int>>("length", description: "Exclude the rest of the string value if it exceeds this length.");
arguments.Add<GraphQLStringType>("match", description: "Returns the matching result based on the specified regular expression pattern, null if no match.");
arguments.Add<GraphQLStringType>("trim", description: Invariant($"{typeof(string).Namespace}.{nameof(String)}.{nameof(string.Trim)}(value)"));
arguments.Add<GraphQLStringType>("trimEnd", description: Invariant($"{typeof(string).Namespace}.{nameof(String)}.{nameof(string.TrimEnd)}(value)"));
arguments.Add<GraphQLStringType>("trimStart", description: Invariant($"{typeof(string).Namespace}.{nameof(String)}.{nameof(string.TrimStart)}(value)"));
arguments.Add<GraphQLScalarType<int>>("length", description: "Exclude the rest of the string value if it exceeds this length.");
arguments.Add<GraphQLScalarType<string>>("match", description: "Returns the matching result based on the specified regular expression pattern, null if no match.");
arguments.Add<GraphQLScalarType<string>>("trim", description: Invariant($"{typeof(string).Namespace}.{nameof(String)}.{nameof(string.Trim)}(value)"));
arguments.Add<GraphQLScalarType<string>>("trimEnd", description: Invariant($"{typeof(string).Namespace}.{nameof(String)}.{nameof(string.TrimEnd)}(value)"));
arguments.Add<GraphQLScalarType<string>>("trimStart", description: Invariant($"{typeof(string).Namespace}.{nameof(String)}.{nameof(string.TrimStart)}(value)"));
}

return new()
Expand Down
Loading

0 comments on commit 55c1ea0

Please sign in to comment.