graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Getting "Cannot Resolve PayLoad Type" error, when using MutationResult of a collection

Open sergeprozorov opened this issue 1 year ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Product

Hot Chocolate

Describe the bug

When a mutation method returns a collection, e.g. an array, I get a Cannot Resolve PayLoad Type error on schema querying.

A workaround would be creating a custom payload type, instead of using MutationResult, but it definitely requires more coding.

Steps to reproduce

Here is the code example I use to reproduce the issue. You can also find it here, https://github.com/sergeprozorov/HC-PayloadIssue

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddGraphQLServer()
    .AddQueryType<Query>()
    .AddMutationType()
    .AddMutationConventions()
    .AddTypeExtension<ProblematicMutation>();

var app = builder.Build();

app.MapGraphQL();

app.Run();

[MutationType]
public class ProblematicMutation
{
    public async Task<MutationResult<Author[], CustomError>> DoSomeWorkProperlyAsync(
        string[] authorNames,
        CancellationToken token) =>
        await Task.FromResult(
            authorNames.Select(n => new Author
            {
                Name = n
            }).ToArray());
}

public class CustomError
{
    public string Message { get; }
}

public class Book
{
    public string Title { get; set; }

    public Author Author { get; set; }
}

public class Author
{
    public string Name { get; set; }
}

public class Query
{
    public Book GetBook() =>
        new Book
        {
            Title = "C# in depth.",
            Author = new Author
            {
                Name = "Jon Skeet"
            }
        };
}

Relevant log output

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      HotChocolate.SchemaException: For more details look at the `Errors` property.

      1. Cannot Resolve PayLoad Type

         at HotChocolate.Types.MutationConventionTypeInterceptor.TryApplyPayloadConvention(ObjectFieldDefinition mutation, String payloadFieldName, Options options)
         at HotChocolate.Types.MutationConventionTypeInterceptor.OnBeforeCompleteMutation(ITypeCompletionContext completionContext, ObjectTypeDefinition definition)
         at HotChocolate.Configuration.AggregateTypeInterceptor.OnBeforeCompleteMutation(ITypeCompletionContext completionContext, ObjectTypeDefinition definition)
         at HotChocolate.Configuration.TypeInitializer.MergeTypeExtensions()
         at HotChocolate.Configuration.TypeInitializer.Initialize()
         at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
         at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
         at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
         at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(ConfigurationContext context, RequestExecutorSetup setup, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(String schemaName, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)
         at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
         at HotChocolate.AspNetCore.HttpPostMiddlewareBase.HandleRequestAsync(HttpContext context)
         at HotChocolate.AspNetCore.HttpPostMiddlewareBase.InvokeAsync(HttpContext context)
         at Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.<>c__DisplayClass19_0.<<UseCancellation>b__1>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Additional Context?

No response

Version

13.8.1

sergeprozorov avatar Jan 03 '24 11:01 sergeprozorov

We have this issue also!

We want to return a list of Guid's

DatStorm avatar May 03 '24 08:05 DatStorm

Also this issue is related but with query #7085

DatStorm avatar May 08 '24 09:05 DatStorm

image

This works fine with 14. I am closing this as fixed with 14.

michaelstaib avatar May 08 '24 20:05 michaelstaib