Skip to content

Skip deferred fragments in collectFields only when same label is used - #4841

Open
robrichard wants to merge 1 commit into
17.x.xfrom
robrichard/skip-defer-by-label
Open

Skip deferred fragments in collectFields only when same label is used#4841
robrichard wants to merge 1 commit into
17.x.xfrom
robrichard/skip-defer-by-label

Conversation

@robrichard

Copy link
Copy Markdown
Contributor

For this case:

query HeroNameQuery {
  hero {
    ...TopFragment @defer(label: "DeferTop1")
    ...TopFragment @defer(label: "DeferTop2")
  }
}
fragment TopFragment on Hero {
  name
}

Currently the second spread of TopFragment gets skipped by the visited fragment check and the result is:

[
  {
    data: { hero: {} },
    pending: [
      { id: '0', path: ['hero'], label: 'DeferTop1' }
    ],
    hasNext: true,
  },
  {
    hasNext: false,
    incremental: [{ id: '0', data: { name: 'Luke' } }],
    completed: [{ id: '0' }],
  },
]

I think this will be an issue for clients. Since no pending is sent for the fragment with the DeferTop2 label, clients will assume this fragment has been inlined (not deferred), but the necessary fields have not been included in the initial result.

This PR updates the visited fragment check to only skip deferred fragments that have already been collected with the same label, while still preventing infinite loops from circular fragment references

New response:

[
  {
    data: { hero: {} },
    pending: [
      { id: '0', path: ['hero'], label: 'DeferTop1' },
      { id: '1', path: ['hero'], label: 'DeferTop2' },
    ],
    hasNext: true,
  },
  {
    hasNext: false,
    incremental: [{ id: '0', data: { name: 'Luke' } }],
    completed: [{ id: '0' }, { id: '1' }],
  },
]

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
graphql-js Ignored Ignored Preview Jul 22, 2026 3:51pm

Request Review

@robrichard
robrichard marked this pull request as draft July 22, 2026 14:39
@robrichard
robrichard marked this pull request as ready for review July 22, 2026 14:39
@robrichard
robrichard requested review from benjie and yaacovCR July 22, 2026 14:39
@robrichard
robrichard force-pushed the robrichard/skip-defer-by-label branch 2 times, most recently from e5c18f6 to d72dfca Compare July 22, 2026 14:46
@robrichard
robrichard force-pushed the robrichard/skip-defer-by-label branch from d72dfca to 71a94a7 Compare July 22, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant