Skip to content

Commit

Permalink
Refactored Fusion Composition validation (#7821)
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Dec 13, 2024
1 parent 410d897 commit 9021541
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 281 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace HotChocolate.Fusion.Collections;

internal sealed class MultiValueDictionary<TKey, TValue>
: Dictionary<TKey, List<TValue>> where TKey : notnull
{
public void Add(TKey key, TValue value)
{
ArgumentNullException.ThrowIfNull(key);

if (!TryGetValue(key, out var list))
{
list = [];
Add(key, list);
}

list.Add(value);
}

public void Remove(TKey key, TValue value)
{
ArgumentNullException.ThrowIfNull(key);

if (TryGetValue(key, out var list))
{
list.Remove(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using HotChocolate.Fusion.PreMergeValidation.Contracts;
using static HotChocolate.Fusion.Properties.CompositionResources;

namespace HotChocolate.Fusion.Errors;

internal static class ErrorHelper
{
public static CompositionError PreMergeValidationRuleFailed(IPreMergeValidationRule rule)
=> new(string.Format(ErrorHelper_PreMergeValidationRuleFailed, rule.GetType().Name));
public static CompositionError PreMergeValidationFailed()
=> new(ErrorHelper_PreMergeValidationFailed);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace HotChocolate.Fusion.Events;

internal interface IEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace HotChocolate.Fusion.Events;

internal interface IEventHandler<in TEvent> where TEvent : IEvent
{
void Handle(TEvent @event, CompositionContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace HotChocolate.Fusion.Logging;

public sealed class CompositionLog : ICompositionLog, IEnumerable<LogEntry>
{
public bool HasErrors { get; private set; }

public bool IsEmpty => _entries.Count == 0;

private readonly List<LogEntry> _entries = [];
Expand All @@ -13,12 +15,12 @@ public void Write(LogEntry entry)
{
ArgumentNullException.ThrowIfNull(entry);

_entries.Add(entry);
}
if (entry.Severity == LogSeverity.Error)
{
HasErrors = true;
}

public ILoggingSession CreateSession()
{
return new LoggingSession(this);
_entries.Add(entry);
}

public IEnumerator<LogEntry> GetEnumerator() => _entries.GetEnumerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ namespace HotChocolate.Fusion.Logging.Contracts;
/// </summary>
public interface ICompositionLog
{
/// <summary>
/// Gets a value indicating whether the log contains errors.
/// </summary>
bool HasErrors { get; }

/// <summary>
/// Gets a value indicating whether the log is empty.
/// </summary>
bool IsEmpty { get; }

/// <summary>
/// Writes the specified <see cref="LogEntry"/> to the log.
/// </summary>
/// <param name="entry">The <see cref="LogEntry"/> to write.</param>
void Write(LogEntry entry);

/// <summary>
/// Creates a new logging session that keeps track of the number of info, warning, and error
/// entries logged.
/// </summary>
ILoggingSession CreateSession();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace HotChocolate.Fusion.Logging;

internal static class LogEntryHelper
{
public static LogEntry DisallowedInaccessibleScalar(
public static LogEntry DisallowedInaccessibleBuiltInScalar(
ScalarTypeDefinition scalar,
SchemaDefinition schema)
=> new(
string.Format(LogEntryHelper_DisallowedInaccessibleScalar, scalar.Name),
string.Format(LogEntryHelper_DisallowedInaccessibleBuiltInScalar, scalar.Name),
LogEntryCodes.DisallowedInaccessible,
LogSeverity.Error,
new SchemaCoordinate(scalar.Name),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Immutable;
using HotChocolate.Fusion.Events;
using HotChocolate.Skimmed;

namespace HotChocolate.Fusion.PreMergeValidation;

internal record DirectiveArgumentEvent(
InputFieldDefinition Argument,
DirectiveDefinition Directive,
SchemaDefinition Schema) : IEvent;

internal record DirectiveEvent(
DirectiveDefinition Directive,
SchemaDefinition Schema) : IEvent;

internal record FieldArgumentEvent(
InputFieldDefinition Argument,
OutputFieldDefinition Field,
INamedTypeDefinition Type,
SchemaDefinition Schema) : IEvent;

internal record FieldArgumentGroupEvent(
string ArgumentName,
ImmutableArray<FieldArgumentInfo> ArgumentGroup,
string FieldName,
string TypeName) : IEvent;

internal record OutputFieldEvent(
OutputFieldDefinition Field,
INamedTypeDefinition Type,
SchemaDefinition Schema) : IEvent;

internal record OutputFieldGroupEvent(
string FieldName,
ImmutableArray<OutputFieldInfo> FieldGroup,
string TypeName) : IEvent;

internal record TypeEvent(
INamedTypeDefinition Type,
SchemaDefinition Schema) : IEvent;

internal record TypeGroupEvent(
string TypeName,
ImmutableArray<TypeInfo> TypeGroup) : IEvent;

This file was deleted.

Loading

0 comments on commit 9021541

Please sign in to comment.