GeezerVison is showing github.com — Add information about deferrals to DataFetchingFieldSelectionSet · Issue #4355 · graphql-java/graphql-java
Add information about deferrals to DataFetchingFieldSelectionSet #4355
Description
From what I can see there is currently no good way to see whether or not a field is part of a fragment with the @defer directive. As a result, I’m not able to postpone fetching deferred fields in my datafetchers.
Am I missing something, or is this something we can and should improve?
Activity
bbakerman commented on Mar 30, 2026
I’m not able to postpone fetching deferred fields in my datafetchers.
Am I missing something,
The DataFetcher is not responsible for "deferring" fields - that is on the engine itself.
So given
query PersonQuery($personId: ID!) {
person(id: $personId) {
# Basic fields (fast)
id
firstName
lastName
# Friend fields (slower)
... @defer {
friends {
id
}
}
}
}
The engine will look for @defer directives on fragments and then find all the fields that are inside them AND then skip executing the fields until it has done all the non deferred fields.
So in the example above the friends field (and child fields of course) are initially skipped by the engine and then later run aka deferred until later
Defer is still a experimental (off by default) feature. You need to turn it on per request
return graphQL.execute(
ExecutionInput.newExecutionInput()
.graphQLContext([(ExperimentalApi.ENABLE_INCREMENTAL_SUPPORT): incrementalSupport])
.query(query)
.variables(variables)
.dataLoaderRegistry(dataLoaderRegistry)
.build())
alf commented on Mar 31, 2026
So in your example the selectionset passed by the engine to the query.person datafetcher won’t contain friends? If so, that’s perfect and exactly what I need.
alf commented on Apr 6, 2026
bbakerman commented on Apr 7, 2026
ok good catch - it sounds like graphql.schema.DataFetchingFieldSelectionSet is not respecting deferred fields. The engine is - it will only invoke data fetchers of fields that are not deferred on the initial pass but I can see how graphql.schema.DataFetchingFieldSelectionSet could lead a DF to get data for child fields that it will not need immediately (and hence not defer them).
I think this needs to be reflected some how in the graphql.schema.DataFetchingFieldSelectionSet model. Not sure off hand how to model it (have a dfSelectionSet.getDeferredFields() ??? say) or make them disappear all together.
Hmmm we need to ponder on this a bit on how best to model it.
github-actions commented on Jun 7, 2026
Hello, this issue has been inactive for 60 days, so we're marking it as stale. If you would like to continue this discussion, please comment within the next 30 days or we'll close the issue.
Metadata
Metadata
Development
No branches or pull requestsIssue actions