Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Fusion Composition validation (alternative event handling) #7822

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,15 @@ namespace HotChocolate.Fusion.Logging.Contracts;
/// </summary>
public interface ICompositionLog
{
// FIXME: Docs.
bool HasErrors { get; }

// FIXME: Docs.
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();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
using HotChocolate.Fusion.Results;

namespace HotChocolate.Fusion.PreMergeValidation.Contracts;

internal interface IPreMergeValidationRule
{
CompositionResult Run(PreMergeValidationContext context);
void OnEachType(EachTypeEvent @event);

void OnEachOutputField(EachOutputFieldEvent @event);

void OnEachFieldArgument(EachFieldArgumentEvent @event);

void OnEachDirective(EachDirectiveEvent @event);

void OnEachDirectiveArgument(EachDirectiveArgumentEvent @event);

void OnEachTypeGroup(EachTypeGroupEvent @event);

void OnEachOutputFieldGroup(EachOutputFieldGroupEvent @event);

void OnEachFieldArgumentGroup(EachFieldArgumentGroupEvent @event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Immutable;
using HotChocolate.Fusion.Events;
using HotChocolate.Skimmed;

namespace HotChocolate.Fusion.PreMergeValidation;

internal record EachDirectiveArgumentEvent(
CompositionContext Context,
InputFieldDefinition Argument,
DirectiveDefinition Directive,
SchemaDefinition Schema) : IEvent;

internal record EachDirectiveEvent(
CompositionContext Context,
DirectiveDefinition Directive,
SchemaDefinition Schema) : IEvent;

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

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

internal record EachOutputFieldEvent(
CompositionContext Context,
OutputFieldDefinition Field,
INamedTypeDefinition Type,
SchemaDefinition Schema) : IEvent;

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

internal record EachTypeEvent(
CompositionContext Context,
INamedTypeDefinition Type,
SchemaDefinition Schema) : IEvent;

internal record EachTypeGroupEvent(
CompositionContext Context,
string TypeName,
ImmutableArray<TypeInfo> TypeGroup) : IEvent;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using HotChocolate.Fusion.PreMergeValidation.Contracts;

namespace HotChocolate.Fusion.PreMergeValidation;

internal abstract class PreMergeValidationRule : IPreMergeValidationRule
{
public virtual void OnEachType(EachTypeEvent @event)
{
}

public virtual void OnEachOutputField(EachOutputFieldEvent @event)
{
}

public virtual void OnEachFieldArgument(EachFieldArgumentEvent @event)
{
}

public virtual void OnEachDirective(EachDirectiveEvent @event)
{
}

public virtual void OnEachDirectiveArgument(EachDirectiveArgumentEvent @event)
{
}

public virtual void OnEachTypeGroup(EachTypeGroupEvent @event)
{
}

public virtual void OnEachOutputFieldGroup(EachOutputFieldGroupEvent @event)
{
}

public virtual void OnEachFieldArgumentGroup(EachFieldArgumentGroupEvent @event)
{
}
}
Loading
Loading