File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
src/Linq2GraphQL.Generator/GraphQLSchema Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments