Skip to content

Bug: Query Planner Doesn't Properly Account for Conditional @requires #3317

@ryan01010111

Description

@ryan01010111

Issue Description

Given:

  1. Subgraphs "A" and "B," where both define an entity T, with a @key of id
  2. "A" defines field T.a
  3. "B" defines fields T.b and T.c, where T.c @requires T.a

When executing a query that conditionally selects T.c, and unconditionally selects other, sibling fields on the entity (T) provided by the same subgraph ("B"), as in:

query q($v: Boolean!) {
    t {
        id
        b
        c @skip(if: $v)
    }
}

and v is the value true

Then:
T.b is never fetched, and is subsequently resolved to null, which can lead to inconsistent data responses.

Cause

The query plan executor receives a FetchNode with requirements (selection set) that include the field required by the excluded (via @skip) field, and the representation collection process (via executeSelectionSet()) attempts to extract that "required" field from the fetched entity data, in which it is (correctly) excluded. This results in null being returned for the fetch's selection set, and a "silent failure" in the case of null-able fields.

Link to Reproduction

https://codesandbox.io/p/devbox/fldc84

Reproduction Steps

  1. If not already running (should be in CodeSandbox), start all services with:
npm run dev
  1. In a free terminal, send example request to reproduce the bug with:
npm run sendRequest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions