Skip to content

Commit 57a1603

Browse files
committed
Preparation
1 parent 503000f commit 57a1603

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Linq2GraphQL.Generator/GraphQLSchema/RootSchema.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ public BaseType GetBaseBaseType()
367367
public CoreType GetCoreType()
368368
{
369369
var result = new CoreType();
370-
371-
370+
372371
bool currentNoneNull = false;
373372

374373
foreach (var type in GetAllTypes())
@@ -428,9 +427,9 @@ public class CoreType
428427
public string CSharpTypeName { get; set; }
429428
public Type CSharpType { get; set; }
430429
public List<CoreTypeList> Lists { get; set; } = [];
430+
public bool IsInList => Lists.Count != 0;
431431

432432

433-
434433

435434
public string GetGraphQLTypeDefinition()
436435
{
@@ -448,16 +447,30 @@ public string GetGraphQLTypeDefinition()
448447

449448
}
450449

450+
private bool UseSharpNoneNull()
451+
{
452+
if (GeneratorSettings.Current.Nullable)
453+
{
454+
return NoneNull;
455+
}
456+
else
457+
{
458+
return NoneNull && !(BaseType.Kind == TypeKind.Enum || (CSharpType != null && CSharpTypeName != "string"));
459+
}
460+
461+
}
462+
463+
451464
public string GetCSharpTypeDefinition()
452465
{
453466
var result = CSharpTypeName;
454467

455-
if (!NoneNull) { result += "?"; }
468+
if (UseSharpNoneNull()) { result += "?"; }
456469

457470
foreach (var list in Lists)
458471
{
459472
result = $"List<{result}>";
460-
if (!list.NoneNull) { result += "?"; }
473+
if (!list.NoneNull && GeneratorSettings.Current.Nullable) { result += "?"; }
461474
}
462475

463476
return result;

0 commit comments

Comments
 (0)