-
Notifications
You must be signed in to change notification settings - Fork 155
feat: support the oneOf directive #1308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ysmolski
wants to merge
10
commits into
master
Choose a base branch
from
yury/eng-8174-router-implement-oneof
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
16c1062
feat: support the oneOf directive
ysmolski 9c0d1e7
Merge branch 'master'
ysmolski c00c15a
refactor the code
ysmolski 838953a
fix execution golden tests
ysmolski 70d719d
add a test
ysmolski 6905cf4
Merge branch 'master' into yury/eng-8174-router-implement-oneof
ysmolski 66499a2
Merge branch 'master' into yury/eng-8174-router-implement-oneof
ysmolski 8c9c8fb
rename var
ysmolski 091c52a
Merge branch 'master' into yury/eng-8174-router-implement-oneof
ysmolski 90f8b92
Merge branch 'master' into yury/eng-8174-router-implement-oneof
ysmolski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify behavior when
operationVariableType
returns!ok
.If
operationVariableType
fails on line 503, thecontinue
on line 505 exits the loop, and the function returnsfalse
(no violation) on line 521. This could potentially miss a constraint violation if the variable info cannot be retrieved.While variables should have been validated earlier in the pipeline, making this edge case unlikely, consider either:
continue
is safe here (e.g., "Variable existence already validated; failure here indicates internal inconsistency")The nullable variable detection logic itself (lines 509-517) is correct and properly reports errors with both field and variable positions.
Run the following to verify that undefined variables are caught before oneOf validation:
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 1389
🏁 Script executed:
Length of output: 1039
🏁 Script executed:
Length of output: 2368
🏁 Script executed:
Length of output: 0
Length of output: 2913
🏁 Script executed:
Length of output: 800
🏁 Script executed:
Length of output: 857
🏁 Script executed:
Length of output: 49
🏁 Script executed:
Length of output: 2003
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 535
🏁 Script executed:
Length of output: 283
🏁 Script executed:
Length of output: 83
Length of output: 44
🏁 Script executed:
Length of output: 225
🏁 Script executed:
Length of output: 1926
🏁 Script executed:
Length of output: 3095
🏁 Script executed:
Length of output: 162
🏁 Script executed:
Length of output: 103
🏁 Script executed:
Length of output: 1072
🏁 Script executed:
Length of output: 964
🏁 Script executed:
Length of output: 0
Add validation for undefined variables in oneOf object fields or report an error when
operationVariableType
fails.Lines 501-505 silently skip undefined variables without reporting an error. While variables at the argument level are validated by the
AllVariableUsesDefined
rule, variables nested in object field values—including those in oneOf fields—are not pre-validated. WhenoperationVariableType
returns!ok
on line 503 (indicating an undefined variable), thecontinue
on line 505 exits the loop without reporting a violation, and the function returnsfalse
(no constraint violation detected).This allows undefined variables in oneOf fields to pass validation uncaught. Either:
continue
: report undefined variables as invalid in oneOf fields🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the good test to verify your hypothesis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ysmolski Here's a test case that would verify the hypothesis:
What this test does:
PetInput
(a oneOf input object)cat
field uses a variable$undefinedVolume
that is not declared in the operation's variable definitions$name
is defined, but$undefinedVolume
is usedExpected behavior:
$undefinedVolume
being undefinedYou can add this test to
v2/pkg/astvalidation/operation_validation_test.go
alongside the other oneOf tests. If the test passes (meaning validation catches the error), then the current implementation is safe. If it doesn't report the undefined variable error, then the hypothesis is confirmed and needs fixing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about rule
AllVariableUsesDefined
? Does it provide what we need?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 1926
🏁 Script executed:
Length of output: 107
🏁 Script executed:
Length of output: 3040
@ysmolski Good question! After examining the code, here's what I found:
AllVariableUsesDefined
has limited scope:The rule only registers
RegisterEnterArgumentVisitor
(line 18), which means it validates only variables that appear directly as argument values. It does not walk through object fields or nested object values.However, the
Values()
rule provides what we need:The
Values()
rule has its own comprehensive variable validation that catches undefined variables at any nesting level:In
valueSatisfiesInputObjectTypeDefinition
(lines 398-445), the validation flow is:Field validation catches undefined variables through
variableValueSatisfiesDefinitionType
(lines 164-178):Conclusion:
By the time the oneOf validation runs on line 442, all variables in the object fields have already been validated by the earlier field validation loop. If
operationVariableType
returns!ok
on line 503, it would indicate an internal inconsistency (since the variable should have been caught earlier), making thecontinue
safe.Your test suggestion would still be valuable to confirm this behavior and document it as a test case, but the validation should already be working correctly. The test would likely show that the undefined variable error is reported during the field validation phase, before oneOf validation even runs.
🧬 Code Graph Analysis Results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check if variable passed to input object field is defined is not done at all, not just for oneOf inputObjects. Can you verify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 608
🏁 Script executed:
Length of output: 12431
🏁 Script executed:
Length of output: 677
🏁 Script executed:
Length of output: 357
🏁 Script executed:
Length of output: 546
🏁 Script executed:
Length of output: 1056
🏁 Script executed:
Length of output: 350
🏁 Script executed:
Length of output: 504
🏁 Script executed:
Length of output: 1240
🏁 Script executed:
Length of output: 557
@ysmolski You're absolutely correct! 🎯 This is a broader bug that affects all input object fields with nullable types, not just oneOf inputs.
The Bug
There are two validation paths for variables in the code:
Path 1: NonNull types ✅ (works correctly)
Path 2: Scalar/Enum/InputObject types ❌ (silently fails)
The Root Cause
In
handleVariableHasIncompatibleTypeError
(lines 619-648):When the variable is undefined,
operationVariableType
returns!ok
, and the function exits without reporting any error.Test Case to Verify
The Fix
The fix should be in
handleVariableHasIncompatibleTypeError
(around line 630-632):This would make undefined variables in all contexts report a proper error, not just in oneOf fields or NonNull fields.
Would you like me to create an issue for this broader fix?
🧬 Code Graph Analysis Results
[relevant_snippets]
Filename: v2/pkg/astvalidation/operation_rule_values.go
Filename: v2/pkg/astvalidation/operation_rule_values.go
2) Function: objectValueSatisfiesInputValueDefinition(objectValue ast.Value, inputObjectDefinition, inputValueDefinition int) bool
Filename: v2/pkg/astvalidation/operation_rule_values.go
3) Function: EnterArgument(ref int)
If you need, I can map these to exact code locations or extract exact excerpts.