Skip to content

Commit

Permalink
Merge branch 'main' into gai/update-gateway-template-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Dec 23, 2024
2 parents d041bab + 88580a1 commit 89801da
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ private void TryApplyInputConvention(

var argumentType = _completionContext.GetType<IInputType>(argument.Type!);

var formatter =
argument.Formatters.Count switch
var formatters = argument.GetFormatters();
var formatter = formatters.Count switch
{
0 => null,
1 => argument.Formatters[0],
_ => new AggregateInputValueFormatter(argument.Formatters),
1 => formatters[0],
_ => new AggregateInputValueFormatter(formatters),
};

var defaultValue = argument.DefaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace HotChocolate.Fusion.Logging;

public sealed class CompositionLog : ICompositionLog, IEnumerable<LogEntry>
public sealed class CompositionLog : ICompositionLog
{
public bool HasErrors { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace HotChocolate.Fusion.Logging.Contracts;
/// <summary>
/// Defines an interface for logging composition information, warnings, and errors.
/// </summary>
public interface ICompositionLog
public interface ICompositionLog : IEnumerable<LogEntry>
{
/// <summary>
/// Gets a value indicating whether the log contains errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,53 @@ internal static class LogEntryHelper
public static LogEntry DisallowedInaccessibleBuiltInScalar(
ScalarTypeDefinition scalar,
SchemaDefinition schema)
=> new(
string.Format(LogEntryHelper_DisallowedInaccessibleBuiltInScalar, scalar.Name),
{
return new LogEntry(
string.Format(
LogEntryHelper_DisallowedInaccessibleBuiltInScalar,
scalar.Name,
schema.Name),
LogEntryCodes.DisallowedInaccessible,
LogSeverity.Error,
new SchemaCoordinate(scalar.Name),
scalar,
schema);
}

public static LogEntry DisallowedInaccessibleIntrospectionType(
INamedTypeDefinition type,
SchemaDefinition schema)
=> new(
string.Format(LogEntryHelper_DisallowedInaccessibleIntrospectionType, type.Name),
{
return new LogEntry(
string.Format(
LogEntryHelper_DisallowedInaccessibleIntrospectionType,
type.Name,
schema.Name),
LogEntryCodes.DisallowedInaccessible,
LogSeverity.Error,
new SchemaCoordinate(type.Name),
type,
schema);
}

public static LogEntry DisallowedInaccessibleIntrospectionField(
OutputFieldDefinition field,
string typeName,
SchemaDefinition schema)
=> new(
{
var coordinate = new SchemaCoordinate(typeName, field.Name);

return new LogEntry(
string.Format(
LogEntryHelper_DisallowedInaccessibleIntrospectionField,
field.Name,
typeName),
coordinate,
schema.Name),
LogEntryCodes.DisallowedInaccessible,
LogSeverity.Error,
new SchemaCoordinate(typeName, field.Name),
coordinate,
field,
schema);
}

public static LogEntry DisallowedInaccessibleIntrospectionArgument(
InputFieldDefinition argument,
Expand All @@ -53,8 +67,8 @@ public static LogEntry DisallowedInaccessibleIntrospectionArgument(
return new LogEntry(
string.Format(
LogEntryHelper_DisallowedInaccessibleIntrospectionArgument,
argument.Name,
coordinate),
coordinate,
schema.Name),
LogEntryCodes.DisallowedInaccessible,
LogSeverity.Error,
coordinate,
Expand All @@ -66,15 +80,23 @@ public static LogEntry DisallowedInaccessibleDirectiveArgument(
InputFieldDefinition argument,
string directiveName,
SchemaDefinition schema)
=> new(
{
var coordinate = new SchemaCoordinate(
directiveName,
argumentName: argument.Name,
ofDirective: true);

return new LogEntry(
string.Format(
LogEntryHelper_DisallowedInaccessibleDirectiveArgument,
argument.Name,
directiveName),
coordinate,
schema.Name),
LogEntryCodes.DisallowedInaccessible,
LogSeverity.Error,
new SchemaCoordinate(directiveName, argumentName: argument.Name, ofDirective: true),
schema: schema);
coordinate,
argument,
schema);
}

public static LogEntry ExternalArgumentDefaultMismatch(
string argumentName,
Expand All @@ -90,23 +112,40 @@ public static LogEntry ExternalArgumentDefaultMismatch(
coordinate);
}

public static LogEntry ExternalMissingOnBase(string fieldName, string typeName)
=> new(
string.Format(
LogEntryHelper_ExternalMissingOnBase,
fieldName,
typeName),
public static LogEntry ExternalMissingOnBase(
OutputFieldDefinition externalField,
INamedTypeDefinition type,
SchemaDefinition schema)
{
var coordinate = new SchemaCoordinate(type.Name, externalField.Name);

return new LogEntry(
string.Format(LogEntryHelper_ExternalMissingOnBase, coordinate, schema.Name),
LogEntryCodes.ExternalMissingOnBase,
LogSeverity.Error,
new SchemaCoordinate(typeName, fieldName));
coordinate,
externalField,
schema);
}

public static LogEntry OutputFieldTypesNotMergeable(
OutputFieldDefinition field,
string typeName,
SchemaDefinition schemaA,
SchemaDefinition schemaB)
{
var coordinate = new SchemaCoordinate(typeName, field.Name);

public static LogEntry OutputFieldTypesNotMergeable(string fieldName, string typeName)
=> new(
return new LogEntry(
string.Format(
LogEntryHelper_OutputFieldTypesNotMergeable,
fieldName,
typeName),
coordinate,
schemaA.Name,
schemaB.Name),
LogEntryCodes.OutputFieldTypesNotMergeable,
LogSeverity.Error,
new SchemaCoordinate(typeName, fieldName));
coordinate,
field,
schemaA);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Immutable;
using HotChocolate.Fusion.Events;
using HotChocolate.Fusion.Extensions;
using static HotChocolate.Fusion.Logging.LogEntryHelper;

namespace HotChocolate.Fusion.PreMergeValidation.Rules;
Expand All @@ -17,14 +17,20 @@ internal sealed class ExternalMissingOnBaseRule : IEventHandler<OutputFieldGroup
{
public void Handle(OutputFieldGroupEvent @event, CompositionContext context)
{
var (fieldName, fieldGroup, typeName) = @event;
var fieldGroup = @event.FieldGroup;

var externalFieldCount = fieldGroup.Count(i => ValidationHelper.IsExternal(i.Field));
var nonExternalFieldCount = fieldGroup.Length - externalFieldCount;
var externalFields = fieldGroup
.Where(i => ValidationHelper.IsExternal(i.Field))
.ToImmutableArray();

if (externalFieldCount != 0 && nonExternalFieldCount == 0)
var nonExternalFieldCount = fieldGroup.Length - externalFields.Length;

foreach (var (field, type, schema) in externalFields)
{
context.Log.Write(ExternalMissingOnBase(fieldName, typeName));
if (nonExternalFieldCount == 0)
{
context.Log.Write(ExternalMissingOnBase(field, type, schema));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ internal sealed class OutputFieldTypesMergeableRule : IEventHandler<OutputFieldG
{
public void Handle(OutputFieldGroupEvent @event, CompositionContext context)
{
var (fieldName, fieldGroup, typeName) = @event;
var (_, fieldGroup, typeName) = @event;

if (!ValidationHelper.FieldsAreMergeable([.. fieldGroup.Select(i => i.Field)]))
for (var i = 0; i < fieldGroup.Length - 1; i++)
{
context.Log.Write(OutputFieldTypesNotMergeable(fieldName, typeName));
var fieldInfoA = fieldGroup[i];
var fieldInfoB = fieldGroup[i + 1];
var typeA = fieldInfoA.Field.Type;
var typeB = fieldInfoB.Field.Type;

if (!ValidationHelper.SameTypeShape(typeA, typeB))
{
context.Log.Write(
OutputFieldTypesNotMergeable(
fieldInfoA.Field,
typeName,
fieldInfoA.Schema,
fieldInfoB.Schema));
}
}
}
}

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

Loading

0 comments on commit 89801da

Please sign in to comment.