Skip to content

Commit

Permalink
Fixed Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Oct 24, 2023
1 parent aeb7158 commit bc5d0fa
Show file tree
Hide file tree
Showing 10 changed files with 617 additions and 411 deletions.
1 change: 1 addition & 0 deletions src/HotChocolate/Core/src/Abstractions/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public static class Schema
public const string InterfaceNotImplemented = "SCHEMA_INTERFACE_NO_IMPL";
public const string DuplicateTypeName = "HC0065";
public const string DuplicateMutationErrorTypeName = "HC0066";
public const string DupplicateFieldNames = "HCXXXX";

/// <summary>
/// The middleware order of a field pipeline is incorrect.
Expand Down
26 changes: 15 additions & 11 deletions src/HotChocolate/Core/src/Types/Internal/FieldInitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using HotChocolate.Types;
using HotChocolate.Types.Descriptors.Definitions;
using HotChocolate.Types.Helpers;
using static HotChocolate.Utilities.ErrorHelper;
using IHasName = HotChocolate.Types.IHasName;

#nullable enable

Expand Down Expand Up @@ -191,16 +193,7 @@ private static FieldCollection<TField> CompleteFieldsInternal<TField>(
{
if (declaringMember is IType type && fields.Length == 0)
{
context.ReportError(SchemaErrorBuilder.New()
.SetMessage(string.Format(
CultureInfo.InvariantCulture,
TypeResources.FieldInitHelper_NoFields,
type.Kind.ToString(),
context.Type.Name))
.SetCode(ErrorCodes.Schema.MissingType)
.SetTypeSystemObject(context.Type)
.AddSyntaxNode((type as IHasSyntaxNode)?.SyntaxNode)
.Build());
context.ReportError(NoFields(context.Type, type));
return FieldCollection<TField>.Empty;
}

Expand All @@ -209,7 +202,18 @@ private static FieldCollection<TField> CompleteFieldsInternal<TField>(
((IFieldCompletion)field).CompleteField(context, declaringMember);
}

return new FieldCollection<TField>(fields);
var collection = FieldCollection<TField>.TryCreate(fields, out var duplicateFieldNames);

if (duplicateFieldNames?.Count > 0)
{
context.ReportError(
DuplicateFieldName(
context.Type,
declaringMember,
duplicateFieldNames));
}

return collection;
}

internal static Type CompleteRuntimeType(IType type, Type? runtimeType)
Expand Down
Loading

0 comments on commit bc5d0fa

Please sign in to comment.