Skip to content

validator: reject duplicate argument definitions - #491

Merged
StevenACoffman merged 2 commits into
vektah:masterfrom
LuisFigueroaG:fix/unique-argument-definition-names
Oct 8, 2026
Merged

StevenACoffman merged 2 commits into
vektah:masterfrom
LuisFigueroaG:fix/unique-argument-definition-names

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

LoadSchema accepted a field or directive definition that declares the same argument twice, e.g. field(id: ID, id: String). Lookups by name only ever see the first one, so the second declaration was silently dropped.

This adds graphql-js' UniqueArgumentDefinitionNames check for field arguments and directive definitions. It reports the second occurrence as Argument Query.field(id:) can only be defined once. (or Argument @dir(id:) ...), the graphql-js message without the quotes, like the other schema errors here. It's listed as an unintentional gap in WIP.md, which I've updated.

I have:

  • Added tests covering the bug / feature
  • Updated any relevant documentation

LoadSchema accepted a field or directive definition that declared the
same argument twice, e.g. `field(id: ID, id: String)`. Lookups by name
only ever see the first one, so the second declaration was silently
ignored.

Add the UniqueArgumentDefinitionNames check from graphql-js for field
arguments on object/interface types and for directive definitions,
reporting the second occurrence as
"Argument Query.field(id:) can only be defined once." or
"Argument @dir(id:) can only be defined once."

Move the rule from the gaps list to the covered list in WIP.md.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The validation is correctly integrated, documented, and comprehensively tested across supported argument-definition contexts.

0 open findings

What changed in this PR

Adds schema validation rejecting duplicate argument definitions for fields and directives.

Changes:

  • Validates argument-name uniqueness and reports the duplicate location.
  • Adds positive and negative object, interface, and directive tests.
  • Updates validation-gap documentation.
File Description
WIP.md Marks argument-definition uniqueness as covered.
validator/​schema.go Adds duplicate argument-name validation.
validator/​schema_test.yml Adds regression and positive test cases.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The owner label for the duplicate-argument error was concatenated on
every field and directive definition, adding ~95 allocs to
BenchmarkLoadSchema. Return the duplicate instead and format the error
only when one is found.
@StevenACoffman

Copy link
Copy Markdown
Collaborator

Hey, this is great! I really appreciated this improvement. Looking forward to the next one. I made a little performance tweak to your code.

@StevenACoffman
StevenACoffman merged commit ca12c04 into vektah:master Oct 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants