Skip to content

Commit

Permalink
Fixed issue where we normalized schema references incorrectly (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Sep 21, 2020
1 parent b04ea1f commit 1b4eb36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Expand Up @@ -107,6 +107,11 @@ public IReadOnlyList<ISchemaError> DiscoverTypes()

CollectErrors();

if (_errors.Count == 0)
{
_typeRegistry.CompleteDiscovery();
}

return _errors;
}

Expand Down Expand Up @@ -168,7 +173,7 @@ private void CollectErrors()
foreach (ITypeReference unresolvedReference in _typeRegistrar.GetUnresolved())
{
var types = _typeRegistry.Types.Where(
t => t.Dependencies.Select(t => t.TypeReference)
t => t.Dependencies.Select(d => d.TypeReference)
.Any(r => r.Equals(unresolvedReference))).ToList();

ISchemaErrorBuilder builder =
Expand Down
7 changes: 3 additions & 4 deletions src/HotChocolate/Core/src/Types/Configuration/TypeLookup.cs
Expand Up @@ -55,9 +55,8 @@ internal sealed class TypeLookup
break;

case SchemaTypeReference r:
namedTypeRef = _typeInspector.GetTypeRef(
r.Type.GetType(), r.Context, typeRef.Scope);
_refs[typeRef] = namedTypeRef;
_refs[typeRef] = r;
namedTypeRef = r;
return true;

case SyntaxTypeReference r:
Expand Down Expand Up @@ -113,7 +112,7 @@ internal sealed class TypeLookup
{
throw new ArgumentNullException(nameof(typeRef));
}

// if the typeRef refers to a schema type base class we skip since such a type is not
// resolvable.
if (typeRef.Type.Type.IsNonGenericSchemaType() ||
Expand Down
10 changes: 4 additions & 6 deletions src/HotChocolate/Core/src/Types/Configuration/TypeRegistrar.cs
Expand Up @@ -59,7 +59,7 @@ internal sealed class TypeRegistrar
if (typeSystemObject is IHasRuntimeType hasRuntimeType
&& hasRuntimeType.RuntimeType != typeof(object))
{
ExtendedTypeReference? runtimeTypeRef =
ExtendedTypeReference runtimeTypeRef =
_context.TypeInspector.GetTypeRef(
hasRuntimeType.RuntimeType,
SchemaTypeReference.InferTypeContext(typeSystemObject),
Expand Down Expand Up @@ -176,17 +176,15 @@ public IReadOnlyCollection<ITypeReference> GetUnhandled()

if (!isInferred)
{
references.Add(TypeReference.Create(
typeSystemObject,
scope: scope));
references.Add(TypeReference.Create(typeSystemObject, scope));
}

if (!ExtendedType.Tools.IsNonGenericBaseType(typeSystemObject.GetType()))
{
references.Add(_context.TypeInspector.GetTypeRef(
typeSystemObject.GetType(),
SchemaTypeReference.InferTypeContext(typeSystemObject),
scope: scope));
scope));
}

if (typeSystemObject is IHasTypeIdentity hasTypeIdentity &&
Expand All @@ -196,7 +194,7 @@ public IReadOnlyCollection<ITypeReference> GetUnhandled()
_context.TypeInspector.GetTypeRef(
hasTypeIdentity.TypeIdentity,
SchemaTypeReference.InferTypeContext(typeSystemObject),
scope: scope);
scope);

if (!references.Contains(reference))
{
Expand Down
17 changes: 15 additions & 2 deletions src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs
Expand Up @@ -18,7 +18,7 @@ internal sealed class TypeRegistry
new ExtendedTypeReferenceEqualityComparer());
private readonly Dictionary<NameString, ITypeReference> _nameRefs =
new Dictionary<NameString, ITypeReference>();
private List<RegisteredType> _types = new List<RegisteredType>();
private readonly List<RegisteredType> _types = new List<RegisteredType>();

public int Count => _typeRegister.Count;

Expand Down Expand Up @@ -121,7 +121,7 @@ public void Register(RegisteredType registeredType)
throw new ArgumentNullException(nameof(registeredType));
}

bool addToTypes = !_typeRegister.ContainsValue(registeredType);
var addToTypes = !_typeRegister.ContainsValue(registeredType);

foreach (ITypeReference typeReference in registeredType.References)
{
Expand Down Expand Up @@ -177,5 +177,18 @@ public void Register(NameString typeName, RegisteredType registeredType)

_nameRefs[typeName] = registeredType.References[0];
}

public void CompleteDiscovery()
{
foreach (RegisteredType registeredType in _types)
{
_typeRegister[TypeReference.Create(registeredType.Type)] = registeredType;

if (registeredType.Type.Scope is { } s)
{
_typeRegister[TypeReference.Create(registeredType.Type, s)] = registeredType;
}
}
}
}
}

0 comments on commit 1b4eb36

Please sign in to comment.