Skip to content

Commit

Permalink
Don't throw UnknownMethodException's for null arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jun 14, 2023
1 parent 0a405b1 commit eaab984
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Added a new `_globals` global Twig variable for front-end templates, which can be used to store custom values in a global scope. ([#13050](https://github.com/craftcms/cms/pull/13050), [#12951](https://github.com/craftcms/cms/discussions/12951))
- The `|replace` Twig filter now supports passing in a hash with regular expression keys. ([#12956](https://github.com/craftcms/cms/issues/12956))
- `{% exit %}` tags now support passing a message after the status code. ([#13166](https://github.com/craftcms/cms/discussions/13166))
- Built-in element types’ GraphQL queries now support passing `null` to `relatedToAssets`, `relatedToEntries`, `relatedToUsers`, `relatedToCategories`, `relatedToTags`, and `relatedToAll` arguments. ([#7954](https://github.com/craftcms/cms/issues/7954))
- Elements now include custom field values when being iterated over, and when being merged. ([#13009](https://github.com/craftcms/cms/issues/13009))
- Dropdown and Radio Buttons fields now have a “Column Type” setting, which will be set to `varchar` for existing fields, and defaults to “Automatic” for new fields. ([#13025](https://github.com/craftcms/cms/pull/13025), [#12954](https://github.com/craftcms/cms/issues/12954))

Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\gql\base\ElementResolver;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class Address
Expand Down Expand Up @@ -42,7 +43,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

if (!GqlHelper::canQueryUsers()) {
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\gql\base\ElementResolver;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class Asset
Expand Down Expand Up @@ -41,7 +42,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

$pairs = GqlHelper::extractAllowedEntitiesFromSchema('read');
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\gql\base\ElementResolver;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class Category
Expand Down Expand Up @@ -41,7 +42,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

$pairs = GqlHelper::extractAllowedEntitiesFromSchema('read');
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\gql\base\ElementResolver;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class Entry
Expand Down Expand Up @@ -41,7 +42,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

$pairs = GqlHelper::extractAllowedEntitiesFromSchema('read');
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/GlobalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use craft\gql\base\ElementResolver;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class GlobalSet
Expand All @@ -28,7 +29,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
$query = GlobalSetElement::find();

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

$pairs = GqlHelper::extractAllowedEntitiesFromSchema('read');
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/MatrixBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use craft\elements\db\ElementQuery;
use craft\elements\MatrixBlock as MatrixBlockElement;
use craft\gql\base\ElementResolver;
use yii\base\UnknownMethodException;

/**
* Class MatrixBlock
Expand Down Expand Up @@ -38,7 +39,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

return $query;
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\gql\base\ElementResolver;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class Tag
Expand Down Expand Up @@ -41,7 +42,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

$pairs = GqlHelper::extractAllowedEntitiesFromSchema('read');
Expand Down
9 changes: 8 additions & 1 deletion src/gql/resolvers/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use craft\helpers\ArrayHelper;
use craft\helpers\Gql as GqlHelper;
use Illuminate\Support\Collection;
use yii\base\UnknownMethodException;

/**
* Class User
Expand Down Expand Up @@ -66,7 +67,13 @@ public static function prepareQuery(mixed $source, array $arguments, ?string $fi
}

foreach ($arguments as $key => $value) {
$query->$key($value);
try {
$query->$key($value);
} catch (UnknownMethodException $e) {
if ($value !== null) {
throw $e;
}
}
}

if (!GqlHelper::canQueryUsers()) {
Expand Down

0 comments on commit eaab984

Please sign in to comment.