Skip to content

Commit

Permalink
Removed TypeReference Interface (#5696)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 19, 2023
1 parent aba413e commit 802c9b8
Show file tree
Hide file tree
Showing 116 changed files with 333 additions and 357 deletions.
Expand Up @@ -16,6 +16,6 @@ public ObjectTypeInfo(ITypeCompletionContext context, ObjectTypeDefinition typeD
TypeRef = TypeReg.TypeReference;
}

public ITypeReference TypeRef { get; }
public TypeReference TypeRef { get; }
}
}
Expand Up @@ -22,26 +22,26 @@ public State(AuthorizationOptions options)
/// <summary>
/// Gets the types to which authorization middleware need to be applied.
/// </summary>
public HashSet<ITypeReference> NeedsAuth { get; } = new();
public HashSet<TypeReference> NeedsAuth { get; } = new();

/// <summary>
/// Gets the types to which are annotated with the @authorize directive.
/// </summary>
public HashSet<ITypeReference> AuthTypes { get; } = new();
public HashSet<TypeReference> AuthTypes { get; } = new();

/// <summary>
/// Gets a lookup table from abstract types to concrete types that need authorization.
/// </summary>
public Dictionary<ITypeReference, List<ITypeReference>> AbstractToConcrete { get; } = new();
public Dictionary<TypeReference, List<TypeReference>> AbstractToConcrete { get; } = new();

/// <summary>
/// Gets a helper queue for processing types.
/// </summary>
public List<ITypeReference> Queue { get; } = new();
public List<TypeReference> Queue { get; } = new();

/// <summary>
/// Gets a helper set for tracking process completion.
/// </summary>
public HashSet<ITypeReference> Completed { get; } = new();
public HashSet<TypeReference> Completed { get; } = new();
}
}
Expand Up @@ -22,7 +22,7 @@ internal sealed partial class AuthorizationTypeInterceptor : TypeInterceptor
private readonly List<ObjectTypeInfo> _objectTypes = new();
private readonly List<UnionTypeInfo> _unionTypes = new();
private readonly Dictionary<ObjectType, IDirectiveCollection> _directives = new();
private readonly HashSet<ITypeReference> _completedTypeRefs = new();
private readonly HashSet<TypeReference> _completedTypeRefs = new();
private readonly HashSet<RegisteredType> _completedTypes = new();
private State? _state;

Expand Down Expand Up @@ -137,7 +137,7 @@ private void InspectObjectTypesForAuthDirective(State state)
interfaceTypeRef,
out var authTypeRefs))
{
authTypeRefs = new List<ITypeReference>();
authTypeRefs = new List<TypeReference>();
state.AbstractToConcrete.Add(interfaceTypeRef, authTypeRefs);
}
Expand All @@ -157,7 +157,7 @@ private void FindUnionTypesThatContainAuthTypes(State state)
{
var unionTypeReg = type.TypeReg;
var unionTypeRef = unionTypeReg.TypeReference;
List<ITypeReference>? authTypeRefs = null;
List<TypeReference>? authTypeRefs = null;

foreach (var memberTypeRef in type.TypeDef.Types)
{
Expand All @@ -171,7 +171,7 @@ private void FindUnionTypesThatContainAuthTypes(State state)
if (authTypeRefs is null &&
!state.AbstractToConcrete.TryGetValue(unionTypeRef, out authTypeRefs))
{
authTypeRefs = new List<ITypeReference>();
authTypeRefs = new List<TypeReference>();
state.AbstractToConcrete.Add(unionTypeRef, authTypeRefs);
}

Expand Down Expand Up @@ -441,8 +441,8 @@ private void CompleteDirectiveType(DirectiveDefinition directive)
}

private void CollectInterfaces(
IReadOnlyList<ITypeReference> interfaces,
Action<ITypeReference> register,
IReadOnlyList<TypeReference> interfaces,
Action<TypeReference> register,
State state)
{
state.Queue.AddRange(interfaces);
Expand All @@ -466,7 +466,7 @@ private void CompleteDirectiveType(DirectiveDefinition directive)
}
}

private RegisteredType GetTypeRegistration(ITypeReference typeReference)
private RegisteredType GetTypeRegistration(TypeReference typeReference)
{
if (_typeLookup.TryNormalizeReference(typeReference, out var normalizedTypeRef) &&
_typeRegistry.TryGetType(normalizedTypeRef, out var registration))
Expand Down
Expand Up @@ -373,7 +373,6 @@ public bool Consume(ISyntaxInfo syntaxInfo)
sourceText.Append($" var p{item.Key} = ");
sourceText.Append("scope.ServiceProvider.GetRequiredService<");
sourceText.Append(item.Value);
TestLog.Log("scoped: " + item.Value);
sourceText.AppendLine(">();");
}
}
Expand All @@ -383,7 +382,6 @@ public bool Consume(ISyntaxInfo syntaxInfo)
{
sourceText.Append($" var p{item.Key} = _services.GetRequiredService<");
sourceText.Append(item.Value);
TestLog.Log("non scoped: " + item.Value);
sourceText.AppendLine(">();");
}
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ internal class ConnectionType
{
internal ConnectionType(
string connectionName,
ITypeReference nodeType,
TypeReference nodeType,
bool withTotalCount)
{
if (nodeType is null)
Expand Down Expand Up @@ -68,7 +68,7 @@ internal class ConnectionType
ApplyConfigurationOn.BeforeCompletion));
}

internal ConnectionType(ITypeReference nodeType, bool withTotalCount)
internal ConnectionType(TypeReference nodeType, bool withTotalCount)
{
if (nodeType is null)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ internal ConnectionType(ITypeReference nodeType, bool withTotalCount)

private static ObjectTypeDefinition CreateTypeDefinition(
bool withTotalCount,
ITypeReference? edgesType = null)
TypeReference? edgesType = null)
{
var definition = new ObjectTypeDefinition
{
Expand Down
6 changes: 3 additions & 3 deletions src/HotChocolate/Core/src/Types.CursorPagination/EdgeType.cs
Expand Up @@ -13,7 +13,7 @@ internal sealed class EdgeType : ObjectType, IEdgeType
{
internal EdgeType(
string connectionName,
ITypeReference nodeType)
TypeReference nodeType)
{
if (nodeType is null)
{
Expand All @@ -35,7 +35,7 @@ internal sealed class EdgeType : ObjectType, IEdgeType
ApplyConfigurationOn.BeforeCompletion));
}

internal EdgeType(ITypeReference nodeType)
internal EdgeType(TypeReference nodeType)
{
if (nodeType is null)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public override bool IsInstanceOfType(IResolverContext context, object resolverR
return false;
}

private static ObjectTypeDefinition CreateTypeDefinition(ITypeReference nodeType)
private static ObjectTypeDefinition CreateTypeDefinition(TypeReference nodeType)
=> new()
{
Description = EdgeType_Description,
Expand Down
Expand Up @@ -145,7 +145,7 @@ public static class PagingObjectFieldDescriptorExtensions
: null;
}
ITypeReference? typeRef = nodeType is not null
TypeReference? typeRef = nodeType is not null
? c.TypeInspector.GetTypeRef(nodeType)
: null;
Expand Down Expand Up @@ -200,7 +200,7 @@ public static class PagingObjectFieldDescriptorExtensions
: null;
}
ITypeReference? typeRef = nodeType is not null
TypeReference? typeRef = nodeType is not null
? c.TypeInspector.GetTypeRef(nodeType)
: null;
Expand Down Expand Up @@ -298,7 +298,7 @@ public static class PagingObjectFieldDescriptorExtensions
this IList<ArgumentDefinition> arguments,
string name,
string description,
ITypeReference type)
TypeReference type)
{
var argument = arguments.FirstOrDefault(t => t.Name.EqualsOrdinal(name));

Expand All @@ -312,11 +312,11 @@ public static class PagingObjectFieldDescriptorExtensions
argument.Type = type;
}

private static ITypeReference CreateConnectionTypeRef(
private static TypeReference CreateConnectionTypeRef(
IDescriptorContext context,
MemberInfo? resolverMember,
string? connectionName,
ITypeReference? nodeType,
TypeReference? nodeType,
PagingOptions options)
{
var typeInspector = context.TypeInspector;
Expand Down Expand Up @@ -390,9 +390,9 @@ public static class PagingObjectFieldDescriptorExtensions
return new QueryableCursorPagingProvider();
}

private static ITypeReference CreateConnectionType(
private static TypeReference CreateConnectionType(
string? connectionName,
ITypeReference nodeType,
TypeReference nodeType,
bool withTotalCount)
{
return connectionName is null
Expand Down
Expand Up @@ -21,7 +21,7 @@ internal sealed class MutationConventionTypeInterceptor : TypeInterceptor
private IDescriptorContext _context = default!;
private List<MutationContextData> _mutations = default!;
private ITypeCompletionContext _completionContext = default!;
private ITypeReference? _errorInterfaceTypeRef;
private TypeReference? _errorInterfaceTypeRef;
private ObjectTypeDefinition? _mutationTypeDef;
private FieldMiddlewareDefinition? _errorNullMiddleware;

Expand Down Expand Up @@ -452,10 +452,10 @@ argument.Formatters.Count switch
return UnionType.CreateUnsafe(unionDef);
}

private static ITypeReference CreateErrorTypeRef(ITypeDiscoveryContext context)
private static TypeReference CreateErrorTypeRef(ITypeDiscoveryContext context)
=> CreateErrorTypeRef(context.DescriptorContext);

private static ITypeReference CreateErrorTypeRef(IDescriptorContext context)
private static TypeReference CreateErrorTypeRef(IDescriptorContext context)
{
var errorInterfaceType =
context.ContextData.TryGetValue(ErrorType, out var value) &&
Expand All @@ -473,7 +473,7 @@ private static ITypeReference CreateErrorTypeRef(IDescriptorContext context)

private static void TryAddErrorInterface(
ObjectTypeDefinition objectTypeDef,
ITypeReference errorInterfaceTypeRef)
TypeReference errorInterfaceTypeRef)
{
if (objectTypeDef.ContextData.IsError())
{
Expand Down Expand Up @@ -660,7 +660,7 @@ private void RegisterType(TypeSystemObjectBase type)
}
}

private ITypeReference EnsureNullable(ITypeReference typeRef)
private TypeReference EnsureNullable(TypeReference typeRef)
{
var type = _completionContext.GetType<IType>(typeRef);

Expand All @@ -672,7 +672,7 @@ private ITypeReference EnsureNullable(ITypeReference typeRef)
return Create(CreateTypeNode(nt.Type));
}

private ITypeReference EnsureNonNull(ITypeReference typeRef)
private TypeReference EnsureNonNull(TypeReference typeRef)
{
var type = _completionContext.GetType<IType>(typeRef);

Expand Down Expand Up @@ -747,14 +747,14 @@ public string FormatErrorTypeName(string mutationName)

private readonly struct FieldDef
{
public FieldDef(string name, ITypeReference type)
public FieldDef(string name, TypeReference type)
{
Name = name;
Type = type;
}

public string Name { get; }

public ITypeReference Type { get; }
public TypeReference Type { get; }
}
}
Expand Up @@ -12,9 +12,9 @@ public MutationResultTypeDiscoveryHandler(ITypeInspector typeInspector)
}

public override bool TryInferType(
ITypeReference typeReference,
TypeReference typeReference,
TypeDiscoveryInfo typeInfo,
[NotNullWhen(true)] out ITypeReference[]? schemaTypeRefs)
[NotNullWhen(true)] out TypeReference[]? schemaTypeRefs)
{
var runtimeType = typeInfo.RuntimeType;

Expand All @@ -23,7 +23,7 @@ public MutationResultTypeDiscoveryHandler(ITypeInspector typeInspector)
typeReference is ExtendedTypeReference typeRef)
{
var type = _typeInspector.GetType(runtimeType.GenericTypeArguments[0]);
schemaTypeRefs = new ITypeReference[runtimeType.GenericTypeArguments.Length];
schemaTypeRefs = new TypeReference[runtimeType.GenericTypeArguments.Length];
schemaTypeRefs[0] = typeRef.WithType(type);

for (var i = 1; i < runtimeType.GenericTypeArguments.Length; i++)
Expand Down
Expand Up @@ -16,7 +16,7 @@ internal class CollectionSegmentType
{
internal CollectionSegmentType(
string? collectionSegmentName,
ITypeReference nodeType,
TypeReference nodeType,
bool withTotalCount)
{
if (nodeType is null)
Expand Down
Expand Up @@ -116,7 +116,7 @@ public static class OffsetPagingObjectFieldDescriptorExtensions
: null;
}
ITypeReference? typeRef = itemType is not null
TypeReference? typeRef = itemType is not null
? c.TypeInspector.GetTypeRef(itemType)
: null;
Expand Down Expand Up @@ -205,7 +205,7 @@ public static class OffsetPagingObjectFieldDescriptorExtensions
: null;
}
ITypeReference? typeRef = itemType is not null
TypeReference? typeRef = itemType is not null
? c.TypeInspector.GetTypeRef(itemType)
: null;
Expand Down Expand Up @@ -255,11 +255,11 @@ public static class OffsetPagingObjectFieldDescriptorExtensions
.Argument(OffsetPagingArgumentNames.Take, a => a.Type<IntType>());
}

private static ITypeReference CreateTypeRef(
private static TypeReference CreateTypeRef(
IDescriptorContext context,
MemberInfo? resolverMember,
string? collectionSegmentName,
ITypeReference? itemsType,
TypeReference? itemsType,
PagingOptions options)
{
var typeInspector = context.TypeInspector;
Expand Down
Expand Up @@ -14,7 +14,7 @@ namespace HotChocolate.Configuration;

internal sealed class AggregateTypeInterceptor : TypeInterceptor
{
private readonly List<ITypeReference> _typeReferences = new();
private readonly List<TypeReference> _typeReferences = new();
private TypeInterceptor[] _typeInterceptors;

public AggregateTypeInterceptor()
Expand Down Expand Up @@ -125,7 +125,7 @@ public override void OnTypeRegistered(ITypeDiscoveryContext discoveryContext)
}
}

public override IEnumerable<ITypeReference> RegisterMoreTypes(
public override IEnumerable<TypeReference> RegisterMoreTypes(
IReadOnlyCollection<ITypeDiscoveryContext> discoveryContexts)
{
_typeReferences.Clear();
Expand Down
Expand Up @@ -54,7 +54,7 @@ public interface ITypeCompletionContext : ITypeSystemObjectContext
/// <returns>
/// <c>true</c> if the type has been resolved; otherwise, <c>false</c>.
/// </returns>
bool TryGetType<T>(ITypeReference typeRef, [NotNullWhen(true)] out T? type) where T : IType;
bool TryGetType<T>(TypeReference typeRef, [NotNullWhen(true)] out T? type) where T : IType;

/// <summary>
/// Gets a type by it's type reference.
Expand All @@ -71,7 +71,7 @@ public interface ITypeCompletionContext : ITypeSystemObjectContext
/// <exception cref="SchemaException">
/// The type could not be resolved for the given <paramref name="typeRef" />.
/// </exception>
T GetType<T>(ITypeReference typeRef) where T : IType;
T GetType<T>(TypeReference typeRef) where T : IType;

/// <summary>
/// Rewrites a type reference to a named type reference.
Expand All @@ -82,14 +82,14 @@ public interface ITypeCompletionContext : ITypeSystemObjectContext
/// <returns>
/// Returns a direct reference to a named type.
/// </returns>
ITypeReference GetNamedTypeReference(ITypeReference typeRef);
TypeReference GetNamedTypeReference(TypeReference typeRef);

/// <summary>
/// Gets all registered types of <typeparamref name="T"/>.
/// </summary>
IEnumerable<T> GetTypes<T>() where T : IType;

bool TryGetDirectiveType(
ITypeReference directiveRef,
TypeReference directiveRef,
[NotNullWhen(true)] out DirectiveType? directiveType);
}

0 comments on commit 802c9b8

Please sign in to comment.