1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?php
namespace WPGraphQL\Type\Theme\Connection;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Relay;
use WPGraphQL\AppContext;
class ThemeConnectionResolver {
public static function resolve( $source, array $args, AppContext $context, ResolveInfo $info ) {
$themes_array = [];
$themes = wp_get_themes();
if ( is_array( $themes ) && ! empty( $themes ) ) {
foreach ( $themes as $theme ) {
$themes_array[] = $theme;
}
}
$connection = Relay::connectionFromArray( $themes_array, $args );
$nodes = [];
if ( ! empty( $connection['edges'] ) && is_array( $connection['edges'] ) ) {
foreach ( $connection['edges'] as $edge ) {
$nodes[] = ! empty( $edge['node'] ) ? $edge['node'] : null;
}
}
$connection['nodes'] = ! empty( $nodes ) ? $nodes : null;
return ! empty( $themes_array ) ? $connection : null;
}
}