Skip to content

Commit

Permalink
Fix delete mutation responses
Browse files Browse the repository at this point in the history
Fixes #15465
  • Loading branch information
brandonkelly committed Aug 3, 2024
1 parent 6b8673c commit 64f8f95
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed a PHP error. ([#14635](https://github.com/craftcms/cms/issues/14635))
- Fixed a PHP error that could occur when running Codeception tests. ([#15445](https://github.com/craftcms/cms/issues/15445))
- Fixed a bug where `deleteAsset`, `deleteCategory`, `deleteEntry`, and `deleteTag` GraphQL mutations were returning `null` rather than `true` or `false`. ([#15465](https://github.com/craftcms/cms/issues/15465))

## 4.10.7 - 2024-07-29

Expand Down
7 changes: 4 additions & 3 deletions src/gql/resolvers/mutations/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ public function saveAsset(mixed $source, array $arguments, mixed $context, Resol
* @param array $arguments
* @param mixed $context
* @param ResolveInfo $resolveInfo
* @return bool
* @throws Throwable if reasons.
*/
public function deleteAsset(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): void
public function deleteAsset(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): bool
{
$assetId = $arguments['id'];

Expand All @@ -124,13 +125,13 @@ public function deleteAsset(mixed $source, array $arguments, mixed $context, Res
$asset = $elementService->getElementById($assetId, AssetElement::class);

if (!$asset) {
return;
return false;
}

$volumeUid = Db::uidById(Table::VOLUMES, $asset->getVolumeId());
$this->requireSchemaAction('volumes.' . $volumeUid, 'delete');

$elementService->deleteElementById($assetId);
return $elementService->deleteElementById($assetId);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/gql/resolvers/mutations/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,23 @@ public function saveCategory(mixed $source, array $arguments, mixed $context, Re
* @param array $arguments
* @param mixed $context
* @param ResolveInfo $resolveInfo
* @return bool
* @throws Throwable if reasons.
*/
public function deleteCategory(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): void
public function deleteCategory(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): bool
{
$categoryId = $arguments['id'];

$elementService = Craft::$app->getElements();
$category = $elementService->getElementById($categoryId, CategoryElement::class);

if (!$category) {
return;
return false;
}

$categoryGroupUid = Db::uidById(Table::CATEGORYGROUPS, $category->groupId);
$this->requireSchemaAction('categorygroups.' . $categoryGroupUid, 'delete');

$elementService->deleteElementById($categoryId);
return $elementService->deleteElementById($categoryId);
}
}
7 changes: 4 additions & 3 deletions src/gql/resolvers/mutations/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ public function saveEntry(mixed $source, array $arguments, mixed $context, Resol
* @param array $arguments
* @param mixed $context
* @param ResolveInfo $resolveInfo
* @return bool
* @throws Throwable if reasons.
*/
public function deleteEntry(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): void
public function deleteEntry(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): bool
{
$entryId = $arguments['id'];
$siteId = $arguments['siteId'] ?? null;
Expand All @@ -119,13 +120,13 @@ public function deleteEntry(mixed $source, array $arguments, mixed $context, Res
$entry = $elementService->getElementById($entryId, EntryElement::class, $siteId);

if (!$entry) {
return;
return false;
}

$entryTypeUid = Db::uidById(Table::ENTRYTYPES, $entry->getTypeId());
$this->requireSchemaAction('entrytypes.' . $entryTypeUid, 'delete');

$elementService->deleteElementById($entryId);
return $elementService->deleteElementById($entryId);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/gql/resolvers/mutations/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,23 @@ public function saveTag(mixed $source, array $arguments, mixed $context, Resolve
* @param array $arguments
* @param mixed $context
* @param ResolveInfo $resolveInfo
* @return bool
* @throws Throwable if reasons.
*/
public function deleteTag(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): void
public function deleteTag(mixed $source, array $arguments, mixed $context, ResolveInfo $resolveInfo): bool
{
$tagId = $arguments['id'];

$elementService = Craft::$app->getElements();
$tag = $elementService->getElementById($tagId, TagElement::class);

if (!$tag) {
return;
return false;
}

$tagGroupUid = Db::uidById(Table::TAGGROUPS, $tag->groupId);
$this->requireSchemaAction('taggroups.' . $tagGroupUid, 'delete');

$elementService->deleteElementById($tagId);
return $elementService->deleteElementById($tagId);
}
}

0 comments on commit 64f8f95

Please sign in to comment.