self::get_input_fields(), 'outputFields' => self::get_output_fields(), 'mutateAndGetPayload' => self::mutate_and_get_payload(), ] ); } /** * Defines the mutation input field configuration * * @return array */ public static function get_input_fields() { return array_merge( Review_Write::get_input_fields(), [ 'id' => [ 'type' => [ 'non_null' => 'ID' ], 'description' => static function () { return __( 'The ID of the review being updated.', 'graphql-for-ecommerce' ); }, ], ] ); } /** * Defines the mutation output field configuration * * @return array */ public static function get_output_fields() { return Review_Write::get_output_fields(); } /** * Defines the mutation data modification closure. * * @return callable */ public static function mutate_and_get_payload() { return static function ( $input, AppContext $context, ResolveInfo $info ) { // Set comment type to "review". $input['type'] = 'review'; $skip = [ 'type' => 'review', 'id' => 1, 'rating' => 1, 'clientMutationId' => 1, ]; $payload = []; $id = Utils::get_database_id_from_id( $input['id'] ); if ( ! $id ) { throw new UserError( __( 'Provided review ID missing or invalid ', 'graphql-for-ecommerce' ) ); } if ( array_intersect_key( $input, $skip ) !== $input ) { $resolver = CommentUpdate::mutate_and_get_payload(); $payload = $resolver( $input, $context, $info ); } // Check if product rating needs updating. if ( ! empty( $payload['id'] ) && isset( $input['rating'] ) ) { update_comment_meta( $payload['id'], 'rating', $input['rating'] ); } return $payload; }; } }