Skip to content

Commit

Permalink
Add first round of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Nov 13, 2024
1 parent 7b7af03 commit 7344282
Show file tree
Hide file tree
Showing 2 changed files with 501 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/HotChocolate/Core/src/Types/SemanticNonNullTypeInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ public override void OnAfterCompleteName(ITypeCompletionContext completionContex
continue;
}

ApplySemanticNonNullDirective(field, completionContext);
// TODO: This is not correct for lists
var hasSemanticNonNull = ApplySemanticNonNullDirective(field, completionContext);

field.FormatterDefinitions.Add(CreateSemanticNonNullResultFormatterDefinition());
if (hasSemanticNonNull)
{
field.FormatterDefinitions.Add(CreateSemanticNonNullResultFormatterDefinition());
}
}
}
else if (definition is InterfaceTypeDefinition interfaceDef)
Expand All @@ -80,20 +84,20 @@ public override void OnAfterCompleteName(ITypeCompletionContext completionContex
}
}

private void ApplySemanticNonNullDirective(
private bool ApplySemanticNonNullDirective(
OutputFieldDefinitionBase field,
ITypeCompletionContext completionContext)
{
if (field.Type is null)
{
return;
return false;
}

var levels = GetSemanticNonNullLevels(field.Type);

if (levels.Count < 1)
{
return;
return false;
}

var directiveDependency = new TypeDependency(
Expand All @@ -105,6 +109,8 @@ private void ApplySemanticNonNullDirective(
field.AddDirective(new SemanticNonNullDirective(levels), _typeInspector);

field.Type = BuildNullableTypeStructure(field.Type, _typeInspector);

return true;
}

private static List<int> GetSemanticNonNullLevels(TypeReference typeReference)
Expand Down
Loading

0 comments on commit 7344282

Please sign in to comment.