Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,22 @@ private void EnsureTypeReferenceRegistered(
return;
}

// Unwrap arrays and collection-interface wrappers (IList<T>, ICollection<T>,
// IEnumerable<T>, IReadOnlyList<T>, ...). The wrapper itself is not a named
// schema type, and CLR collection interfaces carry TypeAttributes.Interface
// which would otherwise misclassify them as a GraphQL interface here.
while (runtimeTypeReference.Type is { IsArrayOrList: true, ElementType: { } element })
{
runtimeTypeReference = runtimeTypeReference.WithType(element);
}

if (_typeRegistry.TryGetTypeRef(runtimeTypeReference, out var existingTypeReference)
&& _typeRegistry.IsRegistered(existingTypeReference))
{
return;
}

if (!_context.TryInferSchemaType(typeReference, out var schemaTypeReferences))
if (!_context.TryInferSchemaType(runtimeTypeReference, out var schemaTypeReferences))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,24 @@ public async Task Union_Result_2_Error_Name_Collision()
exception.Message.MatchSnapshot();
}

[Fact]
public async Task Error_Type_With_IList_Property_Should_Be_Treated_As_List()
{
// arrange & act
var schema =
await new ServiceCollection()
.AddGraphQL()
.AddMutationType<MutationWithIListError>()
.AddMutationConventions()
.ModifyOptions(o => o.StrictValidation = false)
.BuildSchemaAsync();

// assert
var errorType = schema.Types.GetType<ObjectType>("ErrorWithCodes");
Assert.Equal("[Int!]!", errorType.Fields["codes"].Type.ToString());
Assert.False(schema.Types.TryGetType<InterfaceType>("IListOfInt32", out _));
}

[Fact]
public async Task Union_Result_3()
{
Expand Down Expand Up @@ -1746,6 +1764,17 @@ public FooError(string message)
public string Message { get; }
}

public class MutationWithIListError
{
public FieldResult<string, ErrorWithCodes> DoSomething(int[] codes)
=> new ErrorWithCodes(codes);
}

public record ErrorWithCodes(IList<int> Codes)
{
public string Message => $"Codes {string.Join(", ", Codes)} not found.";
}

public class MutationWithPayloadOverride
{
[Error<CustomException>]
Expand Down
Loading