nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.37k stars 439 forks source link

Eliminate redundant `Model::save()` calls in nested mutations #2570

Closed spawnia closed 5 months ago

spawnia commented 5 months ago

Changes

Because NestedBelongsTo unnecessarily passed through the $parentRelation to SaveModel, updating multiple BelongsTo relations of a model in a single nested mutation resulted in multiple save operations. See the repeated calls to update `users` set in the following log:

"select * from `users` where `users`.`id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `companies` where `companies`.`id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `companies` set `name` = ?, `companies`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `users` set `name` = ?, `company_id` = ?, `users`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `teams` where `teams`.`id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `teams` set `name` = ?, `teams`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"update `users` set `team_id` = ?, `users`.`updated_at` = ? where `id` = ?" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `users` where `id` = ? limit 1" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `companies` where `companies`.`id` in (1)" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518
"select * from `teams` where `teams`.`id` in (1)" // /workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:518

Failed asserting that actual size 2 matches expected size 1.
/workdir/tests/Integration/Execution/MutationExecutor/BelongsToTest.php:570

Breaking changes

Should be none.