-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Fusion Composition validation
- Loading branch information
Showing
23 changed files
with
404 additions
and
264 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Collections/MultiValueDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, IList<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); | ||
} | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Errors/ErrorHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Events/EventAggregator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using HotChocolate.Fusion.Collections; | ||
|
||
namespace HotChocolate.Fusion.Events; | ||
|
||
internal sealed class EventAggregator | ||
{ | ||
private readonly MultiValueDictionary<Type, Delegate> _subscribers = new(); | ||
|
||
public void Subscribe<TEvent>(Action<TEvent> handler) | ||
{ | ||
_subscribers.Add(typeof(TEvent), handler); | ||
} | ||
|
||
public void Unsubscribe<TEvent>(Action<TEvent> handler) | ||
{ | ||
_subscribers.Remove(typeof(TEvent), handler); | ||
} | ||
|
||
public void Publish<TEvent>(TEvent @event) | ||
{ | ||
if (_subscribers.ContainsKey(typeof(TEvent))) | ||
{ | ||
foreach (var handler in _subscribers[typeof(TEvent)]) | ||
{ | ||
((Action<TEvent>)handler)(@event); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LoggingSession.cs
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...src/Fusion.Composition/PreMergeValidation/Contracts/IEachDirectiveArgumentEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace HotChocolate.Fusion.PreMergeValidation.Contracts; | ||
|
||
internal interface IEachDirectiveArgumentEventHandler | ||
{ | ||
void OnEachDirectiveArgument(EachDirectiveArgumentEvent @event); | ||
} |
6 changes: 6 additions & 0 deletions
6
...n-vnext/src/Fusion.Composition/PreMergeValidation/Contracts/IEachDirectiveEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace HotChocolate.Fusion.PreMergeValidation.Contracts; | ||
|
||
internal interface IEachDirectiveEventHandler | ||
{ | ||
void OnEachDirective(EachDirectiveEvent @event); | ||
} |
6 changes: 6 additions & 0 deletions
6
...ext/src/Fusion.Composition/PreMergeValidation/Contracts/IEachFieldArgumentEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace HotChocolate.Fusion.PreMergeValidation.Contracts; | ||
|
||
internal interface IEachFieldArgumentEventHandler | ||
{ | ||
void OnEachFieldArgument(EachFieldArgumentEvent @event); | ||
} |
6 changes: 6 additions & 0 deletions
6
...vnext/src/Fusion.Composition/PreMergeValidation/Contracts/IEachOutputFieldEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace HotChocolate.Fusion.PreMergeValidation.Contracts; | ||
|
||
internal interface IEachOutputFieldEventHandler | ||
{ | ||
void OnEachOutputField(EachOutputFieldEvent @event); | ||
} |
6 changes: 6 additions & 0 deletions
6
...t/src/Fusion.Composition/PreMergeValidation/Contracts/IEachOutputFieldNameEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace HotChocolate.Fusion.PreMergeValidation.Contracts; | ||
|
||
internal interface IEachOutputFieldNameEventHandler | ||
{ | ||
void OnEachOutputFieldName(EachOutputFieldNameEvent @event); | ||
} |
6 changes: 6 additions & 0 deletions
6
...Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Contracts/IEachTypeEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace HotChocolate.Fusion.PreMergeValidation.Contracts; | ||
|
||
internal interface IEachTypeEventHandler | ||
{ | ||
void OnEachType(EachTypeEvent @event); | ||
} |
8 changes: 0 additions & 8 deletions
8
...sion-vnext/src/Fusion.Composition/PreMergeValidation/Contracts/IPreMergeValidationRule.cs
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Events.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections.Immutable; | ||
using HotChocolate.Skimmed; | ||
|
||
namespace HotChocolate.Fusion.PreMergeValidation; | ||
|
||
internal record EachDirectiveArgumentEvent( | ||
CompositionContext Context, | ||
InputFieldDefinition Argument, | ||
DirectiveDefinition Directive, | ||
SchemaDefinition Schema); | ||
|
||
internal record EachDirectiveEvent( | ||
CompositionContext Context, | ||
DirectiveDefinition Directive, | ||
SchemaDefinition Schema); | ||
|
||
internal record EachFieldArgumentEvent( | ||
CompositionContext Context, | ||
InputFieldDefinition Argument, | ||
OutputFieldDefinition Field, | ||
INamedTypeDefinition Type, | ||
SchemaDefinition Schema); | ||
|
||
internal record EachFieldArgumentNameEvent( | ||
CompositionContext Context, | ||
string ArgumentName, | ||
ImmutableArray<FieldArgumentInfo> ArgumentInfo, | ||
string FieldName, | ||
string TypeName); | ||
|
||
internal record EachOutputFieldEvent( | ||
CompositionContext Context, | ||
OutputFieldDefinition Field, | ||
INamedTypeDefinition Type, | ||
SchemaDefinition Schema); | ||
|
||
internal record EachOutputFieldNameEvent( | ||
CompositionContext Context, | ||
string FieldName, | ||
ImmutableArray<OutputFieldInfo> FieldInfo, | ||
string TypeName); | ||
|
||
internal record EachTypeEvent( | ||
CompositionContext Context, | ||
INamedTypeDefinition Type, | ||
SchemaDefinition Schema); | ||
|
||
internal record EachTypeNameEvent( | ||
CompositionContext Context, | ||
string TypeName, | ||
ImmutableArray<TypeInfo> TypeInfo); |
77 changes: 0 additions & 77 deletions
77
...olate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/PreMergeValidationContext.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.