-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add UnionType * Add Having types and fields
- Loading branch information
1 parent
bb15b57
commit 0df1d1a
Showing
11 changed files
with
212 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Efabrica\GraphQL\Schema\Custom\Fields; | ||
|
||
use Efabrica\GraphQL\Schema\Custom\Types\HavingType; | ||
use Efabrica\GraphQL\Schema\Definition\Fields\InputObjectField; | ||
|
||
class HavingAndField extends InputObjectField | ||
{ | ||
public const NAME = 'having'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct( | ||
self::NAME, | ||
new HavingType() | ||
); | ||
|
||
$this->setMulti() | ||
->setNullable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Efabrica\GraphQL\Schema\Custom\Fields; | ||
|
||
use Efabrica\GraphQL\Schema\Custom\Types\HavingType; | ||
use Efabrica\GraphQL\Schema\Definition\Fields\InputObjectField; | ||
|
||
class HavingOrField extends InputObjectField | ||
{ | ||
public const NAME = 'having_or'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct( | ||
self::NAME, | ||
new HavingType() | ||
); | ||
|
||
$this->setMulti() | ||
->setNullable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Efabrica\GraphQL\Schema\Custom\Types; | ||
|
||
use Efabrica\GraphQL\Schema\Definition\Fields\InputObjectField; | ||
use Efabrica\GraphQL\Schema\Definition\Types\InputObjectType; | ||
use Efabrica\GraphQL\Schema\Definition\Types\Scalar\StringType; | ||
|
||
class GroupType extends InputObjectType | ||
{ | ||
public const FIELD_COLUMN = 'column'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct( | ||
'group_type', | ||
); | ||
|
||
$this->setFields(fn() => [ | ||
new InputObjectField(self::FIELD_COLUMN, new StringType()), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Efabrica\GraphQL\Schema\Custom\Types; | ||
|
||
use Efabrica\GraphQL\Schema\Custom\Fields\HavingAndField; | ||
use Efabrica\GraphQL\Schema\Custom\Fields\HavingOrField; | ||
use Efabrica\GraphQL\Schema\Definition\Fields\InputObjectField; | ||
use Efabrica\GraphQL\Schema\Definition\Types\InputObjectType; | ||
use Efabrica\GraphQL\Schema\Definition\Types\Scalar\StringType; | ||
|
||
class HavingType extends InputObjectType | ||
{ | ||
public const FIELD_COLUMN = 'column'; | ||
public const FIELD_VALUE = 'value'; | ||
public const FIELD_COMPARATOR = 'comparator'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct( | ||
'having_type', | ||
); | ||
|
||
$this->setFields(fn() => [ | ||
new HavingAndField(), | ||
new HavingOrField(), | ||
(new InputObjectField(self::FIELD_COLUMN, new StringType())) | ||
->setNullable(), | ||
(new InputObjectField(self::FIELD_VALUE, new StringType())) | ||
->setMulti() | ||
->setNullable(), | ||
(new InputObjectField(self::FIELD_COMPARATOR, new WhereComparatorEnum())) | ||
->setDefaultValue(WhereComparatorEnum::EQUAL), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Efabrica\GraphQL\Schema\Definition\Types; | ||
|
||
class UnionType extends Type | ||
{ | ||
/** | ||
* @var ObjectType[] | ||
*/ | ||
protected array $objectTypes = []; | ||
|
||
/** @var callable */ | ||
protected $objectTypesCallback; | ||
|
||
/** @var callable */ | ||
protected $resolveType; | ||
|
||
public function getObjectTypes(): array | ||
{ | ||
if ($this->objectTypesCallback === null) { | ||
return $this->objectTypes; | ||
} | ||
|
||
$objectTypes = []; | ||
foreach (call_user_func($this->objectTypesCallback) as $type) { | ||
$objectTypes[$type->getName()] = $type; | ||
} | ||
|
||
return array_merge($objectTypes, $this->objectTypes); | ||
} | ||
|
||
public function addObjectType(ObjectType $objectType): self | ||
{ | ||
$this->objectTypes[$objectType->getName()] = $objectType; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param ObjectType[]|callable $objectTypes | ||
*/ | ||
public function setObjectTypes($objectTypes): self | ||
{ | ||
if (is_callable($objectTypes)) { | ||
$this->objectTypesCallback = $objectTypes; | ||
} else { | ||
$this->objectTypes = []; | ||
foreach ($objectTypes as $objectType) { | ||
$this->objectTypes[$objectType->getName()] = $objectType; | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function getResolveType(): callable | ||
{ | ||
return $this->resolveType; | ||
} | ||
|
||
public function setResolveType(callable $resolveType): self | ||
{ | ||
$this->resolveType = $resolveType; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters