0

This is necessary as I need to show which array element is causing the issue.

This was working fine before in HotChocolate 10, but after upgrading to 12 this is breaking. I am running the following line and it is breaking with the error below it:

IErrorBuilder errorBuilder = new ErrorBuilder()
    .SetPath(new List<string>() { "Users[0]"})
"extensions": {
    "message": "`Users[0]` is not a valid GraphQL type name. (Parameter 'value')",
    "stackTrace": "   at HotChocolate.NameString..ctor(String value)
      at HotChocolate.NameString.ConvertFromString(String s)
      at HotChocolate.Path.FromList(IReadOnlyList`1 path)
      at HotChocolate.ErrorBuilder.SetPath(IReadOnlyList`1 path)
      at AppAPI.Common.AppServicesExceptionHandler.ConstructQueryError(String type, String path, String idCode, String description, Dictionary`2 parameters) in \\Project.AppAPI HOT CHOCOLATE 12\\AppAPI WebAPI\\Common\\Exceptions\\AppServicesExceptionHandler.cs:line 268
      at AppAPI.Common.AppServicesExceptionHandler.ProcessException(Exception e, IConfiguration configuration) in \\Project.AppAPI HOT CHOCOLATE 12\\AppAPI WebAPI\\Common\\Exceptions\\AppServicesExceptionHandler.cs:line 97
      at AppAPI.Queries.TestByPeriodQuery.GetTestByPeriod(Int32 accountId, DateTime startUtcDate, DateTime endUtcDate, String aggregatePeriodIdCode, Int32[] Users, Int32[] monitorGroupIds, String[] groupByIdCodes, IMediator mediator, IMapper mapper, IHttpContextAccessor httpContextAccessor, IConfiguration configuration) in \\Project.AppAPI HOT CHOCOLATE 12\\AppAPI WebAPI\\Queries\\TestByPeriodQuery.cs:line 43
      at HotChocolate.Resolvers.Expressions.ExpressionHelper.AwaitTaskHelper[T](Task`1 task)
      at HotChocolate.Types.Helpers.FieldMiddlewareCompiler.<>c__DisplayClass9_0.<<CreateResolverMiddleware>b__0>d.MoveNext()
      --- End of stack trace from previous location where exception was thrown ---
      at HotChocolate.AspNetCore.Authorization.AuthorizeMiddleware.InvokeAsync(IDirectiveContext context)
      at HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)
      at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)
      at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
}
Joundill
  • 6,828
  • 12
  • 36
  • 50
Jacob Shaffer
  • 43
  • 1
  • 8

1 Answers1

3

The error is exactly correct. The ErrorBuilder wants either a Path object or a List<object> which consists of the elements of the path.

ErrorBuilder.New()
    .SetMessage("foo")
    .SetPath(new List<object> { "Users", 0 })
    .Build()

OR

You can use the path object:

ErrorBuilder.New()
    .SetMessage("foo")
    .SetPath(Path.New("Users").Append(0))
    .Build()