Skip to content

QueryContext projection drops nested selected fields when @include(if: $variable) evaluates true #9753

@faethto

Description

@faethto

Product

Hot Chocolate

Version

16.0.6

Link to minimal reproduction

https://github.com/faethto/hotchocolate-include-querycontext-repro

Steps to reproduce

Compare these two integration tests:

  • StaticIncludeTrue_ShouldReturnProjectedRecordFields
  • VariableIncludeTrue_ShouldReturnSameProjectedRecordFields

Both tests POST a GraphQL request to /graphql. The only relevant difference is the include directive on parent.child:

child @include(if: true) {
  records {
    id
    sequence
    label
  }
}

versus:

query Repro($includeChild: Boolean!) {
  parent {
    child @include(if: $includeChild) {
      records {
        id
        sequence
        label
      }
    }
  }
}

with variables:

{
  "includeChild": true
}

What is expected?

@include(if: true) and @include(if: $includeChild) with includeChild = true should produce the same selected payload.

The records response should include the explicitly selected scalar fields:

{
  "id": 1,
  "sequence": 7,
  "label": "alpha"
}

The variable-driven include should not alter the QueryContext<SampleRecord> selector for the nested records field when the directive evaluates to true.

What is actually happening?

The static include test passes, but the variable-driven include test fails.

The nested field is executed, and the correct record identity is present, but projected scalar fields are returned with default CLR values:

Assert.Equal() Failure: Values differ
Expected: 7
Actual:   0

Relevant log output

Additional context

No response

Metadata

Metadata

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions