Skip to content

Update RenameArgsDirective.php#2763

Open
baonguyen212002 wants to merge 1 commit intonuwave:masterfrom
baonguyen212002:patch-1
Open

Update RenameArgsDirective.php#2763
baonguyen212002 wants to merge 1 commit intonuwave:masterfrom
baonguyen212002:patch-1

Conversation

@baonguyen212002
Copy link

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md (skip for docs-only changes)

Changes

Breaking changes

@baonguyen212002
Copy link
Author

Bug: @rename directive drops field when attribute name matches the original field name

Problem

When using @rename(attribute: "currency") on a field already named currency (i.e., source name === target name), the field is silently dropped from the arguments and never reaches the resolver.

Example schema:
input CommonPaymentMethodInput {
currency: String @rename(attribute: "currency")
settlementDays: Float @rename(attribute: "settlement_days")
}

Sending { currency: "USD", settlementDays: 0 } results in the resolver receiving only { settlement_days: 0 } — currency is missing.

Root Cause

In RenameArgsDirective::rename() (line 64-67):

if ($maybeRenameDirective instanceof RenameDirective) {
$argumentSet->arguments[$maybeRenameDirective->attributeArgValue()] = $argument;
unset($argumentSet->arguments[$name]);
}

When $name === $maybeRenameDirective->attributeArgValue() (e.g., both are "currency"):

  1. Line 65: assigns $arguments["currency"] = $argument
  2. Line 66: immediately unset($arguments["currency"]) — deleting what was just assigned

Fix

if ($maybeRenameDirective instanceof RenameDirective) {
$newName = $maybeRenameDirective->attributeArgValue();
$argumentSet->arguments[$newName] = $argument;
if ($newName !== $name) {
unset($argumentSet->arguments[$name]);
}
}

Skip the unset when source and target names are identical.

Reproduction

Schema

input TestInput {
name: String @rename(attribute: "name") # same name → BUG
firstName: String @rename(attribute: "first_name") # different name → OK
}

Query

mutation {
test(input: { name: "John", firstName: "Jane" })
}

Resolver receives: { "first_name": "Jane" }

Expected: { "name": "John", "first_name": "Jane" }

baonguyen212002

This comment was marked as duplicate.

@spawnia
Copy link
Collaborator

spawnia commented Mar 21, 2026

Let's throw a DefinitionException instead for that case - the correct fix is to delete the directive. That can be done at schema build time, so it costs nothing at runtime.

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.

2 participants