ChilliCream / ChilliCream/graphql-platform

Hot Chocolate throws error when Flags Enum is in a paged response

Open
#8,355 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Type System
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Version

15.1.3

Link to minimal reproduction

https://github.com/cabillin/hot-chocolate-issues/tree/flag_enum_incorrect_handling

Steps to reproduce
query bob {
  parents(first: 1) {
    nodes {
      childId
      id
      flags {
        isANA
      }
    }
  }
}
What is expected?
{
  "data": {
    "parents": {
      "nodes": [
        {
          "childId": "Child1",
          "id": 1,
          "flags": {
            "isANA": false
          }
        }
      ]
    }
  }
}
What is actually happening?
{
  "errors": [
    {
      "message": "Unexpected Execution Error",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "parents"
      ],
      "extensions": {
        "message": "Property 'Int32 Count' is not defined for type 'HotChocolate.Issues.Classes.FlagEnum' (Parameter 'property')",
        "stackTrace": "   at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildAssignmentExpression(PropertyNode node, Context context)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildSelectionSetExpression(Context context, TypeNode parent)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildTypeSwitchExpression(Context context, TypeContainer parent)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildAssignmentExpression(PropertyNode node, Context context)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildSelectionSetExpression(Context context, TypeNode parent)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildTypeSwitchExpression(Context context, TypeContainer parent)\r\n   at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildExpression[TRoot](ISelection selection)\r\n   at HotChocolate.Execution.Processing.HotChocolateExecutionSelectionExtensions.<>c__2`1.<GetOrCreateExpression>b__2_0(String _, ValueTuple`2 ctx)\r\n   at HotChocolate.Execution.Processing.Operation.GetOrAddState[TState,TContext](String key, Func`3 createState, TContext context)\r\n   at HotChocolate.Execution.Processing.HotChocolateExecutionSelectionExtensions.GetOrCreateExpression[TValue](ISelection selection)\r\n   at HotChocolate.Execution.Processing.HotChocolateExecutionSelectionExtensions.AsSelector[TValue](ISelection selection)\r\n   at HotChocolate.Data.QueryContextParameterExpressionBuilder.CreateQueryContext[T](IResolverContext context)\r\n   at lambda_method3(Closure, IResolverContext)\r\n   at HotChocolate.Types.Helpers.FieldMiddlewareCompiler.<>c__DisplayClass9_0.<<CreateResolverMiddleware>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Types.UnwrapFieldMiddlewareHelper.<>c__DisplayClass0_1.<<CreateDataMiddleware>b__1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Types.Pagination.PagingMiddleware.InvokeAsync(IMiddlewareContext context)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
      }
    }
  ],
  "data": {
    "parents": null
  }
}

Additional Context

query bob {
  parents(first: 1) {
    nodes {
      childId
      id
    }
  }
}

works

query bob {
  parents(first: 2, where: { flags: { eq: { isANA: true } } }) {
    nodes {
      childId
      id
    }
  }
}

returns successfully, but I'm not sure if it is working correctly. I would have expected to get back id 3 and id 5, but I only get back id 3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the linked minimal reproduction and the paged GraphQL query. Start with the stack-traced SelectionExpressionBuilder.BuildAssignmentExpression path and inspect how the flags enum is projected before PagingMiddleware runs. Done means the paged response returns the expected isANA value without an execution error, and the reported flags filter returns the expected records.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, graphql
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.