Skip to content

Commit

Permalink
refactor(graphql): Added default implementation of `InputObject::getO…
Browse files Browse the repository at this point in the history
…perators()`.
  • Loading branch information
LastDragon-ru committed Jan 31, 2024
1 parent 467b023 commit 53f01f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 49 deletions.
11 changes: 10 additions & 1 deletion packages/graphql/src/Builder/Types/InputObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ protected function getOperators(
InputSource|ObjectSource|InterfaceSource $source,
Context $context,
): array {
return [];
$type = $this->getTypeForOperators();
$operators = $type
? $manipulator->getTypeOperators($this->getScope(), $type, $context)
: [];

return $operators;
}

/**
Expand Down Expand Up @@ -434,6 +439,10 @@ protected function isFieldDirectiveAllowed(
|| $directive instanceof RenameDirective;
}

protected function getTypeForOperators(): ?string {
return null;
}

protected function getTypeForFieldOperator(): ?string {
return null;
}
Expand Down
28 changes: 5 additions & 23 deletions packages/graphql/src/SearchBy/Types/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
use LastDragon_ru\LaraASP\GraphQL\SearchBy\Operators;
use Override;

use function array_merge;
use function array_unique;
use function array_values;
use function is_string;

use const SORT_REGULAR;

class Condition extends InputObject {
#[Override]
public function getTypeName(TypeSource $source, Context $context): string {
Expand All @@ -53,24 +48,6 @@ protected function getDescription(
return "Available conditions for `{$source}` (only one property allowed at a time).";
}

/**
* @inheritDoc
*/
#[Override]
protected function getOperators(
Manipulator $manipulator,
InputSource|ObjectSource|InterfaceSource $source,
Context $context,
): array {
return array_values(array_unique(
array_merge(
parent::getOperators($manipulator, $source, $context),
$manipulator->getTypeOperators($this->getScope(), Operators::Extra, $context),
),
SORT_REGULAR,
));
}

#[Override]
protected function getFieldMarkerOperator(): string {
return Operator::class;
Expand All @@ -81,6 +58,11 @@ protected function getFieldMarkerIgnored(): ?string {
return Ignored::class;
}

#[Override]
protected function getTypeForOperators(): ?string {
return Operators::Extra;
}

#[Override]
protected function getTypeForFieldOperator(): ?string {
return Operators::Object;
Expand Down
30 changes: 5 additions & 25 deletions packages/graphql/src/SortBy/Types/Clause.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
use LastDragon_ru\LaraASP\GraphQL\SortBy\Operators;
use Override;

use function array_merge;
use function array_unique;
use function array_values;
use function is_string;

use const SORT_REGULAR;

class Clause extends InputObject {
#[Override]
public function getTypeName(TypeSource $source, Context $context): string {
Expand All @@ -53,26 +48,6 @@ protected function getDescription(
return "Sort clause for `{$source}` (only one property allowed at a time).";
}

/**
* @inheritDoc
*/
#[Override]
protected function getOperators(
Manipulator $manipulator,
InputSource|ObjectSource|InterfaceSource $source,
Context $context,
): array {
return array_values(
array_unique(
array_merge(
parent::getOperators($manipulator, $source, $context),
$manipulator->getTypeOperators($this->getScope(), Operators::Extra, $context),
),
SORT_REGULAR,
),
);
}

#[Override]
protected function isFieldConvertableImplicit(
Manipulator $manipulator,
Expand Down Expand Up @@ -103,6 +78,11 @@ protected function getFieldMarkerIgnored(): ?string {
return Ignored::class;
}

#[Override]
protected function getTypeForOperators(): ?string {
return Operators::Extra;
}

#[Override]
protected function getTypeForFieldOperator(): ?string {
return Operators::Object;
Expand Down

0 comments on commit 53f01f7

Please sign in to comment.