Skip to content

Commit

Permalink
Add TimeSpan support and enhance enum strategy handling
Browse files Browse the repository at this point in the history
Introduced a nullable TimeSpan property to Order.cs and updated Helpers.cs for TimeSpan type mapping. Also improved enum strategy handling in GenerateClientAsync to check for null values.
  • Loading branch information
Magnus Ahlberg committed Aug 6, 2024
1 parent 570574d commit 11d776d
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Linq2GraphQL.Generator/GraphQLSchema/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static class Helpers
{ "timestamptz", new ValueTuple<string, Type>("DateTimeOffset", typeof(DateTimeOffset)) },
{ "Uri", new ValueTuple<string, Type>("Uri", typeof(Uri)) },
{ "DateTime", new ValueTuple<string, Type>("DateTimeOffset", typeof(DateTimeOffset)) },
{ "Decimal", new ValueTuple<string, Type>("decimal", typeof(decimal)) }
{ "Decimal", new ValueTuple<string, Type>("decimal", typeof(decimal)) },
{ "TimeSpan", new ValueTuple<string, Type>("TimeSpan", typeof(TimeSpan)) }
};


Expand Down
2 changes: 1 addition & 1 deletion src/Linq2GraphQL.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ await GenerateClientAsync(uriValue, outputFolderValue, namespaceValue, clientNam
private static async Task GenerateClientAsync(Uri uri, string outputFolder, string namespaceName, string name,
bool includeSubscriptions, string authToken, string enumStrategy)
{
var enumStrat = enumStrategy.Equals("AddUnknownOption", StringComparison.InvariantCultureIgnoreCase)
var enumStrat = enumStrategy != null && enumStrategy.Equals("AddUnknownOption", StringComparison.InvariantCultureIgnoreCase)
? EnumGeneratorStrategy.AddUnknownOption
: EnumGeneratorStrategy.FailIfMissing;

Expand Down
115 changes: 115 additions & 0 deletions test/Linq2GraphQL.TestClient/Generated/Inputs/InputFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public static StringOperationFilterInput StringOperationFilter()
{
return new StringOperationFilterInput();
}
public static TimeSpanOperationFilterInput TimeSpanOperationFilter()
{
return new TimeSpanOperationFilterInput();
}
public static UuidOperationFilterInput UuidOperationFilter()
{
return new UuidOperationFilterInput();
Expand Down Expand Up @@ -991,6 +995,15 @@ public static OrderFilterInput Lines(this OrderFilterInput input, Action<ListFil
return input;
}

public static OrderFilterInput EntryTime(this OrderFilterInput input, Action<TimeSpanOperationFilterInput> mod)
{
var filter = new TimeSpanOperationFilterInput();
mod ??= _ => { };
mod(filter);
input.EntryTime = filter;
return input;
}

}

public static class OrderInputExtensions
Expand Down Expand Up @@ -1036,6 +1049,13 @@ public static OrderInput Lines(this OrderInput input, Action<List<OrderLineInput
return input;
}


public static OrderInput EntryTime(this OrderInput input, TimeSpan? val)
{
input.EntryTime = val;
return input;
}

}

public static class OrderLineFilterInputExtensions
Expand Down Expand Up @@ -1182,6 +1202,13 @@ public static OrderSortInput OrderDate(this OrderSortInput input, SortEnumType?
return input;
}


public static OrderSortInput EntryTime(this OrderSortInput input, SortEnumType? val)
{
input.EntryTime = val;
return input;
}

}

public static class StringOperationFilterInputExtensions
Expand Down Expand Up @@ -1276,6 +1303,94 @@ public static StringOperationFilterInput NendsWith(this StringOperationFilterInp

}

public static class TimeSpanOperationFilterInputExtensions
{

public static TimeSpanOperationFilterInput Eq(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Eq = val;
return input;
}


public static TimeSpanOperationFilterInput Neq(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Neq = val;
return input;
}


public static TimeSpanOperationFilterInput In(this TimeSpanOperationFilterInput input, List<TimeSpan?> val)
{
input.In = val;
return input;
}


public static TimeSpanOperationFilterInput Nin(this TimeSpanOperationFilterInput input, List<TimeSpan?> val)
{
input.Nin = val;
return input;
}


public static TimeSpanOperationFilterInput Gt(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Gt = val;
return input;
}


public static TimeSpanOperationFilterInput Ngt(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Ngt = val;
return input;
}


public static TimeSpanOperationFilterInput Gte(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Gte = val;
return input;
}


public static TimeSpanOperationFilterInput Ngte(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Ngte = val;
return input;
}


public static TimeSpanOperationFilterInput Lt(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Lt = val;
return input;
}


public static TimeSpanOperationFilterInput Nlt(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Nlt = val;
return input;
}


public static TimeSpanOperationFilterInput Lte(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Lte = val;
return input;
}


public static TimeSpanOperationFilterInput Nlte(this TimeSpanOperationFilterInput input, TimeSpan? val)
{
input.Nlte = val;
return input;
}

}

public static class UuidOperationFilterInputExtensions
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public ListFilterInputTypeOfOrderLineFilterInput Lines
set => SetValue("lines", value);
}

[JsonPropertyName("entryTime")]
public TimeSpanOperationFilterInput EntryTime
{
get => GetValue<TimeSpanOperationFilterInput>("entryTime");
set => SetValue("entryTime", value);
}

}
7 changes: 7 additions & 0 deletions test/Linq2GraphQL.TestClient/Generated/Inputs/OrderInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ public List<OrderLineInput> Lines
set => SetValue("lines", value);
}

[JsonPropertyName("entryTime")]
public TimeSpan? EntryTime
{
get => GetValue<TimeSpan?>("entryTime");
set => SetValue("entryTime", value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public SortEnumType? OrderDate
set => SetValue("orderDate", value);
}

[JsonPropertyName("entryTime")]
public SortEnumType? EntryTime
{
get => GetValue<SortEnumType?>("entryTime");
set => SetValue("entryTime", value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Linq2GraphQL.Client;

namespace Linq2GraphQL.TestClient;

[JsonConverter(typeof(GraphInputConverter<TimeSpanOperationFilterInput>))]
public partial class TimeSpanOperationFilterInput : GraphInputBase
{
[JsonPropertyName("eq")]
public TimeSpan? Eq
{
get => GetValue<TimeSpan?>("eq");
set => SetValue("eq", value);
}

[JsonPropertyName("neq")]
public TimeSpan? Neq
{
get => GetValue<TimeSpan?>("neq");
set => SetValue("neq", value);
}

[JsonPropertyName("in")]
public List<TimeSpan?> In
{
get => GetValue<List<TimeSpan?>>("in");
set => SetValue("in", value);
}

[JsonPropertyName("nin")]
public List<TimeSpan?> Nin
{
get => GetValue<List<TimeSpan?>>("nin");
set => SetValue("nin", value);
}

[JsonPropertyName("gt")]
public TimeSpan? Gt
{
get => GetValue<TimeSpan?>("gt");
set => SetValue("gt", value);
}

[JsonPropertyName("ngt")]
public TimeSpan? Ngt
{
get => GetValue<TimeSpan?>("ngt");
set => SetValue("ngt", value);
}

[JsonPropertyName("gte")]
public TimeSpan? Gte
{
get => GetValue<TimeSpan?>("gte");
set => SetValue("gte", value);
}

[JsonPropertyName("ngte")]
public TimeSpan? Ngte
{
get => GetValue<TimeSpan?>("ngte");
set => SetValue("ngte", value);
}

[JsonPropertyName("lt")]
public TimeSpan? Lt
{
get => GetValue<TimeSpan?>("lt");
set => SetValue("lt", value);
}

[JsonPropertyName("nlt")]
public TimeSpan? Nlt
{
get => GetValue<TimeSpan?>("nlt");
set => SetValue("nlt", value);
}

[JsonPropertyName("lte")]
public TimeSpan? Lte
{
get => GetValue<TimeSpan?>("lte");
set => SetValue("lte", value);
}

[JsonPropertyName("nlte")]
public TimeSpan? Nlte
{
get => GetValue<TimeSpan?>("nlte");
set => SetValue("nlte", value);
}

}
3 changes: 3 additions & 0 deletions test/Linq2GraphQL.TestClient/Generated/Types/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ public partial class Order : GraphQLTypeBase
[JsonPropertyName("lines")]
public List<OrderLine> Lines { get; set; }

[JsonPropertyName("entryTime")]
public TimeSpan? EntryTime { get; set; }

}
1 change: 1 addition & 0 deletions test/Linq2GraphQL.TestServer.Shared/Models/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public Order(Customer customer)
public Address? Address { get; set; }
public DateTimeOffset OrderDate { get; set; }
public List<OrderLine> Lines { get; set; } = new();
public TimeOnly? EntryTime { get; set; }

public string GetOrderHello(string name, int first = 0)
{
Expand Down

0 comments on commit 11d776d

Please sign in to comment.