-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b311d0b
commit 764480c
Showing
3 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\commerce\gql\types; | ||
|
||
use craft\gql\base\ObjectType; | ||
use craft\gql\GqlEntityRegistry; | ||
use craft\gql\TypeManager; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* Class SaleType | ||
* | ||
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com> | ||
* @since 3.x | ||
*/ | ||
class SaleType extends ObjectType | ||
{ | ||
/** | ||
* @return string|null | ||
*/ | ||
public static function getName(): string | ||
{ | ||
return 'Sale'; | ||
} | ||
|
||
/** | ||
* @return Type | ||
*/ | ||
public static function getType(): Type | ||
{ | ||
if ($type = GqlEntityRegistry::getEntity(self::getName())) { | ||
return $type; | ||
} | ||
|
||
$type = GqlEntityRegistry::createEntity(self::getName(), new self([ | ||
'name' => static::getName(), | ||
'fields' => self::class . '::getFieldDefinitions', | ||
'description' => '', | ||
])); | ||
|
||
return $type; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getFieldDefinitions(): array | ||
{ | ||
return TypeManager::prepareFieldDefinitions([ | ||
'name' => [ | ||
'name' => 'name', | ||
'type' => Type::string(), | ||
'description' => 'The name of the sale as described in the control panel.', | ||
], | ||
'description' => [ | ||
'name' => 'description', | ||
'type' => Type::string(), | ||
'description' => 'Description of the sale.', | ||
], | ||
], self::getName()); | ||
} | ||
} |