class_exists('WPGraphQL'), ]; $missing_dependencies = array_keys( array_diff($core_dependencies, array_filter($core_dependencies)) ); $display_admin_notice = static function () use ($missing_dependencies) { ?>

__( 'The redirect', 'add-wpgraphql-redirection' ), 'fields' => [ 'origin' => ['type' => 'String'], 'target' => ['type' => 'String'], 'type' => ['type' => 'String'], 'code' => ['type' => 'Int'], 'groupId' => ['type' => 'Int'], 'groupName' => ['type' => 'String'], 'matchType' => ['type' => 'String'], ], ]); register_graphql_object_type('RedirectionRedirects', [ 'description' => __('The Redirects', 'add-wpgraphql-redirection'), 'fields' => [ 'redirects' => ['type' => ['list_of' => 'RedirectionRedirect']], ], ]); register_graphql_field( 'RootQuery', 'redirection', [ 'type' => 'RedirectionRedirects', 'description' => __( 'The redirects', 'add-wpgraphql-redirection' ), 'resolve' => function ( $post, array $args, AppContext $context ) { global $wpdb; $cache_key = 'wpgraphql_redirection_items'; $rows = wp_cache_get($cache_key); if (false === $rows) { $sql = "SELECT {$wpdb->prefix}redirection_items.*, {$wpdb->prefix}redirection_groups.name FROM {$wpdb->prefix}redirection_items INNER JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_groups.id={$wpdb->prefix}redirection_items.group_id ORDER BY {$wpdb->prefix}redirection_items.position"; $rows = $wpdb->get_results($sql); wp_cache_set($cache_key, $rows); } $items = []; foreach ((array) $rows as $row) { $items[] = [ 'origin' => $row->url, 'target' => $row->action_data, 'code' => absint($row->action_code), 'type' => $row->action_type, 'groupId' => $row->group_id, 'groupName' => $row->name, 'matchType' => $row->match_type, ]; } return ['redirects' => !empty($items) ? $items : null]; }, ] ); }); });