diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Extensions/DirectivesProviderExtensions.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Extensions/DirectivesProviderExtensions.cs new file mode 100644 index 00000000000..5bef95a943f --- /dev/null +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Extensions/DirectivesProviderExtensions.cs @@ -0,0 +1,37 @@ +using HotChocolate.Skimmed; +using static HotChocolate.Fusion.WellKnownDirectiveNames; + +namespace HotChocolate.Fusion.Extensions; + +internal static class DirectivesProviderExtensions +{ + public static bool HasExternalDirective(this IDirectivesProvider type) + { + return type.Directives.ContainsName(External); + } + + public static bool HasInaccessibleDirective(this IDirectivesProvider type) + { + return type.Directives.ContainsName(Inaccessible); + } + + public static bool HasInternalDirective(this IDirectivesProvider type) + { + return type.Directives.ContainsName(Internal); + } + + public static bool HasLookupDirective(this IDirectivesProvider type) + { + return type.Directives.ContainsName(Lookup); + } + + public static bool HasOverrideDirective(this IDirectivesProvider type) + { + return type.Directives.ContainsName(Override); + } + + public static bool HasProvidesDirective(this IDirectivesProvider type) + { + return type.Directives.ContainsName(Provides); + } +} diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryCodes.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryCodes.cs index a7b9357dd6a..98c702f4eb8 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryCodes.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryCodes.cs @@ -18,8 +18,8 @@ public static class LogEntryCodes public const string KeyInvalidFields = "KEY_INVALID_FIELDS"; public const string KeyInvalidFieldsType = "KEY_INVALID_FIELDS_TYPE"; public const string KeyInvalidSyntax = "KEY_INVALID_SYNTAX"; - public const string LookupMustNotReturnList = "LOOKUP_MUST_NOT_RETURN_LIST"; - public const string LookupShouldHaveNullableReturnType = "LOOKUP_SHOULD_HAVE_NULLABLE_RETURN_TYPE"; + public const string LookupReturnsList = "LOOKUP_RETURNS_LIST"; + public const string LookupReturnsNonNullableType = "LOOKUP_RETURNS_NON_NULLABLE_TYPE"; public const string OutputFieldTypesNotMergeable = "OUTPUT_FIELD_TYPES_NOT_MERGEABLE"; public const string OverrideFromSelf = "OVERRIDE_FROM_SELF"; public const string OverrideOnInterface = "OVERRIDE_ON_INTERFACE"; diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryHelper.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryHelper.cs index 369867b9cfe..13ec45f630d 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryHelper.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryHelper.cs @@ -378,7 +378,7 @@ public static LogEntry KeyInvalidSyntax( schema); } - public static LogEntry LookupMustNotReturnList( + public static LogEntry LookupReturnsList( OutputFieldDefinition field, INamedTypeDefinition type, SchemaDefinition schema) @@ -387,17 +387,17 @@ public static LogEntry LookupMustNotReturnList( return new LogEntry( string.Format( - LogEntryHelper_LookupMustNotReturnList, + LogEntryHelper_LookupReturnsList, coordinate, schema.Name), - LogEntryCodes.LookupMustNotReturnList, + LogEntryCodes.LookupReturnsList, LogSeverity.Error, coordinate, field, schema); } - public static LogEntry LookupShouldHaveNullableReturnType( + public static LogEntry LookupReturnsNonNullableType( OutputFieldDefinition field, INamedTypeDefinition type, SchemaDefinition schema) @@ -406,10 +406,10 @@ public static LogEntry LookupShouldHaveNullableReturnType( return new LogEntry( string.Format( - LogEntryHelper_LookupShouldHaveNullableReturnType, + LogEntryHelper_LookupReturnsNonNullableType, coordinate, schema.Name), - LogEntryCodes.LookupShouldHaveNullableReturnType, + LogEntryCodes.LookupReturnsNonNullableType, LogSeverity.Warning, coordinate, field, diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Events.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Events.cs index 8ba8adb381f..da16f7533ac 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Events.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Events.cs @@ -45,29 +45,29 @@ internal record InputTypeGroupEvent( ImmutableArray InputTypeGroup) : IEvent; internal record KeyFieldEvent( - ComplexTypeDefinition EntityType, Directive KeyDirective, + ComplexTypeDefinition EntityType, OutputFieldDefinition Field, ComplexTypeDefinition Type, SchemaDefinition Schema) : IEvent; internal record KeyFieldNodeEvent( - ComplexTypeDefinition EntityType, - Directive KeyDirective, FieldNode FieldNode, ImmutableArray FieldNamePath, + Directive KeyDirective, + ComplexTypeDefinition EntityType, SchemaDefinition Schema) : IEvent; internal record KeyFieldsInvalidReferenceEvent( - ComplexTypeDefinition EntityType, - Directive KeyDirective, FieldNode FieldNode, ComplexTypeDefinition Type, + Directive KeyDirective, + ComplexTypeDefinition EntityType, SchemaDefinition Schema) : IEvent; internal record KeyFieldsInvalidSyntaxEvent( - ComplexTypeDefinition EntityType, Directive KeyDirective, + ComplexTypeDefinition EntityType, SchemaDefinition Schema) : IEvent; internal record KeyFieldsInvalidTypeEvent( @@ -129,6 +129,13 @@ internal record RequireFieldsInvalidSyntaxEvent( ComplexTypeDefinition Type, SchemaDefinition Schema) : IEvent; +internal record RequireFieldsInvalidTypeEvent( + Directive RequireDirective, + InputFieldDefinition Argument, + OutputFieldDefinition Field, + ComplexTypeDefinition Type, + SchemaDefinition Schema) : IEvent; + internal record SchemaEvent(SchemaDefinition Schema) : IEvent; internal record TypeEvent( diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/PreMergeValidator.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/PreMergeValidator.cs index 46e078bd3ec..2150f6dd118 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/PreMergeValidator.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/PreMergeValidator.cs @@ -184,8 +184,7 @@ private void PublishEntityEvents( foreach (var keyDirective in keyDirectives) { - if ( - !keyDirective.Arguments.TryGetValue(WellKnownArgumentNames.Fields, out var f) + if (!keyDirective.Arguments.TryGetValue(WellKnownArgumentNames.Fields, out var f) || f is not StringValueNode fields) { PublishEvent( @@ -211,7 +210,7 @@ private void PublishEntityEvents( catch (SyntaxException) { PublishEvent( - new KeyFieldsInvalidSyntaxEvent(entityType, keyDirective, schema), + new KeyFieldsInvalidSyntaxEvent(keyDirective, entityType, schema), context); } } @@ -236,10 +235,10 @@ private void PublishKeyFieldEvents( PublishEvent( new KeyFieldNodeEvent( - entityType, - keyDirective, fieldNode, [.. fieldNamePath], + keyDirective, + entityType, schema), context); @@ -249,8 +248,8 @@ private void PublishKeyFieldEvents( { PublishEvent( new KeyFieldEvent( - entityType, keyDirective, + entityType, field, parentType, schema), @@ -265,10 +264,10 @@ private void PublishKeyFieldEvents( { PublishEvent( new KeyFieldsInvalidReferenceEvent( - entityType, - keyDirective, fieldNode, parentType, + keyDirective, + entityType, schema), context); @@ -302,8 +301,7 @@ private void PublishProvidesEvents( var providesDirective = field.Directives.First(d => d.Name == WellKnownDirectiveNames.Provides); - if ( - !providesDirective.Arguments.TryGetValue(WellKnownArgumentNames.Fields, out var f) + if (!providesDirective.Arguments.TryGetValue(WellKnownArgumentNames.Fields, out var f) || f is not StringValueNode fields) { PublishEvent( @@ -365,8 +363,7 @@ private void PublishProvidesFieldEvents( if (parentType?.NullableType() is ComplexTypeDefinition providedType) { - if ( - providedType.Fields.TryGetField( + if (providedType.Fields.TryGetField( fieldNode.Name.Value, out var providedField)) { @@ -419,10 +416,13 @@ private void PublishRequireEvents( var requireDirective = argument.Directives.First(d => d.Name == WellKnownDirectiveNames.Require); - if ( - !requireDirective.Arguments.TryGetValue(WellKnownArgumentNames.Fields, out var f) + if (!requireDirective.Arguments.TryGetValue(WellKnownArgumentNames.Fields, out var f) || f is not StringValueNode fields) { + PublishEvent( + new RequireFieldsInvalidTypeEvent(requireDirective, argument, field, type, schema), + context); + return; } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/DisallowedInaccessibleElementsRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/DisallowedInaccessibleElementsRule.cs index 9e3823dba32..5ce9c49bc68 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/DisallowedInaccessibleElementsRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/DisallowedInaccessibleElementsRule.cs @@ -1,4 +1,5 @@ using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Skimmed; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -25,13 +26,13 @@ public void Handle(TypeEvent @event, CompositionContext context) // Built-in scalar types must be accessible. if (type is ScalarTypeDefinition { IsSpecScalar: true } scalar - && !ValidationHelper.IsAccessible(scalar)) + && scalar.HasInaccessibleDirective()) { context.Log.Write(DisallowedInaccessibleBuiltInScalar(scalar, schema)); } // Introspection types must be accessible. - if (type.IsIntrospectionType && !ValidationHelper.IsAccessible(type)) + if (type.IsIntrospectionType && type.HasInaccessibleDirective()) { context.Log.Write(DisallowedInaccessibleIntrospectionType(type, schema)); } @@ -42,7 +43,7 @@ public void Handle(OutputFieldEvent @event, CompositionContext context) var (field, type, schema) = @event; // Introspection fields must be accessible. - if (type.IsIntrospectionType && !ValidationHelper.IsAccessible(field)) + if (type.IsIntrospectionType && field.HasInaccessibleDirective()) { context.Log.Write( DisallowedInaccessibleIntrospectionField( @@ -57,7 +58,7 @@ public void Handle(FieldArgumentEvent @event, CompositionContext context) var (argument, field, type, schema) = @event; // Introspection arguments must be accessible. - if (type.IsIntrospectionType && !ValidationHelper.IsAccessible(argument)) + if (type.IsIntrospectionType && argument.HasInaccessibleDirective()) { context.Log.Write( DisallowedInaccessibleIntrospectionArgument( @@ -73,7 +74,7 @@ public void Handle(DirectiveArgumentEvent @event, CompositionContext context) var (argument, directive, schema) = @event; // Built-in directive arguments must be accessible. - if (BuiltIns.IsBuiltInDirective(directive.Name) && !ValidationHelper.IsAccessible(argument)) + if (BuiltIns.IsBuiltInDirective(directive.Name) && argument.HasInaccessibleDirective()) { context.Log.Write( DisallowedInaccessibleDirectiveArgument( diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/EnumValuesMismatchRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/EnumValuesMismatchRule.cs index d2b4dcdbd16..b2dec6f5f80 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/EnumValuesMismatchRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/EnumValuesMismatchRule.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using static HotChocolate.Fusion.Logging.LogEntryHelper; namespace HotChocolate.Fusion.PreMergeValidation.Rules; @@ -34,7 +35,7 @@ public void Handle(EnumTypeGroupEvent @event, CompositionContext context) var enumValues = enumGroup .SelectMany(e => e.Type.Values) - .Where(ValidationHelper.IsAccessible) + .Where(v => !v.HasInaccessibleDirective()) .Select(v => v.Name) .ToImmutableHashSet(); diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalArgumentDefaultMismatchRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalArgumentDefaultMismatchRule.cs index 9b84ebc3069..5831e6be917 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalArgumentDefaultMismatchRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalArgumentDefaultMismatchRule.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Language; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -20,7 +21,7 @@ public void Handle(OutputFieldGroupEvent @event, CompositionContext context) var (fieldName, fieldGroup, typeName) = @event; var externalFields = fieldGroup - .Where(i => ValidationHelper.IsExternal(i.Field)) + .Where(i => i.Field.HasExternalDirective()) .ToImmutableArray(); if (externalFields.Length == 0) diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalMissingOnBaseRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalMissingOnBaseRule.cs index 46a9dd2308b..6f33e46eb99 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalMissingOnBaseRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalMissingOnBaseRule.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using static HotChocolate.Fusion.Logging.LogEntryHelper; namespace HotChocolate.Fusion.PreMergeValidation.Rules; @@ -20,7 +21,7 @@ public void Handle(OutputFieldGroupEvent @event, CompositionContext context) var fieldGroup = @event.FieldGroup; var externalFields = fieldGroup - .Where(i => ValidationHelper.IsExternal(i.Field)) + .Where(i => i.Field.HasExternalDirective()) .ToImmutableArray(); var nonExternalFieldCount = fieldGroup.Length - externalFields.Length; diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalOnInterfaceRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalOnInterfaceRule.cs index 39fb5b96070..d15bd16d365 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalOnInterfaceRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalOnInterfaceRule.cs @@ -1,4 +1,5 @@ using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Skimmed; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -21,7 +22,7 @@ public void Handle(OutputFieldEvent @event, CompositionContext context) { var (field, type, schema) = @event; - if (type is InterfaceTypeDefinition && ValidationHelper.IsExternal(field)) + if (type is InterfaceTypeDefinition && field.HasExternalDirective()) { context.Log.Write(ExternalOnInterface(field, type, schema)); } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalUnusedRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalUnusedRule.cs index 74b9833a0cc..a25d9936141 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalUnusedRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ExternalUnusedRule.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Skimmed; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -18,7 +19,7 @@ public void Handle(OutputFieldEvent @event, CompositionContext context) { var (field, type, schema) = @event; - if (ValidationHelper.IsExternal(field)) + if (field.HasExternalDirective()) { var referencingFields = schema.Types diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/FieldArgumentTypesMergeableRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/FieldArgumentTypesMergeableRule.cs index 7a894b587e9..49af11d7cf9 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/FieldArgumentTypesMergeableRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/FieldArgumentTypesMergeableRule.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using static HotChocolate.Fusion.Logging.LogEntryHelper; namespace HotChocolate.Fusion.PreMergeValidation.Rules; @@ -24,10 +25,10 @@ public void Handle(FieldArgumentGroupEvent @event, CompositionContext context) var argumentGroupVisible = argumentGroup .Where( i => - ValidationHelper.IsAccessible(i.Type) - && !ValidationHelper.IsInternal(i.Type) - && ValidationHelper.IsAccessible(i.Field) - && !ValidationHelper.IsInternal(i.Field)) + !i.Type.HasInaccessibleDirective() + && !i.Type.HasInternalDirective() + && !i.Field.HasInaccessibleDirective() + && !i.Field.HasInternalDirective()) .ToImmutableArray(); for (var i = 0; i < argumentGroupVisible.Length - 1; i++) diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/InputWithMissingRequiredFieldsRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/InputWithMissingRequiredFieldsRule.cs index 74326899780..b7b1a9c166f 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/InputWithMissingRequiredFieldsRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/InputWithMissingRequiredFieldsRule.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Skimmed; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -21,15 +22,15 @@ public void Handle(InputTypeGroupEvent @event, CompositionContext context) var requiredFieldNames = inputTypeGroup - .Where(i => ValidationHelper.IsAccessible(i.InputType)) + .Where(i => !i.InputType.HasInaccessibleDirective()) .SelectMany(i => i.InputType.Fields) - .Where(f => ValidationHelper.IsAccessible(f) && f.Type is NonNullTypeDefinition) + .Where(f => !f.HasInaccessibleDirective() && f.Type is NonNullTypeDefinition) .Select(f => f.Name) .ToImmutableHashSet(); foreach (var (inputType, schema) in inputTypeGroup) { - if (ValidationHelper.IsInaccessible(inputType)) + if (inputType.HasInaccessibleDirective()) { continue; } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyDirectiveInFieldsArgumentRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyDirectiveInFieldsArgumentRule.cs index a283626ed88..c7f0e2e4d30 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyDirectiveInFieldsArgumentRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyDirectiveInFieldsArgumentRule.cs @@ -15,7 +15,7 @@ internal sealed class KeyDirectiveInFieldsArgumentRule : IEventHandler { public void Handle(KeyFieldEvent @event, CompositionContext context) { - var (entityType, keyDirective, field, type, schema) = @event; + var (keyDirective, entityType, field, type, schema) = @event; if (field.Arguments.Count != 0) { diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyFieldsSelectInvalidTypeRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyFieldsSelectInvalidTypeRule.cs index ef29a45f3ea..5e18aeebf71 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyFieldsSelectInvalidTypeRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/KeyFieldsSelectInvalidTypeRule.cs @@ -18,7 +18,7 @@ internal sealed class KeyFieldsSelectInvalidTypeRule : IEventHandler@lookup must have a return type that is NOT a list. /// -/// +/// /// Specification /// -internal sealed class LookupMustNotReturnListRule : IEventHandler +internal sealed class LookupReturnsListRule : IEventHandler { public void Handle(OutputFieldEvent @event, CompositionContext context) { var (field, type, schema) = @event; - if (ValidationHelper.IsLookup(field) && field.Type.NullableType() is ListTypeDefinition) + if (field.HasLookupDirective() && field.Type.NullableType() is ListTypeDefinition) { - context.Log.Write(LookupMustNotReturnList(field, type, schema)); + context.Log.Write(LookupReturnsList(field, type, schema)); } } } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupReturnsNonNullableTypeRule.cs similarity index 72% rename from src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRule.cs rename to src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupReturnsNonNullableTypeRule.cs index d1e779e0632..f85b3d901ae 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/LookupReturnsNonNullableTypeRule.cs @@ -1,4 +1,5 @@ using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Skimmed; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -11,18 +12,18 @@ namespace HotChocolate.Fusion.PreMergeValidation.Rules; /// entity matching the provided criteria is not found, following the standard GraphQL practices for /// representing missing data. /// -/// +/// /// Specification /// -internal sealed class LookupShouldHaveNullableReturnTypeRule : IEventHandler +internal sealed class LookupReturnsNonNullableTypeRule : IEventHandler { public void Handle(OutputFieldEvent @event, CompositionContext context) { var (field, type, schema) = @event; - if (ValidationHelper.IsLookup(field) && field.Type is NonNullTypeDefinition) + if (field.HasLookupDirective() && field.Type is NonNullTypeDefinition) { - context.Log.Write(LookupShouldHaveNullableReturnType(field, type, schema)); + context.Log.Write(LookupReturnsNonNullableType(field, type, schema)); } } } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideFromSelfRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideFromSelfRule.cs index 61acbb466e0..8b59156f530 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideFromSelfRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideFromSelfRule.cs @@ -23,8 +23,7 @@ public void Handle(OutputFieldEvent @event, CompositionContext context) var overrideDirective = field.Directives[Override].FirstOrDefault(); - if ( - overrideDirective?.Arguments[From] is StringValueNode from + if (overrideDirective?.Arguments[From] is StringValueNode from && from.Value == schema.Name) { context.Log.Write(OverrideFromSelf(overrideDirective, field, type, schema)); diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideOnInterfaceRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideOnInterfaceRule.cs index 482ccaf7cbf..d0721ac1e5f 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideOnInterfaceRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/OverrideOnInterfaceRule.cs @@ -1,4 +1,5 @@ using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using HotChocolate.Skimmed; using static HotChocolate.Fusion.Logging.LogEntryHelper; @@ -21,7 +22,7 @@ public void Handle(OutputFieldEvent @event, CompositionContext context) { var (field, type, schema) = @event; - if (type is InterfaceTypeDefinition && ValidationHelper.HasOverrideDirective(field)) + if (type is InterfaceTypeDefinition && field.HasOverrideDirective()) { context.Log.Write(OverrideOnInterface(field, type, schema)); } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesFieldsMissingExternalRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesFieldsMissingExternalRule.cs index 586de9d14a1..7fcc58a5743 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesFieldsMissingExternalRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesFieldsMissingExternalRule.cs @@ -1,4 +1,5 @@ using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using static HotChocolate.Fusion.Logging.LogEntryHelper; namespace HotChocolate.Fusion.PreMergeValidation.Rules; @@ -25,7 +26,7 @@ public void Handle(ProvidesFieldEvent @event, CompositionContext context) { var (providedField, providedType, providesDirective, field, type, schema) = @event; - if (!ValidationHelper.IsExternal(providedField)) + if (!providedField.HasExternalDirective()) { context.Log.Write( ProvidesFieldsMissingExternal( diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesOnNonCompositeFieldRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesOnNonCompositeFieldRule.cs index 79531b789d2..595d3defc28 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesOnNonCompositeFieldRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/ProvidesOnNonCompositeFieldRule.cs @@ -21,7 +21,7 @@ public void Handle(OutputFieldEvent @event, CompositionContext context) { var (field, type, schema) = @event; - if (ValidationHelper.HasProvidesDirective(field)) + if (field.HasProvidesDirective()) { var fieldType = field.Type.NamedType(); diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/QueryRootTypeInaccessibleRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/QueryRootTypeInaccessibleRule.cs index 8b27168556f..95fd4d1c643 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/QueryRootTypeInaccessibleRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/QueryRootTypeInaccessibleRule.cs @@ -1,4 +1,5 @@ using HotChocolate.Fusion.Events; +using HotChocolate.Fusion.Extensions; using static HotChocolate.Fusion.Logging.LogEntryHelper; namespace HotChocolate.Fusion.PreMergeValidation.Rules; @@ -19,7 +20,7 @@ public void Handle(SchemaEvent @event, CompositionContext context) var schema = @event.Schema; var rootQuery = schema.QueryType; - if (rootQuery is not null && !ValidationHelper.IsAccessible(rootQuery)) + if (rootQuery?.HasInaccessibleDirective() == true) { context.Log.Write(QueryRootTypeInaccessible(rootQuery, schema)); } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RequireInvalidFieldsTypeRule.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RequireInvalidFieldsTypeRule.cs index a4ddeec347e..d13133915b7 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RequireInvalidFieldsTypeRule.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/PreMergeValidation/Rules/RequireInvalidFieldsTypeRule.cs @@ -1,8 +1,5 @@ using HotChocolate.Fusion.Events; -using HotChocolate.Language; using static HotChocolate.Fusion.Logging.LogEntryHelper; -using static HotChocolate.Fusion.WellKnownArgumentNames; -using static HotChocolate.Fusion.WellKnownDirectiveNames; namespace HotChocolate.Fusion.PreMergeValidation.Rules; @@ -15,26 +12,18 @@ namespace HotChocolate.Fusion.PreMergeValidation.Rules; /// /// Specification /// -internal sealed class RequireInvalidFieldsTypeRule : IEventHandler +internal sealed class RequireInvalidFieldsTypeRule : IEventHandler { - public void Handle(FieldArgumentEvent @event, CompositionContext context) + public void Handle(RequireFieldsInvalidTypeEvent @event, CompositionContext context) { - var (argument, field, type, schema) = @event; + var (requireDirective, argument, field, type, schema) = @event; - var requireDirective = argument.Directives.FirstOrDefault(Require); - - if ( - requireDirective is not null - && requireDirective.Arguments.TryGetValue(Fields, out var fields) - && fields is not StringValueNode) - { - context.Log.Write( - RequireInvalidFieldsType( - requireDirective, - argument.Name, - field.Name, - type.Name, - schema)); - } + context.Log.Write( + RequireInvalidFieldsType( + requireDirective, + argument.Name, + field.Name, + type.Name, + schema)); } } diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.Designer.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.Designer.cs index cd431cb260d..75ac0ee8cee 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.Designer.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.Designer.cs @@ -132,7 +132,7 @@ internal static string LogEntryHelper_ExternalArgumentDefaultMismatch { } /// - /// Looks up a localized string similar to External field '{0}' in schema '{1}' is not defined (non-external) in any other schema.. + /// Looks up a localized string similar to The external field '{0}' in schema '{1}' is not defined (non-external) in any other schema.. /// internal static string LogEntryHelper_ExternalMissingOnBase { get { @@ -141,7 +141,7 @@ internal static string LogEntryHelper_ExternalMissingOnBase { } /// - /// Looks up a localized string similar to Interface field '{0}' in schema '{1}' must not be marked as external.. + /// Looks up a localized string similar to The interface field '{0}' in schema '{1}' must not be marked as external.. /// internal static string LogEntryHelper_ExternalOnInterface { get { @@ -150,7 +150,7 @@ internal static string LogEntryHelper_ExternalOnInterface { } /// - /// Looks up a localized string similar to External field '{0}' in schema '{1}' is not referenced by a @provides directive in the schema.. + /// Looks up a localized string similar to The external field '{0}' in schema '{1}' is not referenced by a @provides directive in the schema.. /// internal static string LogEntryHelper_ExternalUnused { get { @@ -251,23 +251,23 @@ internal static string LogEntryHelper_KeyInvalidSyntax { /// /// Looks up a localized string similar to The lookup field '{0}' in schema '{1}' must not return a list.. /// - internal static string LogEntryHelper_LookupMustNotReturnList { + internal static string LogEntryHelper_LookupReturnsList { get { - return ResourceManager.GetString("LogEntryHelper_LookupMustNotReturnList", resourceCulture); + return ResourceManager.GetString("LogEntryHelper_LookupReturnsList", resourceCulture); } } /// /// Looks up a localized string similar to The lookup field '{0}' in schema '{1}' should return a nullable type.. /// - internal static string LogEntryHelper_LookupShouldHaveNullableReturnType { + internal static string LogEntryHelper_LookupReturnsNonNullableType { get { - return ResourceManager.GetString("LogEntryHelper_LookupShouldHaveNullableReturnType", resourceCulture); + return ResourceManager.GetString("LogEntryHelper_LookupReturnsNonNullableType", resourceCulture); } } /// - /// Looks up a localized string similar to Field '{0}' has a different type shape in schema '{1}' than it does in schema '{2}'.. + /// Looks up a localized string similar to The output field '{0}' has a different type shape in schema '{1}' than it does in schema '{2}'.. /// internal static string LogEntryHelper_OutputFieldTypesNotMergeable { get { diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.resx b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.resx index 2667addcb2d..7daa39801a7 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.resx +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Properties/CompositionResources.resx @@ -43,13 +43,13 @@ The argument with schema coordinate '{0}' has inconsistent default values. - External field '{0}' in schema '{1}' is not defined (non-external) in any other schema. + The external field '{0}' in schema '{1}' is not defined (non-external) in any other schema. - Interface field '{0}' in schema '{1}' must not be marked as external. + The interface field '{0}' in schema '{1}' must not be marked as external. - External field '{0}' in schema '{1}' is not referenced by a @provides directive in the schema. + The external field '{0}' in schema '{1}' is not referenced by a @provides directive in the schema. The argument '{0}' has a different type shape in schema '{1}' than it does in schema '{2}'. @@ -81,14 +81,14 @@ A @key directive on type '{0}' in schema '{1}' contains invalid syntax in the 'fields' argument. - + The lookup field '{0}' in schema '{1}' must not return a list. - + The lookup field '{0}' in schema '{1}' should return a nullable type. - Field '{0}' has a different type shape in schema '{1}' than it does in schema '{2}'. + The output field '{0}' has a different type shape in schema '{1}' than it does in schema '{2}'. The @override directive on field '{0}' in schema '{1}' must not reference the same schema. diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/SourceSchemaMerger.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/SourceSchemaMerger.cs index 5f3c5b4b04f..94be53f413e 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/SourceSchemaMerger.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/SourceSchemaMerger.cs @@ -62,8 +62,8 @@ private CompositionResult MergeSchemaDefinitions(CompositionCo new KeyInvalidFieldsRule(), new KeyInvalidFieldsTypeRule(), new KeyInvalidSyntaxRule(), - new LookupMustNotReturnListRule(), - new LookupShouldHaveNullableReturnTypeRule(), + new LookupReturnsListRule(), + new LookupReturnsNonNullableTypeRule(), new OutputFieldTypesMergeableRule(), new OverrideFromSelfRule(), new OverrideOnInterfaceRule(), diff --git a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/ValidationHelper.cs b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/ValidationHelper.cs index 71615e771bb..a008c971903 100644 --- a/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/ValidationHelper.cs +++ b/src/HotChocolate/Fusion-vnext/src/Fusion.Composition/ValidationHelper.cs @@ -5,41 +5,6 @@ namespace HotChocolate.Fusion; internal sealed class ValidationHelper { - public static bool HasOverrideDirective(IDirectivesProvider type) - { - return type.Directives.ContainsName(WellKnownDirectiveNames.Override); - } - - public static bool HasProvidesDirective(IDirectivesProvider type) - { - return type.Directives.ContainsName(WellKnownDirectiveNames.Provides); - } - - public static bool IsAccessible(IDirectivesProvider type) - { - return !type.Directives.ContainsName(WellKnownDirectiveNames.Inaccessible); - } - - public static bool IsInaccessible(IDirectivesProvider type) - { - return type.Directives.ContainsName(WellKnownDirectiveNames.Inaccessible); - } - - public static bool IsExternal(IDirectivesProvider type) - { - return type.Directives.ContainsName(WellKnownDirectiveNames.External); - } - - public static bool IsInternal(IDirectivesProvider type) - { - return type.Directives.ContainsName(WellKnownDirectiveNames.Internal); - } - - public static bool IsLookup(IDirectivesProvider type) - { - return type.Directives.ContainsName(WellKnownDirectiveNames.Lookup); - } - /// /// Returns true if the specified has a @provides /// directive that references the specified . diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalMissingOnBaseRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalMissingOnBaseRuleTests.cs index c79b015116d..0fafaefa6fe 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalMissingOnBaseRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalMissingOnBaseRuleTests.cs @@ -93,8 +93,8 @@ type Product { """ ], [ - "External field 'Product.name' in schema 'B' is not defined (non-external) " + - "in any other schema." + "The external field 'Product.name' in schema 'B' is not defined " + + "(non-external) in any other schema." ] }, // The "name" field is marked as @external in both source schemas. @@ -116,11 +116,11 @@ type Product { """ ], [ - "External field 'Product.name' in schema 'A' is not defined (non-external) " + - "in any other schema.", + "The external field 'Product.name' in schema 'A' is not defined " + + "(non-external) in any other schema.", - "External field 'Product.name' in schema 'B' is not defined (non-external) " + - "in any other schema." + "The external field 'Product.name' in schema 'B' is not defined " + + "(non-external) in any other schema." ] } }; diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalOnInterfaceRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalOnInterfaceRuleTests.cs index 446dce059e3..4a362e588f1 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalOnInterfaceRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalOnInterfaceRuleTests.cs @@ -86,7 +86,7 @@ interface Node { """ ], [ - "Interface field 'Node.id' in schema 'A' must not be marked as external." + "The interface field 'Node.id' in schema 'A' must not be marked as external." ] } }; diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalUnusedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalUnusedRuleTests.cs index d091f3c5a69..51b2f486666 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalUnusedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/ExternalUnusedRuleTests.cs @@ -97,7 +97,7 @@ type Product { """ ], [ - "External field 'Product.title' in schema 'A' is not referenced by a " + + "The external field 'Product.title' in schema 'A' is not referenced by a " + "@provides directive in the schema." ] }, @@ -117,7 +117,7 @@ type Query { """ ], [ - "External field 'Product.title' in schema 'A' is not referenced by a " + + "The external field 'Product.title' in schema 'A' is not referenced by a " + "@provides directive in the schema." ] } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/InputFieldTypesMergeableRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/InputFieldTypesMergeableRuleTests.cs index 0321689f437..a0f1401b538 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/InputFieldTypesMergeableRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/InputFieldTypesMergeableRuleTests.cs @@ -100,7 +100,7 @@ input AuthorInput { } """ ] - }, + } }; } @@ -124,8 +124,8 @@ input AuthorInput { """ ], [ - "Input field 'AuthorInput.birthdate' has a different type shape in schema " + - "'A' than it does in schema 'B'." + "The input field 'AuthorInput.birthdate' has a different type shape in " + + "schema 'A' than it does in schema 'B'." ] }, // List versus non-list. @@ -143,8 +143,8 @@ input AuthorInput { """ ], [ - "Input field 'AuthorInput.birthdate' has a different type shape in schema " + - "'A' than it does in schema 'B'." + "The input field 'AuthorInput.birthdate' has a different type shape in " + + "schema 'A' than it does in schema 'B'." ] } }; diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidFieldsRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidFieldsRuleTests.cs index 76841841606..1994265b1e3 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidFieldsRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidFieldsRuleTests.cs @@ -115,10 +115,6 @@ type Product @key(fields: "category { id name } info { id }") { type ProductCategory { description: String } - - type ProductInfo { - updatedAt: DateTime! - } """ ], [ diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidSyntaxRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidSyntaxRuleTests.cs index f77f920b11e..42158c19ecc 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidSyntaxRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/KeyInvalidSyntaxRuleTests.cs @@ -68,7 +68,7 @@ public static TheoryData InvalidExamplesData() return new TheoryData { // Here, the selection set "featuredItem { id" is missing the closing brace "}". It is - // thus invalid syntax, causing a "KEY_INVALID_SYNTAX" error. + // thus invalid syntax, causing a KEY_INVALID_SYNTAX error. { [ """ diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupMustNotReturnListRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupReturnsListRuleTests.cs similarity index 91% rename from src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupMustNotReturnListRuleTests.cs rename to src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupReturnsListRuleTests.cs index b29d33071b6..fe6fdd5406d 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupMustNotReturnListRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupReturnsListRuleTests.cs @@ -4,10 +4,9 @@ namespace HotChocolate.Composition.PreMergeValidation.Rules; -public sealed class LookupMustNotReturnListRuleTests : CompositionTestBase +public sealed class LookupReturnsListRuleTests : CompositionTestBase { - private readonly PreMergeValidator _preMergeValidator = - new([new LookupMustNotReturnListRule()]); + private readonly PreMergeValidator _preMergeValidator = new([new LookupReturnsListRule()]); [Theory] [MemberData(nameof(ValidExamplesData))] @@ -37,7 +36,7 @@ public void Examples_Invalid(string[] sdl, string[] errorMessages) // assert Assert.True(result.IsFailure); Assert.Equal(errorMessages, context.Log.Select(e => e.Message).ToArray()); - Assert.True(context.Log.All(e => e.Code == "LOOKUP_MUST_NOT_RETURN_LIST")); + Assert.True(context.Log.All(e => e.Code == "LOOKUP_RETURNS_LIST")); Assert.True(context.Log.All(e => e.Severity == LogSeverity.Error)); } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupReturnsNonNullableTypeRuleTests.cs similarity index 91% rename from src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRuleTests.cs rename to src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupReturnsNonNullableTypeRuleTests.cs index 024bd7ff575..ec32ed0a28e 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupShouldHaveNullableReturnTypeRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/LookupReturnsNonNullableTypeRuleTests.cs @@ -4,10 +4,10 @@ namespace HotChocolate.Composition.PreMergeValidation.Rules; -public sealed class LookupShouldHaveNullableReturnTypeRuleTests : CompositionTestBase +public sealed class LookupReturnsNonNullableTypeRuleTests : CompositionTestBase { private readonly PreMergeValidator _preMergeValidator = - new([new LookupShouldHaveNullableReturnTypeRule()]); + new([new LookupReturnsNonNullableTypeRule()]); [Theory] [MemberData(nameof(ValidExamplesData))] @@ -37,7 +37,7 @@ public void Examples_Invalid(string[] sdl, string[] errorMessages) // assert Assert.True(result.IsSuccess); Assert.Equal(errorMessages, context.Log.Select(e => e.Message).ToArray()); - Assert.True(context.Log.All(e => e.Code == "LOOKUP_SHOULD_HAVE_NULLABLE_RETURN_TYPE")); + Assert.True(context.Log.All(e => e.Code == "LOOKUP_RETURNS_NON_NULLABLE_TYPE")); Assert.True(context.Log.All(e => e.Severity == LogSeverity.Warning)); } diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/OutputFieldTypesMergeableRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/OutputFieldTypesMergeableRuleTests.cs index 3a94c203c2c..a3491b93201 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/OutputFieldTypesMergeableRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/OutputFieldTypesMergeableRuleTests.cs @@ -117,8 +117,8 @@ type User { """ ], [ - "Field 'User.birthdate' has a different type shape in schema 'A' than it " + - "does in schema 'B'." + "The output field 'User.birthdate' has a different type shape in schema 'A' " + + "than it does in schema 'B'." ] }, { @@ -141,8 +141,8 @@ scalar Tag """ ], [ - "Field 'User.tags' has a different type shape in schema 'A' than it does in " + - "schema 'B'." + "The output field 'User.tags' has a different type shape in schema 'A' than " + + "it does in schema 'B'." ] }, // More than two schemas. @@ -165,11 +165,11 @@ type User { """ ], [ - "Field 'User.birthdate' has a different type shape in schema 'A' than it " + - "does in schema 'B'.", + "The output field 'User.birthdate' has a different type shape in schema 'A' " + + "than it does in schema 'B'.", - "Field 'User.birthdate' has a different type shape in schema 'B' than it " + - "does in schema 'C'." + "The output field 'User.birthdate' has a different type shape in schema 'B' " + + "than it does in schema 'C'." ] } }; diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RequireDirectiveInFieldsArgumentRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RequireDirectiveInFieldsArgumentRuleTests.cs index a6cfb269910..f8a16d689b8 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RequireDirectiveInFieldsArgumentRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RequireDirectiveInFieldsArgumentRuleTests.cs @@ -104,7 +104,7 @@ type User @key(fields: "id name") { type Profile { id: ID! - info: ProfileInfo! + info: ProfileInfo } type ProfileInfo { diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs index 9c056c8e222..3c7a5d6aee2 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootMutationUsedRuleTests.cs @@ -92,7 +92,7 @@ type Mutation { "The root mutation type in schema 'A' must be named 'Mutation'." ] }, - // A type named 'Mutation' is not the root mutation type. + // A type named "Mutation" is not the root mutation type. { [ "scalar Mutation" diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs index 7b3a6bf9ac0..db361cfaecb 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootQueryUsedRuleTests.cs @@ -92,7 +92,7 @@ type Query { "The root query type in schema 'A' must be named 'Query'." ] }, - // A type named 'Query' is not the root query type. + // A type named "Query" is not the root query type. { [ "scalar Query" diff --git a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs index 2ae4f69257d..50385c23858 100644 --- a/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs +++ b/src/HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/PreMergeValidation/Rules/RootSubscriptionUsedRuleTests.cs @@ -92,7 +92,7 @@ type Subscription { "The root subscription type in schema 'A' must be named 'Subscription'." ] }, - // A type named 'Subscription' is not the root subscription type. + // A type named "Subscription" is not the root subscription type. { [ "scalar Subscription"