Fix ExecutableNormalizedField to respect GraphqlFieldVisibility by Samjin · Pull Request #4204 · graphql-java/graphql-java
Problem
ExecutableNormalizedField.forEachFieldDefinition() and getOneFieldDefinition() call type.getField(fieldName) directly, bypassing the schema's configured GraphqlFieldVisibility.
This is inconsistent with other parts of graphql-java (validation, execution) that respect field visibility, and causes issues when:
- A custom GraphqlFieldVisibility provides field definitions that differ from what's in the schema type (e.g., placeholder fields, virtual fields, or dynamically-computed fields)
- Application code accesses DataFetchingEnvironment.getSelectionSet().getFields() in a DataFetcher
- Normalization fails with "No field X found for type Y" because it bypasses the visibility
Reproduction
- Configure a custom
GraphqlFieldVisibilitythat provides virtual/placeholder fields - Execute a query that includes a field only available through the visibility
- Access
DataFetchingEnvironment.getSelectionSet().getFields()in a DataFetcher - Normalization fails because
ExecutableNormalizedField.forEachFieldDefinition()callstype.getField()directly
Solution
Change the field lookup to use the schema's field visibility:
// Before type.getField(fieldName) // After schema.getCodeRegistry().getFieldVisibility().getFieldDefinition(type, fieldName)