fix: add missing support for oneOf directive in schema printer #1727
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Add Missing Test and Support for
@oneOfDirective in Schema PrinterSummary
This PR addresses missing test coverage and implementation gaps for the
@oneOfdirective in the schema printer. While PR #1715 implemented the core@oneOfdirective support, it was missing tests to ensure the directive is properly printed when schemas are serialized, and the underlying build cycle was not preserving the directive.This fix ensures full compatibility with the GraphQL.js reference implementation for schema printing and rebuilding.
Missing Test Coverage
testInputTypeWithOneOfDirective()inSchemaPrinterTest.phpto verify@oneOfdirective printing for input types withisOneOf: truetestCorrectlyExtendInputObjectTypeWithOneOfDirective()inBuildSchemaTest.phpto cover@oneOfdirective parsing from input object extensionsprintSchema-test.tsSchema Printer Fix
printInputObject()inSchemaPrinter.phpto check$type->isOneOf()and append@oneOfdirective when trueBuild Schema Fix
makeInputObjectDef()inASTDefinitionBuilder.phpto:@oneOfdirective from input object definition nodes usingValues::getDirectiveValues()@oneOfdirective from extension nodes (previously uncovered code path)isOneOfproperty correctly when buildingInputObjectTypeinstances@throwsannotations for PHPStan complianceRoot Cause
The issue occurred because:
SchemaPrinter::printInputObject()was not checking theisOneOfpropertyASTDefinitionBuilder::makeInputObjectDef()was not parsing the@oneOfdirective from AST nodesInputObjectType→print→build→printwas not preserving the directiveTest Coverage
@oneOfdirective appears in printed schemaSchemaPrinter::doPrint()→BuildSchema::build()→SchemaPrinter::doPrint()cycle@oneOfdirective parsing from both main definitions and extension nodesBreaking Changes
None. This is a bug fix that adds missing functionality without changing existing behavior.
Validation Results
Example Scenarios
Main Definition:
Extension Definition:
Both scenarios now properly preserve the
@oneOfdirective through the complete build cycle.