Skip to content

Commit

Permalink
Add missing type error message (#5346)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmary2014 authored Sep 12, 2022
1 parent 79c8093 commit 5c822d4
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 318 deletions.
23 changes: 20 additions & 3 deletions src/HotChocolate/Core/src/Types/Configuration/TypeInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,21 @@ private bool ProcessTypes(

IReadOnlyList<ITypeReference> needed =
TryNormalizeDependencies(type.Conditionals,
out var normalized)
out var normalized,
out var notFound)
? normalized.Except(processed).ToArray()
: type.Conditionals.Select(t => t.TypeReference).ToArray();

if (notFound != null)
{
_errors.Add(SchemaErrorBuilder.New()
.SetMessage(
TypeInitializer_CannotFindType,
string.Join(", ", notFound.Reverse()))
.SetTypeSystemObject(type.Type)
.Build());
}

_errors.Add(SchemaErrorBuilder.New()
.SetMessage(
TypeInitializer_CannotResolveDependency,
Expand Down Expand Up @@ -512,7 +523,9 @@ private IEnumerable<RegisteredType> GetNextBatch(
{
foreach (var type in _next)
{
if (TryNormalizeDependencies(type.Conditionals, out var normalized) &&
if (TryNormalizeDependencies(type.Conditionals,
out var normalized,
out var _) &&
processed.IsSupersetOf(GetTypeRefsExceptSelfRefs(type, normalized)))
{
yield return type;
Expand Down Expand Up @@ -553,7 +566,8 @@ List<ITypeReference> GetTypeRefsExceptSelfRefs(

private bool TryNormalizeDependencies(
List<TypeDependency> dependencies,
[NotNullWhen(true)] out IReadOnlyList<ITypeReference>? normalized)
[NotNullWhen(true)] out IReadOnlyList<ITypeReference>? normalized,
[NotNullWhen(false)] out IReadOnlyList<ITypeReference>? notFound)
{
var n = new List<ITypeReference>();

Expand All @@ -564,6 +578,8 @@ private bool TryNormalizeDependencies(
out var nr))
{
normalized = null;
n.Add(dependency.TypeReference);
notFound = n;
return false;
}

Expand All @@ -574,6 +590,7 @@ private bool TryNormalizeDependencies(
}

normalized = n;
notFound = null;
return true;
}

Expand Down
Loading

0 comments on commit 5c822d4

Please sign in to comment.