0

I'm trying to put together a more complex stuff than Getting started guide with HotChocolate and I hit a wall, and the documentation does not help.

I have multiple questions:

  • What I'm doing wrong here? I went through all the examples they have and it seems I'm doing the right thing, but the error shows something totally opposite.
  • How can I access to that Errors property? I haven't found any further detail in their BananaCake graphql UI

QueryType class:

public class QueryType : ObjectType
{
    protected override void Configure(IObjectTypeDescriptor descriptor)
    {
        descriptor
            .Name(OperationTypeNames.Query)
            .Description("Represents the Document entity of the system");

        descriptor
            .Field("document")
            .Description("query field description")
            .Type<ListType<DocumentDtoType>>()
            .Resolve(r =>
            {
                return new List<DocumentDto>
                {
                    new DocumentDto { Id = 1, Name = "one", Description = "one d" },
                    new DocumentDto { Id = 2, Name = "two", Description = "two d" },
                };
                // return new List<string>
                // {
                //     "whatever",
                //     "anything"
                // };
            });
    }
}

The type:

public class DocumentDto
{
    public DocumentDto()
    {
    }

    public long Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public Uri? Uri { get; set; }
}

The DocumentDtoType:

public class DocumentDtoType : ObjectType<DocumentDto>
{
    protected override void Configure(IObjectTypeDescriptor<DocumentDto> descriptor)
    {
        descriptor
            .Name("Unique identifier of the entity")
            .Field(f => f.Id)
            .Type<IdType>();

        descriptor
            .Name("Name of the document")
            .Field(f => f.Name)
            .Type<StringType>();

        descriptor
            .Name("Description of the document entity")
            .Field(f => f.Description)
            .Type<StringType>();

        descriptor
            .Field(f => f.Uri).Ignore();
    }
}

Setup:

var builder = WebApplication.CreateBuilder(args);
builder.Services
    .AddGraphQLServer()
    .AddQueryType<QueryType>()
    .AddType<DocumentDtoType>();

var app = builder.Build();

app.MapGet("/", () => "Hello World!");
app.MapGraphQL();

app.Run();

The error:

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5102
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /Users/andrascsanyi/DEV/github.com/EncyclopediaGalactica/EncyclopediaGalactica/Services/Document/Document.Graphql
fail: 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. The specified name is not a valid GraphQL name. (Parameter 'value') (Document.Graphql.Types.DocumentDtoType)
      
         at HotChocolate.Configuration.TypeInitializer.DiscoverTypes()
         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.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      HotChocolate.SchemaException: For more details look at the `Errors` property.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77

1 Answers1

0
  • Method IObjectTypeDescriptor.Name defines a name of GraphQL type that will be exposed to the output schema. And the way you used it is incorrect:
    1. Type name can not include any white space characters, as in your case descriptor.Name("Unique identifier of the entity")
    2. Each method call overwrites the type name so it makes no sense to call it three times
  • Actually SchemaException prints to the console all its exceptions from the Errors property. In your case, the property contains only one exception: "The specified name is not a valid GraphQL name".
Eugene
  • 169
  • 1
  • 6