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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
<?php
namespace WPGraphQL\Type;
use WPGraphQL\Type\MediaItem\Mutation\MediaItemCreate;
use WPGraphQL\Type\MediaItem\Mutation\MediaItemUpdate;
use WPGraphQL\Type\MediaItem\Mutation\MediaItemDelete;
use WPGraphQL\Type\PostObject\Mutation\PostObjectCreate;
use WPGraphQL\Type\PostObject\Mutation\PostObjectDelete;
use WPGraphQL\Type\PostObject\Mutation\PostObjectUpdate;
use WPGraphQL\Type\PostObject\Mutation\TermObjectDelete;
use WPGraphQL\Type\TermObject\Mutation\TermObjectCreate;
use WPGraphQL\Type\TermObject\Mutation\TermObjectUpdate;
use WPGraphQL\Type\User\Mutation\UserCreate;
use WPGraphQL\Type\User\Mutation\UserDelete;
use WPGraphQL\Type\User\Mutation\UserUpdate;
class RootMutationType extends WPObjectType {
private static $fields;
private static $type_name;
public function __construct() {
self::$type_name = 'rootMutation';
$config = [
'name' => self::$type_name,
'description' => __( 'The root mutation', 'wp-graphql' ),
'fields' => self::fields(),
];
parent::__construct( $config );
}
private static function fields() {
if ( null === self::$fields ) {
$fields = [];
$allowed_post_types = \WPGraphQL::$allowed_post_types;
$allowed_taxonomies = \WPGraphQL::$allowed_taxonomies;
if ( ! empty( $allowed_post_types ) && is_array( $allowed_post_types ) ) {
foreach ( $allowed_post_types as $post_type ) {
$post_type_object = get_post_type_object( $post_type );
if ( 'mediaItem' === $post_type_object->graphql_single_name ) {
$fields[ 'create' . ucwords( $post_type_object->graphql_single_name ) ] = MediaItemCreate::mutate( $post_type_object );
$fields[ 'update' . ucwords( $post_type_object->graphql_single_name ) ] = MediaItemUpdate::mutate( $post_type_object );
$fields[ 'delete' . ucwords( $post_type_object->graphql_single_name ) ] = MediaItemDelete::mutate( $post_type_object );
} else {
$fields[ 'create' . ucwords( $post_type_object->graphql_single_name ) ] = PostObjectCreate::mutate( $post_type_object );
$fields[ 'update' . ucwords( $post_type_object->graphql_single_name ) ] = PostObjectUpdate::mutate( $post_type_object );
$fields[ 'delete' . ucwords( $post_type_object->graphql_single_name ) ] = PostObjectDelete::mutate( $post_type_object );
}
}
}
if ( ! empty( $allowed_taxonomies ) && is_array( $allowed_taxonomies ) ) {
foreach ( $allowed_taxonomies as $taxonomy ) {
$taxonomy_object = get_taxonomy( $taxonomy );
$fields[ 'create' . ucwords( $taxonomy_object->graphql_single_name ) ] = TermObjectCreate::mutate( $taxonomy_object );
$fields[ 'update' . ucwords( $taxonomy_object->graphql_single_name ) ] = TermObjectUpdate::mutate( $taxonomy_object );
$fields[ 'delete' . ucwords( $taxonomy_object->graphql_single_name ) ] = TermObjectDelete::mutate( $taxonomy_object );
}
}
$fields[ 'createUser' ] = UserCreate::mutate();
$fields[ 'updateUser' ] = UserUpdate::mutate();
$fields[ 'deleteUser' ] = UserDelete::mutate();
self::$fields = $fields;
}
return self::prepare_fields( self::$fields, self::$type_name );
}
}