Skip to content

Commit 4dd3bf0

Browse files
committed
added required
1 parent 4b0a8cf commit 4dd3bf0

12 files changed

Lines changed: 419 additions & 17 deletions

File tree

src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public virtual string TransformText()
235235
this.Write("\")]\r\n\tpublic ");
236236

237237
#line 40 "C:\Code\Github\Linq2GraphQL.Client\src\Linq2GraphQL.Generator\Templates\Class\ClassTemplate.tt"
238-
this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field)));
238+
this.Write(this.ToStringHelper.ToStringWithCulture(GetFieldCSharpName(field, true)));
239239

240240
#line default
241241
#line hidden

src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public partial class <#= classType.Name #> <#= classType.GetInterfacesString("Gr
3737

3838
<# } else { #>
3939
[JsonPropertyName("<#= field.Name #>")]
40-
public <#= GetFieldCSharpName(field) #> <#= field.CSharpName #> { get; set; }
40+
public <#= GetFieldCSharpName(field, true) #> <#= field.CSharpName #> { get; set; }
4141

4242
<# } #>
4343
<# } #>

src/Linq2GraphQL.Generator/Templates/Class/ClassTemplate.tt.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public ClassTemplate(GraphqlType classType, string namespaceName)
1515
public bool IsInput => classType.Kind == TypeKind.InputObject;
1616

1717

18-
public string GetFieldCSharpName(Field field)
18+
public string GetFieldCSharpName(Field field, bool addRequired = false)
1919
{
2020

2121
if (field.GraphqlType.IsPageInfo())
@@ -24,7 +24,7 @@ public string GetFieldCSharpName(Field field)
2424
}
2525

2626
var result = "";
27-
if (GeneratorSettings.Current.Nullable && field.FieldInfo.IsNoneNull)
27+
if (addRequired && GeneratorSettings.Current.Nullable && field.FieldInfo.IsNoneNull)
2828
{
2929
result += "required ";
3030
}

test/Linq2GraphQL.TestClientNullable/Generated/Client/MutationMethods.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ public MutationMethods(GraphClient client)
1313
this.client = client;
1414
}
1515

16-
public GraphQuery<Customer?> UpdateCustomer(Guid customerId, string name)
16+
public GraphQuery<Customer?> UpdateCustomer(CustomerInput customer)
1717
{
1818
var arguments = new List<ArgumentValue>
1919
{
20-
new("customerId","UUID!", customerId),
21-
new("name","String!", name),
20+
new("customer","CustomerInput!", customer),
2221
};
2322

2423
return new GraphQuery<Customer?>(client, "updateCustomer", OperationType.Mutation, arguments);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json.Serialization;
4+
using Linq2GraphQL.Client;
5+
6+
namespace Linq2GraphQL.TestClientNullable;
7+
8+
[JsonConverter(typeof(GraphInputConverter<AddressInput>))]
9+
public partial class AddressInput : GraphInputBase
10+
{
11+
[JsonPropertyName("name")]
12+
public string Name
13+
{
14+
get => GetValue<string>("name");
15+
set => SetValue("name", value);
16+
}
17+
18+
[JsonPropertyName("street")]
19+
public string Street
20+
{
21+
get => GetValue<string>("street");
22+
set => SetValue("street", value);
23+
}
24+
25+
[JsonPropertyName("postalCode")]
26+
public string PostalCode
27+
{
28+
get => GetValue<string>("postalCode");
29+
set => SetValue("postalCode", value);
30+
}
31+
32+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json.Serialization;
4+
using Linq2GraphQL.Client;
5+
6+
namespace Linq2GraphQL.TestClientNullable;
7+
8+
[JsonConverter(typeof(GraphInputConverter<CustomerInput>))]
9+
public partial class CustomerInput : GraphInputBase
10+
{
11+
[JsonPropertyName("customerId")]
12+
public Guid CustomerId
13+
{
14+
get => GetValue<Guid>("customerId");
15+
set => SetValue("customerId", value);
16+
}
17+
18+
[JsonPropertyName("customerName")]
19+
public string CustomerName
20+
{
21+
get => GetValue<string>("customerName");
22+
set => SetValue("customerName", value);
23+
}
24+
25+
[JsonPropertyName("status")]
26+
public CustomerStatus Status
27+
{
28+
get => GetValue<CustomerStatus>("status");
29+
set => SetValue("status", value);
30+
}
31+
32+
[JsonPropertyName("orders")]
33+
public List<OrderInput> Orders
34+
{
35+
get => GetValue<List<OrderInput>>("orders");
36+
set => SetValue("orders", value);
37+
}
38+
39+
[JsonPropertyName("address")]
40+
public AddressInput? Address
41+
{
42+
get => GetValue<AddressInput?>("address");
43+
set => SetValue("address", value);
44+
}
45+
46+
}

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

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,207 @@ namespace Linq2GraphQL.TestClientNullable;
77

88
public static class IF
99
{
10+
public static AddressInput Address()
11+
{
12+
return new AddressInput();
13+
}
14+
public static CustomerInput Customer()
15+
{
16+
return new CustomerInput();
17+
}
18+
public static ItemInput Item()
19+
{
20+
return new ItemInput();
21+
}
22+
public static OrderInput Order()
23+
{
24+
return new OrderInput();
25+
}
26+
public static OrderLineInput OrderLine()
27+
{
28+
return new OrderLineInput();
29+
}
1030
}
1131

1232

33+
34+
public static class AddressInputExtensions
35+
{
36+
37+
public static AddressInput Name(this AddressInput input, string val)
38+
{
39+
input.Name = val;
40+
return input;
41+
}
42+
43+
44+
public static AddressInput Street(this AddressInput input, string val)
45+
{
46+
input.Street = val;
47+
return input;
48+
}
49+
50+
51+
public static AddressInput PostalCode(this AddressInput input, string val)
52+
{
53+
input.PostalCode = val;
54+
return input;
55+
}
56+
57+
}
58+
59+
public static class CustomerInputExtensions
60+
{
61+
62+
public static CustomerInput CustomerId(this CustomerInput input, Guid val)
63+
{
64+
input.CustomerId = val;
65+
return input;
66+
}
67+
68+
69+
public static CustomerInput CustomerName(this CustomerInput input, string val)
70+
{
71+
input.CustomerName = val;
72+
return input;
73+
}
74+
75+
76+
public static CustomerInput Status(this CustomerInput input, CustomerStatus val)
77+
{
78+
input.Status = val;
79+
return input;
80+
}
81+
82+
public static CustomerInput Orders(this CustomerInput input, Action<List<OrderInput>> mod)
83+
{
84+
var filter = new List<OrderInput>();
85+
mod ??= _ => { };
86+
mod(filter);
87+
input.Orders = filter;
88+
return input;
89+
}
90+
91+
public static CustomerInput Address(this CustomerInput input, Action<AddressInput?> mod)
92+
{
93+
var filter = new AddressInput?();
94+
mod ??= _ => { };
95+
mod(filter);
96+
input.Address = filter;
97+
return input;
98+
}
99+
100+
}
101+
102+
public static class ItemInputExtensions
103+
{
104+
105+
public static ItemInput ItemId(this ItemInput input, string val)
106+
{
107+
input.ItemId = val;
108+
return input;
109+
}
110+
111+
112+
public static ItemInput ItemName(this ItemInput input, string val)
113+
{
114+
input.ItemName = val;
115+
return input;
116+
}
117+
118+
}
119+
120+
public static class OrderInputExtensions
121+
{
122+
123+
public static OrderInput OrderId(this OrderInput input, Guid val)
124+
{
125+
input.OrderId = val;
126+
return input;
127+
}
128+
129+
public static OrderInput Customer(this OrderInput input, Action<CustomerInput> mod)
130+
{
131+
var filter = new CustomerInput();
132+
mod ??= _ => { };
133+
mod(filter);
134+
input.Customer = filter;
135+
return input;
136+
}
137+
138+
public static OrderInput Address(this OrderInput input, Action<AddressInput?> mod)
139+
{
140+
var filter = new AddressInput?();
141+
mod ??= _ => { };
142+
mod(filter);
143+
input.Address = filter;
144+
return input;
145+
}
146+
147+
148+
public static OrderInput OrderDate(this OrderInput input, DateTimeOffset val)
149+
{
150+
input.OrderDate = val;
151+
return input;
152+
}
153+
154+
public static OrderInput Lines(this OrderInput input, Action<List<OrderLineInput>> mod)
155+
{
156+
var filter = new List<OrderLineInput>();
157+
mod ??= _ => { };
158+
mod(filter);
159+
input.Lines = filter;
160+
return input;
161+
}
162+
163+
164+
public static OrderInput EntryTime(this OrderInput input, TimeSpan? val)
165+
{
166+
input.EntryTime = val;
167+
return input;
168+
}
169+
170+
}
171+
172+
public static class OrderLineInputExtensions
173+
{
174+
175+
public static OrderLineInput LineNumber(this OrderLineInput input, int val)
176+
{
177+
input.LineNumber = val;
178+
return input;
179+
}
180+
181+
public static OrderLineInput Order(this OrderLineInput input, Action<OrderInput> mod)
182+
{
183+
var filter = new OrderInput();
184+
mod ??= _ => { };
185+
mod(filter);
186+
input.Order = filter;
187+
return input;
188+
}
189+
190+
public static OrderLineInput Item(this OrderLineInput input, Action<ItemInput?> mod)
191+
{
192+
var filter = new ItemInput?();
193+
mod ??= _ => { };
194+
mod(filter);
195+
input.Item = filter;
196+
return input;
197+
}
198+
199+
200+
public static OrderLineInput Price(this OrderLineInput input, decimal val)
201+
{
202+
input.Price = val;
203+
return input;
204+
}
205+
206+
207+
public static OrderLineInput Quantity(this OrderLineInput input, double val)
208+
{
209+
input.Quantity = val;
210+
return input;
211+
}
212+
213+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.Json.Serialization;
4+
using Linq2GraphQL.Client;
5+
6+
namespace Linq2GraphQL.TestClientNullable;
7+
8+
[JsonConverter(typeof(GraphInputConverter<ItemInput>))]
9+
public partial class ItemInput : GraphInputBase
10+
{
11+
[JsonPropertyName("itemId")]
12+
public string ItemId
13+
{
14+
get => GetValue<string>("itemId");
15+
set => SetValue("itemId", value);
16+
}
17+
18+
[JsonPropertyName("itemName")]
19+
public string ItemName
20+
{
21+
get => GetValue<string>("itemName");
22+
set => SetValue("itemName", value);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)