-
Notifications
You must be signed in to change notification settings - Fork 166
feat: add new visitor for inline arguments validation #1577
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
Merged
SkArchon
merged 23 commits into
master
from
milinda/eng-9586-routerengine-force-use-of-variables
Jul 15, 2026
Merged
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c166d91
feat: add new visitor
SkArchon 937a0f2
fix: changes
SkArchon 3e3675d
fix: linting
SkArchon 201ed9a
fix: nil check
SkArchon 7c1f178
fix: tests
SkArchon 9dba9d6
fix: do not charge children of null-parents (#1574)
ysmolski 145115f
chore(master): release 2.9.1 (#1578)
wundergraph-bot[bot] 67bef6e
chore(master): release execution 1.17.0 (#1568)
wundergraph-bot[bot] c28eb40
fix: updates
SkArchon 6d4d207
Merge branch 'master' into milinda/eng-9586-routerengine-force-use-of…
SkArchon e459572
fix: err cleanup
SkArchon 8e7cb3f
fix: renaming
SkArchon 0d395a0
fix: review comments
SkArchon f3ead5a
Merge remote-tracking branch 'origin/master' into milinda/eng-9586-ro…
SkArchon 137aad6
fix: connectrpc resolving
SkArchon 4db647f
fix: make router start
SkArchon 12a89e3
fix: review comments
SkArchon 2d90740
fix: tests
SkArchon ad52548
fix: revert
SkArchon 7517d48
fix: naming
SkArchon 7ab70df
fix: updates
SkArchon b8b1e26
fix: ancestor
SkArchon bfee16b
fix: add clone copy
SkArchon 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package astnormalization | ||
|
|
||
| import ( | ||
| "github.com/wundergraph/graphql-go-tools/v2/pkg/ast" | ||
| "github.com/wundergraph/graphql-go-tools/v2/pkg/astvisitor" | ||
| "github.com/wundergraph/graphql-go-tools/v2/pkg/lexer/position" | ||
| "github.com/wundergraph/graphql-go-tools/v2/pkg/operationreport" | ||
| ) | ||
|
|
||
| // InlineArgument describes a single argument in an operation whose value was | ||
| // supplied inline (a literal) instead of as a variable. | ||
| type InlineArgument struct { | ||
| ArgumentName string | ||
| EnclosingName string | ||
|
SkArchon marked this conversation as resolved.
Outdated
|
||
| EnclosingKind ast.NodeKind | ||
| ValueKind ast.ValueKind | ||
| Position position.Position | ||
| } | ||
|
|
||
| func (a InlineArgument) QualifiedName() string { | ||
| switch a.EnclosingKind { | ||
| case ast.NodeKindField: | ||
| return a.EnclosingName + "." + a.ArgumentName | ||
|
SkArchon marked this conversation as resolved.
Outdated
|
||
| case ast.NodeKindDirective: | ||
| return "@" + a.EnclosingName + "." + a.ArgumentName | ||
| default: | ||
| return a.ArgumentName | ||
| } | ||
| } | ||
|
|
||
| type InlineArgumentsValidationOptions struct { | ||
| Enforce bool | ||
| ErrorMessage string | ||
| ErrorCode string | ||
| StatusCode int | ||
| } | ||
|
|
||
| // NormalizationResult carries per-run outputs of normalization beyond report errors. | ||
| type NormalizationResult struct { | ||
| InlineArguments []InlineArgument | ||
| } | ||
|
|
||
| // RunOptions are per-call inputs to a normalization run. | ||
| type RunOptions struct { | ||
| SkipInlineArguments bool | ||
| } | ||
|
|
||
| func registerInlineArgumentsValidation(walker *astvisitor.Walker, opts InlineArgumentsValidationOptions) *inlineArgumentsVisitor { | ||
| visitor := &inlineArgumentsVisitor{ | ||
| Walker: walker, | ||
| opts: opts, | ||
| } | ||
| walker.RegisterEnterDocumentVisitor(visitor) | ||
| walker.RegisterEnterArgumentVisitor(visitor) | ||
| return visitor | ||
| } | ||
|
|
||
| type inlineArgumentsVisitor struct { | ||
| *astvisitor.Walker | ||
|
|
||
| operation, definition *ast.Document | ||
| opts InlineArgumentsValidationOptions | ||
|
|
||
| // disabled is set per run (see RunOptions.SkipInlineArguments) to exempt this | ||
| // operation from detection/enforcement. | ||
| disabled bool | ||
| // result accumulates the findings for the current run. Reset by the normalizer | ||
| // at the start of each run. | ||
| result NormalizationResult | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| func (v *inlineArgumentsVisitor) EnterDocument(operation, definition *ast.Document) { | ||
| v.operation = operation | ||
| v.definition = definition | ||
| } | ||
|
|
||
| func (v *inlineArgumentsVisitor) EnterArgument(ref int) { | ||
| if v.disabled { | ||
| return | ||
| } | ||
| valueKind := v.operation.Arguments[ref].Value.Kind | ||
| if valueKind == ast.ValueKindVariable { | ||
| return | ||
| } | ||
|
|
||
| if v.opts.Enforce { | ||
| // Reject on the first inline argument and stop the walk. A single generic | ||
| // error is enough to signal that the operation is non-compliant; we don't | ||
| // name the argument or point at its location. | ||
| v.StopWithExternalErr(operationreport.ExternalError{ | ||
| Message: v.opts.ErrorMessage, | ||
| ExtensionCode: v.opts.ErrorCode, | ||
| StatusCode: v.opts.StatusCode, | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| finding := InlineArgument{ | ||
| ArgumentName: v.operation.ArgumentNameString(ref), | ||
| ValueKind: valueKind, | ||
| Position: v.operation.Arguments[ref].Position, | ||
| } | ||
|
|
||
| if len(v.Ancestors) > 0 { | ||
|
SkArchon marked this conversation as resolved.
Outdated
|
||
| parent := v.Ancestors[len(v.Ancestors)-1] | ||
| finding.EnclosingKind = parent.Kind | ||
| switch parent.Kind { | ||
| case ast.NodeKindField: | ||
| finding.EnclosingName = v.operation.FieldNameString(parent.Ref) | ||
| case ast.NodeKindDirective: | ||
| finding.EnclosingName = v.operation.DirectiveNameString(parent.Ref) | ||
| } | ||
| } | ||
|
|
||
| v.result.InlineArguments = append(v.result.InlineArguments, finding) | ||
| } | ||
Oops, something went wrong.
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.