GetCoupon.php
1 month ago
GetProduct.php
1 month ago
ListCoupons.php
1 month ago
ListProducts.php
1 month ago
ListCoupons.php
102 lines
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | // THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY. |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLQueries; |
| 7 | |
| 8 | use Automattic\WooCommerce\Api\Queries\Coupons\ListCoupons as ListCouponsCommand; |
| 9 | use Automattic\WooCommerce\Api\Infrastructure\QueryInfoExtractor; |
| 10 | use Automattic\WooCommerce\Api\Infrastructure\ResolverHelpers; |
| 11 | use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Pagination\CouponConnection as CouponConnectionType; |
| 12 | use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Enums\CouponStatus as CouponStatusType; |
| 13 | use Automattic\WooCommerce\Api\Infrastructure\Schema\ResolveInfo; |
| 14 | use Automattic\WooCommerce\Api\Infrastructure\Schema\Type; |
| 15 | |
| 16 | class ListCoupons { |
| 17 | public static function get_field_definition(): array { |
| 18 | return array( |
| 19 | 'type' => Type::nonNull( CouponConnectionType::get() ), |
| 20 | 'description' => __( 'List coupons with cursor-based pagination.', 'woocommerce' ), |
| 21 | 'authorization' => array( |
| 22 | array( |
| 23 | 'attribute' => 'RequiredCapability', |
| 24 | 'args' => array( |
| 25 | 0 => 'read_private_shop_coupons', |
| 26 | ), |
| 27 | ), |
| 28 | ), |
| 29 | 'args' => array( |
| 30 | 'first' => array( |
| 31 | 'type' => Type::int(), |
| 32 | 'description' => __( 'Return the first N results. Must be between 0 and 100.', 'woocommerce' ), |
| 33 | 'defaultValue' => null, |
| 34 | ), |
| 35 | 'last' => array( |
| 36 | 'type' => Type::int(), |
| 37 | 'description' => __( 'Return the last N results. Must be between 0 and 100.', 'woocommerce' ), |
| 38 | 'defaultValue' => null, |
| 39 | ), |
| 40 | 'after' => array( |
| 41 | 'type' => Type::string(), |
| 42 | 'description' => __( 'Return results after this cursor.', 'woocommerce' ), |
| 43 | 'defaultValue' => null, |
| 44 | ), |
| 45 | 'before' => array( |
| 46 | 'type' => Type::string(), |
| 47 | 'description' => __( 'Return results before this cursor.', 'woocommerce' ), |
| 48 | 'defaultValue' => null, |
| 49 | ), |
| 50 | 'status' => array( |
| 51 | 'type' => CouponStatusType::get(), |
| 52 | 'description' => __( 'Filter by coupon status.', 'woocommerce' ), |
| 53 | 'defaultValue' => null, |
| 54 | ), |
| 55 | ), |
| 56 | 'complexity' => ResolverHelpers::complexity_from_pagination( ... ), |
| 57 | 'resolve' => array( self::class, 'resolve' ), |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | public static function resolve( mixed $root, array $args, mixed $context, ResolveInfo $info ): mixed { |
| 62 | // Standalone authorization gate: no authorize() method on the command, |
| 63 | // so the autodiscovered authorization attributes are the sole guard. |
| 64 | if ( ! self::compute_preauthorized( $context['principal'] ) ) { |
| 65 | throw ResolverHelpers::build_authorization_error( $context['principal'] ); |
| 66 | } |
| 67 | |
| 68 | // Publish the root query's metadata so downstream field-level |
| 69 | // authorization gates can read it via `$_metadata['query']`. |
| 70 | // $context is an ArrayObject (see GraphQLController::process_request()) |
| 71 | // so the mutation propagates to nested resolvers. |
| 72 | $context['_query_metadata'] = array(); |
| 73 | |
| 74 | $command = \Automattic\WooCommerce\Api\Infrastructure\ClassResolver::resolve_class( ListCouponsCommand::class ); |
| 75 | |
| 76 | $execute_args = array(); |
| 77 | $execute_args['pagination'] = ResolverHelpers::create_pagination_params( $args ); |
| 78 | if ( array_key_exists( 'status', $args ) ) { |
| 79 | $execute_args['status'] = $args['status']; |
| 80 | } |
| 81 | |
| 82 | $result = ResolverHelpers::execute_command( $command, $execute_args ); |
| 83 | |
| 84 | return $result; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Compute the value `_preauthorized` would carry for a given principal — |
| 89 | * the AND of the autodiscovered authorization attributes' authorize() |
| 90 | * outcomes on this command. Single source of truth for both the resolver's |
| 91 | * own gates and external (code-API) callers asking about authorization |
| 92 | * without going through GraphQL execution. |
| 93 | * |
| 94 | * Returns true vacuously when the command has no authorization attributes |
| 95 | * (in that case authorize() on the command is the sole guard, and that |
| 96 | * method should be consulted instead). |
| 97 | */ |
| 98 | public static function compute_preauthorized( \Automattic\WooCommerce\Api\Infrastructure\Principal $principal ): bool { |
| 99 | return ( new \Automattic\WooCommerce\Api\Attributes\RequiredCapability( 'read_private_shop_coupons' ) )->authorize( $principal ); |
| 100 | } |
| 101 | } |
| 102 |