Skip to content

Commit e6249d2

Browse files
committed
1 parent 5f30a3e commit e6249d2

File tree

18 files changed

+144
-293
lines changed

18 files changed

+144
-293
lines changed

src/Linq2GraphQL.Client/Attributes/GraphQLMemberAttribute.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
44
public class GraphQLMemberAttribute : Attribute
55
{
6-
public GraphQLMemberAttribute(string graphQLName)
6+
public GraphQLMemberAttribute(string graphQLName, bool interfaceProperty = false)
77
{
88
GraphQLName = graphQLName;
9+
InterfaceProperty = interfaceProperty;
910
}
1011

1112
public string GraphQLName { get; private set; }
13+
14+
public bool InterfaceProperty { get; set; }
1215
}

src/Linq2GraphQL.Client/GraphBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public GraphBase(GraphClient client, string name, OperationType operationType, L
1111
{
1212
this.client = client;
1313
this.operationType = operationType;
14-
QueryNode = new(typeof(T), name, arguments, false, true);
14+
QueryNode = new(typeof(T), name, arguments, null, true);
1515
}
1616

1717
public QueryNode QueryNode { get; }

src/Linq2GraphQL.Client/QueryNode.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ public class QueryNode
1010
private string argumentHashCodeId;
1111

1212
public QueryNode(MemberInfo member, string name = null, List<ArgumentValue> arguments = null,
13-
bool interfaceProperty = false, bool topLevel = false)
13+
bool? interfaceProperty = null, bool topLevel = false)
1414
{
15-
Name = name ?? member.GetCustomAttribute<GraphQLMemberAttribute>()?.GraphQLName ?? member.Name.ToCamelCase();
15+
var memberAttribute = member.GetCustomAttribute<GraphQLMemberAttribute>();
16+
17+
Name = name ?? memberAttribute?.GraphQLName ?? member.Name.ToCamelCase();
1618
Member = member;
1719
Arguments = arguments ?? new List<ArgumentValue>();
1820
underlyingMemberType = member.GetUnderlyingType();
1921
mustHaveChildren = MustHaveChildren(underlyingMemberType);
20-
InterfaceProperty = interfaceProperty;
22+
InterfaceProperty = memberAttribute?.InterfaceProperty == true;
2123

2224
if (!topLevel)
2325
{

src/Linq2GraphQL.Generator/Properties/launchSettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"profiles": {
33
"Linq2GraphQL.Generator": {
44
"commandName": "Project",
5-
// "commandLineArgs": "https://localhost:7184/graphql/ -c=\"SampleClient\" -n=\"Linq2GraphQL.TestClient\" -o=\"C:\\Code\\Linq2GraphQL.Client\\test\\Linq2GraphQL.TestClient\\Generated\" -s=true -d=true"
6-
"commandLineArgs": "https://localhost:50741/graphql/ -c=\"SampleNullableClient\" -n=\"Linq2GraphQL.TestClientNullable\" -o=\"C:\\Code\\Linq2GraphQL.Client\\test\\Linq2GraphQL.TestClientNullable\\Generated\" -s=true -d=true -nu=true"
5+
"commandLineArgs": "https://localhost:7184/graphql/ -c=\"SampleClient\" -n=\"Linq2GraphQL.TestClient\" -o=\"C:\\Code\\Github\\Linq2GraphQL.Client\\test\\Linq2GraphQL.TestClient\\Generated\" -s=true -d=true"
76
}
87
}
98
}

src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.cs

Lines changed: 74 additions & 52 deletions
Large diffs are not rendered by default.

src/Linq2GraphQL.Generator/Templates/Interface/InterfaceTemplate.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class <#= classType.Name #>Extensions
2323
/// </summary>
2424
/// <param name="value">The interface value to cast</param>
2525
/// <returns><#= field #> instance or null if type doesn't match</returns>
26-
[GraphInterface]
26+
[GraphQLMember("<#= field #>", true)]
2727
public static <#= field #> <#= field #>(this <#= classType.Name #> value)
2828
{
2929
if (value.__TypeName == "<#= field #>")

test/Linq2GraphQL.TestClient/Generated/Inputs/CustomerFilterInput.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ public AddressFilterInput Address
7171
set => SetValue("address", value);
7272
}
7373

74+
[GraphQLMember("created")]
75+
[JsonPropertyName("created")]
76+
public DateTimeOperationFilterInput Created
77+
{
78+
get => GetValue<DateTimeOperationFilterInput>("created");
79+
set => SetValue("created", value);
80+
}
81+
7482
}

test/Linq2GraphQL.TestClient/Generated/Inputs/CustomerInput.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@ public AddressInput Address
5555
set => SetValue("address", value);
5656
}
5757

58+
[GraphQLMember("created")]
59+
[JsonPropertyName("created")]
60+
public DateTimeOffset? Created
61+
{
62+
get => GetValue<DateTimeOffset?>("created");
63+
set => SetValue("created", value);
64+
}
65+
5866
}

test/Linq2GraphQL.TestClient/Generated/Inputs/CustomerSortInput.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ public AddressSortInput Address
4747
set => SetValue("address", value);
4848
}
4949

50+
[GraphQLMember("created")]
51+
[JsonPropertyName("created")]
52+
public SortEnumType? Created
53+
{
54+
get => GetValue<SortEnumType?>("created");
55+
set => SetValue("created", value);
56+
}
57+
5058
}

test/Linq2GraphQL.TestClient/Generated/Inputs/InputFactory.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ public static CustomerFilterInput Address(this CustomerFilterInput input, Action
405405
return input;
406406
}
407407

408+
public static CustomerFilterInput Created(this CustomerFilterInput input, Action<DateTimeOperationFilterInput> mod)
409+
{
410+
var filter = new DateTimeOperationFilterInput();
411+
mod ??= _ => { };
412+
mod(filter);
413+
input.Created = filter;
414+
return input;
415+
}
416+
408417
}
409418

410419
public static class CustomerInputExtensions
@@ -448,6 +457,13 @@ public static CustomerInput Address(this CustomerInput input, Action<AddressInpu
448457
return input;
449458
}
450459

460+
461+
public static CustomerInput Created(this CustomerInput input, DateTimeOffset? val)
462+
{
463+
input.Created = val;
464+
return input;
465+
}
466+
451467
}
452468

453469
public static class CustomerSortInputExtensions
@@ -482,6 +498,13 @@ public static CustomerSortInput Address(this CustomerSortInput input, Action<Add
482498
return input;
483499
}
484500

501+
502+
public static CustomerSortInput Created(this CustomerSortInput input, SortEnumType? val)
503+
{
504+
input.Created = val;
505+
return input;
506+
}
507+
485508
}
486509

487510
public static class CustomerStatusOperationFilterInputExtensions

0 commit comments

Comments
 (0)