Skip to content

Commit ad5785a

Browse files
committed
[Fusion] Refactored SchemaComposer
1 parent 0fe4ffb commit ad5785a

File tree

62 files changed

+697
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+697
-414
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/CompositionContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
namespace HotChocolate.Fusion;
66

77
internal sealed class CompositionContext(
8-
ImmutableArray<SchemaDefinition> schemaDefinitions,
8+
ImmutableSortedSet<SchemaDefinition> schemaDefinitions,
99
ICompositionLog compositionLog)
1010
{
1111
/// <summary>
1212
/// Gets the schema definitions.
1313
/// </summary>
14-
public ImmutableArray<SchemaDefinition> SchemaDefinitions { get; } = schemaDefinitions;
14+
public ImmutableSortedSet<SchemaDefinition> SchemaDefinitions { get; } = schemaDefinitions;
1515

1616
/// <summary>
1717
/// Gets the composition log.

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Errors/ErrorHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ namespace HotChocolate.Fusion.Errors;
44

55
internal static class ErrorHelper
66
{
7+
public static CompositionError SourceSchemaParsingFailed()
8+
=> new(ErrorHelper_SourceSchemaParsingFailed);
9+
710
public static CompositionError SourceSchemaValidationFailed()
811
=> new(ErrorHelper_SourceSchemaValidationFailed);
912

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static class LogEntryCodes
1212
public const string InputFieldDefaultMismatch = "INPUT_FIELD_DEFAULT_MISMATCH";
1313
public const string InputFieldTypesNotMergeable = "INPUT_FIELD_TYPES_NOT_MERGEABLE";
1414
public const string InputWithMissingRequiredFields = "INPUT_WITH_MISSING_REQUIRED_FIELDS";
15+
public const string InvalidGraphQL = "INVALID_GRAPHQL";
1516
public const string KeyDirectiveInFieldsArg = "KEY_DIRECTIVE_IN_FIELDS_ARG";
1617
public const string KeyFieldsHasArgs = "KEY_FIELDS_HAS_ARGS";
1718
public const string KeyFieldsSelectInvalidType = "KEY_FIELDS_SELECT_INVALID_TYPE";

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ public static LogEntry InputWithMissingRequiredFields(
266266
schema);
267267
}
268268

269+
public static LogEntry InvalidGraphQL(string exceptionMessage)
270+
{
271+
return new LogEntry(
272+
string.Format(LogEntryHelper_InvalidGraphQL, exceptionMessage),
273+
LogEntryCodes.InvalidGraphQL,
274+
severity: LogSeverity.Error);
275+
}
276+
269277
public static LogEntry KeyDirectiveInFieldsArgument(
270278
string entityTypeName,
271279
Directive keyDirective,

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PostMergeValidator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace HotChocolate.Fusion;
66

7-
internal sealed class PostMergeValidator(IEnumerable<object> rules)
7+
#pragma warning disable CS9113 // Parameter is unread.
8+
internal sealed class PostMergeValidator(
9+
SchemaDefinition mergedSchema,
10+
ImmutableArray<object> rules)
11+
#pragma warning restore CS9113 // Parameter is unread.
812
{
9-
private readonly ImmutableArray<object> _rules = [.. rules];
10-
11-
public CompositionResult Validate(SchemaDefinition _)
13+
public CompositionResult Validate()
1214
{
1315
// FIXME: Implement.
1416
return CompositionResult.Success();

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidator.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,30 @@
33
using HotChocolate.Fusion.Errors;
44
using HotChocolate.Fusion.Events;
55
using HotChocolate.Fusion.Info;
6+
using HotChocolate.Fusion.Logging.Contracts;
67
using HotChocolate.Fusion.PreMergeValidation;
78
using HotChocolate.Fusion.Results;
89
using HotChocolate.Skimmed;
910

1011
namespace HotChocolate.Fusion;
1112

12-
internal sealed class PreMergeValidator(IEnumerable<object> rules)
13+
internal sealed class PreMergeValidator(
14+
ImmutableSortedSet<SchemaDefinition> schemas,
15+
ImmutableArray<object> rules,
16+
ICompositionLog log)
1317
{
14-
private readonly ImmutableArray<object> _rules = [.. rules];
15-
16-
public CompositionResult Validate(CompositionContext context)
18+
public CompositionResult Validate()
1719
{
18-
PublishEvents(context);
20+
PublishEvents();
1921

20-
return context.Log.HasErrors
22+
return log.HasErrors
2123
? ErrorHelper.PreMergeValidationFailed()
2224
: CompositionResult.Success();
2325
}
2426

25-
private void PublishEvents(CompositionContext context)
27+
private void PublishEvents()
2628
{
29+
var context = new CompositionContext(schemas, log);
2730
MultiValueDictionary<string, TypeInfo> typeGroupByName = [];
2831

2932
foreach (var schema in context.SchemaDefinitions)
@@ -127,7 +130,7 @@ private void PublishEvents(CompositionContext context)
127130
private void PublishEvent<TEvent>(TEvent @event, CompositionContext context)
128131
where TEvent : IEvent
129132
{
130-
foreach (var rule in _rules)
133+
foreach (var rule in rules)
131134
{
132135
if (rule is IEventHandler<TEvent> handler)
133136
{

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<data name="ErrorHelper_PreMergeValidationFailed" xml:space="preserve">
2222
<value>Pre-merge validation failed. View the composition log for details.</value>
2323
</data>
24+
<data name="ErrorHelper_SourceSchemaParsingFailed" xml:space="preserve">
25+
<value>Source schema parsing failed. View the composition log for details.</value>
26+
</data>
2427
<data name="ErrorHelper_SourceSchemaValidationFailed" xml:space="preserve">
2528
<value>Source schema validation failed. View the composition log for details.</value>
2629
</data>
@@ -66,6 +69,9 @@
6669
<data name="LogEntryHelper_InputWithMissingRequiredFields" xml:space="preserve">
6770
<value>The input type '{0}' in schema '{1}' must define the required field '{2}'.</value>
6871
</data>
72+
<data name="LogEntryHelper_InvalidGraphQL" xml:space="preserve">
73+
<value>Invalid GraphQL in source schema. Exception message: {0}.</value>
74+
</data>
6975
<data name="LogEntryHelper_KeyDirectiveInFieldsArgument" xml:space="preserve">
7076
<value>A @key directive on type '{0}' in schema '{1}' references field '{2}', which must not include directive applications.</value>
7177
</data>

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Results/CompositionResult~1.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,16 @@ public static implicit operator CompositionResult<TValue>(CompositionResult resu
7676
{
7777
return new CompositionResult<TValue>(result.Errors);
7878
}
79+
80+
public void Deconstruct(
81+
out bool isSuccess,
82+
out bool isFailure,
83+
out TValue value,
84+
out ImmutableArray<CompositionError> errors)
85+
{
86+
isSuccess = IsSuccess;
87+
isFailure = IsFailure;
88+
value = Value;
89+
errors = Errors;
90+
}
7991
}

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/SatisfiabilityValidator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
namespace HotChocolate.Fusion;
55

6-
internal sealed class SatisfiabilityValidator
6+
#pragma warning disable CS9113 // Parameter is unread.
7+
internal sealed class SatisfiabilityValidator(SchemaDefinition mergedSchema)
8+
#pragma warning restore CS9113 // Parameter is unread.
79
{
8-
public CompositionResult Validate(SchemaDefinition _)
10+
public CompositionResult Validate()
911
{
1012
// FIXME: Implement.
1113
return CompositionResult.Success();

0 commit comments

Comments
 (0)