Skip to content

Commit

Permalink
Make amendments following feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielreynolds1 committed Dec 18, 2024
1 parent 4c6d65b commit f18e747
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ public static LogEntry DisallowedInaccessibleDirectiveArgument(
new SchemaCoordinate(directiveName, argumentName: argument.Name, ofDirective: true),
schema: schema);

public static LogEntry ExternalArgumentDefaultMismatch(string fieldName, string typeName)
=> new(
public static LogEntry ExternalArgumentDefaultMismatch(string fieldName, string typeName, string argumentName)
{
var coordinate = new SchemaCoordinate(typeName, fieldName, argumentName);
return new LogEntry(
string.Format(
LogEntryHelper_ExternalArgumentDefaultMismatch,
fieldName,
typeName),
coordinate),
LogEntryCodes.ExternalArgumentDefaultMismatch,
LogSeverity.Error,
new SchemaCoordinate(typeName, fieldName));
coordinate);
}

public static LogEntry ExternalMissingOnBase(string fieldName, string typeName)
=> new(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Immutable;
using HotChocolate.Fusion.Events;
using HotChocolate.Skimmed;
using static HotChocolate.Fusion.Logging.LogEntryHelper;

namespace HotChocolate.Fusion.PreMergeValidation.Rules;

/// <summary>
/// This rule ensures that arguments on fields marked as <c>@external</c> have default values
/// compatible with the corresponding arguments on fields from other source schemas where the field
/// is defined (non-<c>@external</c>).
/// </summary>
/// <seealso href="https://graphql.github.io/composite-schemas-spec/draft/#sec-External-Argument-Default-Mismatch">
/// Specification
/// </seealso>
internal sealed class ExternalArgumentDefaultMismatchRule : IEventHandler<OutputFieldGroupEvent>
{
public void Handle(OutputFieldGroupEvent @event, CompositionContext context)
{
var (fieldName, fieldGroup, typeName) = @event;

IReadOnlyCollection<OutputFieldInfo> externalFields =
[..fieldGroup.Where(i => ValidationHelper.IsExternal(i.Field))];
if (externalFields.Count == 0)
{
return;
}

var argumentNames = fieldGroup
.SelectMany(i => i.Field.Arguments, (_, arg) => arg.Name)
.ToHashSet();

foreach (var argumentName in argumentNames)
{
IReadOnlyList<InputFieldDefinition> arguments = [..fieldGroup.Select(i => i.Field.Arguments[argumentName])];
var defaultValue = arguments[0].DefaultValue;

foreach (var argument in arguments)
{
var currentDefaultValue = argument.DefaultValue;
var match = (currentDefaultValue, defaultValue) switch
{
(null, null) => true,
(not null, null) => false,
(null, not null) => false,
_ => currentDefaultValue.Value!.Equals(defaultValue.Value)
};

if (!match)
{
context.Log.Write(ExternalArgumentDefaultMismatch(fieldName, typeName, argumentName));
}
}
}
}
}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
Expand All @@ -13,10 +14,14 @@
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="ErrorHelper_PreMergeValidationFailed" xml:space="preserve">
<value>Pre-merge validation failed. View the composition log for details.</value>
Expand All @@ -36,13 +41,13 @@
<data name="LogEntryHelper_DisallowedInaccessibleDirectiveArgument" xml:space="preserve">
<value>The argument '{0}' on built-in directive type '{1}' is not accessible.</value>
</data>
<data name="LogEntryHelper_ExternalArgumentDefaultMismatch" xml:space="preserve">
<value>The argument with schema coordinate '{0}' has inconsistent default values.</value>
</data>
<data name="LogEntryHelper_ExternalMissingOnBase" xml:space="preserve">
<value>Field '{0}' on type '{1}' is only declared as external.</value>
</data>
<data name="LogEntryHelper_OutputFieldTypesNotMergeable" xml:space="preserve">
<value>Field '{0}' on type '{1}' is not mergeable.</value>
</data>
<data name="LogEntryHelper_ExternalArgumentDefaultMismatch" xml:space="preserve">
<value>Field '{0}' on type '{1}' must have consistent default values.</value>
</data>
</root>
Loading

0 comments on commit f18e747

Please sign in to comment.