Overview
  • Namespace
  • Class

Namespaces

  • WPGraphQL
    • Data
    • Type
      • Avatar
      • Comment
        • Connection
      • CommentAuthor
      • EditLock
      • Enum
      • MediaItem
        • Mutation
      • Plugin
        • Connection
      • PostObject
        • Connection
        • Mutation
      • PostType
      • Setting
      • Taxonomy
      • TermObject
        • Connection
        • Mutation
      • Theme
        • Connection
      • Union
      • User
        • Connection
        • Mutation
    • Utils

Classes

  • WPGraphQL\AppContext
  • WPGraphQL\Data\Config
  • WPGraphQL\Data\ConnectionResolver
  • WPGraphQL\Data\DataSource
  • WPGraphQL\Data\Loader
  • WPGraphQL\Router
  • WPGraphQL\Type\Avatar\AvatarType
  • WPGraphQL\Type\Comment\CommentQuery
  • WPGraphQL\Type\Comment\CommentType
  • WPGraphQL\Type\Comment\Connection\CommentConnectionArgs
  • WPGraphQL\Type\Comment\Connection\CommentConnectionDefinition
  • WPGraphQL\Type\Comment\Connection\CommentConnectionResolver
  • WPGraphQL\Type\CommentAuthor\CommentAuthorQuery
  • WPGraphQL\Type\CommentAuthor\CommentAuthorType
  • WPGraphQL\Type\EditLock\EditLockType
  • WPGraphQL\Type\Enum\MediaItemStatusEnumType
  • WPGraphQL\Type\Enum\MimeTypeEnumType
  • WPGraphQL\Type\Enum\PostObjectFieldFormatEnumType
  • WPGraphQL\Type\Enum\PostStatusEnumType
  • WPGraphQL\Type\Enum\PostTypeEnumType
  • WPGraphQL\Type\Enum\RelationEnumType
  • WPGraphQL\Type\Enum\TaxonomyEnumType
  • WPGraphQL\Type\MediaItem\MediaItemType
  • WPGraphQL\Type\MediaItem\Mutation\MediaItemCreate
  • WPGraphQL\Type\MediaItem\Mutation\MediaItemDelete
  • WPGraphQL\Type\MediaItem\Mutation\MediaItemMutation
  • WPGraphQL\Type\MediaItem\Mutation\MediaItemUpdate
  • WPGraphQL\Type\Plugin\Connection\PluginConnectionDefinition
  • WPGraphQL\Type\Plugin\Connection\PluginConnectionResolver
  • WPGraphQL\Type\Plugin\PluginQuery
  • WPGraphQL\Type\Plugin\PluginType
  • WPGraphQL\Type\PostObject\Connection\PostObjectConnectionArgs
  • WPGraphQL\Type\PostObject\Connection\PostObjectConnectionArgsDateQuery
  • WPGraphQL\Type\PostObject\Connection\PostObjectConnectionDefinition
  • WPGraphQL\Type\PostObject\Connection\PostObjectConnectionResolver
  • WPGraphQL\Type\PostObject\Mutation\PostObjectCreate
  • WPGraphQL\Type\PostObject\Mutation\PostObjectDelete
  • WPGraphQL\Type\PostObject\Mutation\PostObjectMutation
  • WPGraphQL\Type\PostObject\Mutation\PostObjectUpdate
  • WPGraphQL\Type\PostObject\Mutation\TermObjectDelete
  • WPGraphQL\Type\PostObject\PostObjectQuery
  • WPGraphQL\Type\PostObject\PostObjectType
  • WPGraphQL\Type\PostType\PostTypeType
  • WPGraphQL\Type\RootMutationType
  • WPGraphQL\Type\RootQueryType
  • WPGraphQL\Type\Setting\SettingQuery
  • WPGraphQL\Type\Setting\SettingType
  • WPGraphQL\Type\Taxonomy\TaxonomyType
  • WPGraphQL\Type\TermObject\Connection\TermObjectConnectionArgs
  • WPGraphQL\Type\TermObject\Connection\TermObjectConnectionDefinition
  • WPGraphQL\Type\TermObject\Connection\TermObjectConnectionResolver
  • WPGraphQL\Type\TermObject\Mutation\TermObjectCreate
  • WPGraphQL\Type\TermObject\Mutation\TermObjectMutation
  • WPGraphQL\Type\TermObject\Mutation\TermObjectUpdate
  • WPGraphQL\Type\TermObject\TermObjectQuery
  • WPGraphQL\Type\TermObject\TermObjectType
  • WPGraphQL\Type\Theme\Connection\ThemeConnectionDefinition
  • WPGraphQL\Type\Theme\Connection\ThemeConnectionResolver
  • WPGraphQL\Type\Theme\ThemeType
  • WPGraphQL\Type\Union\CommentAuthorUnionType
  • WPGraphQL\Type\Union\PostObjectUnionType
  • WPGraphQL\Type\Union\TermObjectUnionType
  • WPGraphQL\Type\User\Connection\UserConnectionArgs
  • WPGraphQL\Type\User\Connection\UserConnectionDefinition
  • WPGraphQL\Type\User\Connection\UserConnectionResolver
  • WPGraphQL\Type\User\Mutation\UserCreate
  • WPGraphQL\Type\User\Mutation\UserDelete
  • WPGraphQL\Type\User\Mutation\UserMutation
  • WPGraphQL\Type\User\Mutation\UserUpdate
  • WPGraphQL\Type\User\UserQuery
  • WPGraphQL\Type\User\UserType
  • WPGraphQL\Type\WPEnumType
  • WPGraphQL\Type\WPInputObjectType
  • WPGraphQL\Type\WPObjectType
  • WPGraphQL\Types
  • WPGraphQL\Utils\InstrumentSchema
  • WPGraphQL\WPSchema

Interfaces

  • WPGraphQL\Data\ConnectionResolverInterface
  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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 
<?php
namespace WPGraphQL\Data;

use GraphQL\Deferred;
use GraphQL\Error\UserError;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Relay;

use WPGraphQL\AppContext;
use WPGraphQL\Type\TermObject\Connection\TermObjectConnectionResolver;
use WPGraphQL\Type\Comment\Connection\CommentConnectionResolver;
use WPGraphQL\Type\Plugin\Connection\PluginConnectionResolver;
use WPGraphQL\Type\PostObject\Connection\PostObjectConnectionResolver;
use WPGraphQL\Type\Theme\Connection\ThemeConnectionResolver;
use WPGraphQL\Type\User\Connection\UserConnectionResolver;
use WPGraphQL\Types;

/**
 * Class DataSource
 *
 * This class serves as a factory for all the resolvers for queries and mutations. This layer of
 * abstraction over the actual resolve functions allows easier, granular control over versioning as
 * we can change big things behind the scenes if/when needed, and we just need to ensure the
 * call to the DataSource method returns the expected data later on. This should make it easy
 * down the road to version resolvers if/when changes to the WordPress API are rolled out.
 *
 * @package WPGraphQL\Data
 * @since   0.0.4
 */
class DataSource {

    /**
     * Stores an array of node definitions
     *
     * @var array $node_definition
     * @since  0.0.4
     * @access protected
     */
    protected static $node_definition;

    /**
     * Stores an array of setting types that exist in
     * get_registered_settings. In order to register a
     * setting with register_setting it must be categorized
     * under one of the whitelisted group names
     * See: https://developer.wordpress.org/reference/functions/register_setting/
     *
     * @var array $allowed_setting_types
     * @access protected
     */
    protected static $allowed_setting_types;

    /**
     * Stores an array of allowed setting groups.
     *
     * @var array $allowed_setting_groups
     * @access protected
     */
    protected static $allowed_setting_groups;

    /**
     * Retrieves a WP_Comment object for the id that gets passed
     *
     * @param int $id ID of the comment we want to get the object for
     *
     * @return \WP_Comment object
     * @throws UserError
     * @since  0.0.5
     * @access public
     */
    public static function resolve_comment( $id ) {

        $comment = \WP_Comment::get_instance( $id );
        if ( empty( $comment ) ) {
            throw new UserError( sprintf( __( 'No comment was found with ID %d', 'wp-graphql' ), absint( $id ) ) );
        }

        return $comment;

    }

    /**
     * Retrieves a WP_Comment object for the ID that gets passed
     *
     * @param string $author_email The ID of the comment the comment author is associated with.
     *
     * @return array
     * @throws
     */
    public static function resolve_comment_author( $author_email ) {
        global $wpdb;
        $comment_author = $wpdb->get_row( $wpdb->prepare( "SELECT comment_author_email, comment_author, comment_author_url, comment_author_email from $wpdb->comments WHERE comment_author_email = %s LIMIT 1", esc_sql( $author_email ) ) );
        $comment_author = ! empty( $comment_author ) ? ( array ) $comment_author : [];
        $comment_author['is_comment_author'] = true;
        return $comment_author;
    }

    /**
     * Wrapper for the CommentsConnectionResolver class
     *
     * @param             WP_Post  object $source
     * @param array       $args    Query args to pass to the connection resolver
     * @param AppContext  $context The context of the query to pass along
     * @param ResolveInfo $info    The ResolveInfo object
     *
     * @return mixed
     * @since 0.0.5
     */
    public static function resolve_comments_connection( $source, array $args, $context, ResolveInfo $info ) {
        $resolver = new CommentConnectionResolver();

        return $resolver->resolve( $source, $args, $context, $info );
    }

    /**
     * Returns an array of data about the plugin you are requesting
     *
     * @param string $name Name of the plugin you want info for
     *
     * @return null|array
     * @throws \Exception
     * @since  0.0.5
     * @access public
     */
    public static function resolve_plugin( $name ) {

        // Puts input into a url friendly slug format.
        $slug   = sanitize_title( $name );
        $plugin = null;

        // The file may have not been loaded yet.
        require_once ABSPATH . 'wp-admin/includes/plugin.php';

        /**
         * NOTE: This is missing must use and drop in plugins.
         */
        $plugins = apply_filters( 'all_plugins', get_plugins() );

        /**
         * Loop through the plugins and find the matching one
         *
         * @since 0.0.5
         */
        foreach ( $plugins as $path => $plugin_data ) {
            if ( sanitize_title( $plugin_data['Name'] ) === $slug ) {
                $plugin         = $plugin_data;
                $plugin['path'] = $path;
                // Exit early when plugin is found.
                break;
            }
        }

        /**
         * Return the plugin, or throw an exception
         */
        if ( ! empty( $plugin ) ) {
            return $plugin;
        } else {
            throw new UserError( sprintf( __( 'No plugin was found with the name %s', 'wp-graphql' ), $name ) );
        }
    }

    /**
     * Wrapper for PluginsConnectionResolver::resolve
     *
     * @param \WP_Post    $source  WP_Post object
     * @param array       $args    Array of arguments to pass to reolve method
     * @param AppContext  $context AppContext object passed down
     * @param ResolveInfo $info    The ResolveInfo object
     *
     * @return array
     * @since  0.0.5
     * @access public
     */
    public static function resolve_plugins_connection( $source, array $args, AppContext $context, ResolveInfo $info ) {
        return PluginConnectionResolver::resolve( $source, $args, $context, $info );
    }

    /**
     * Returns the post object for the ID and post type passed
     *
     * @param int    $id        ID of the post you are trying to retrieve
     * @param string $post_type Post type the post is attached to
     *
     * @throws UserError
     * @since  0.0.5
     * @return \WP_Post
     * @access public
     */
    public static function resolve_post_object( $id, $post_type ) {

        $post_object = \WP_Post::get_instance( $id );
        if ( empty( $post_object ) ) {
            throw new UserError( sprintf( __( 'No %1$s was found with the ID: %2$s', 'wp-graphql' ), $id, $post_type ) );
        }

        /**
         * Set the resolving post to the global $post. That way any filters that
         * might be applied when resolving fields can rely on global post and
         * post data being set up.
         */
        $GLOBALS['post'] = $post_object;

        return $post_object;

    }

    /**
     * Wrapper for PostObjectsConnectionResolver
     *
     * @param string      $post_type Post type of the post we are trying to resolve
     * @param             $source
     * @param array       $args      Arguments to pass to the resolve method
     * @param AppContext  $context   AppContext object to pass down
     * @param ResolveInfo $info      The ResolveInfo object
     *
     * @return mixed
     * @since  0.0.5
     * @access public
     */
    public static function resolve_post_objects_connection( $source, array $args, AppContext $context, ResolveInfo $info, $post_type ) {
        $resolver = new PostObjectConnectionResolver( $post_type );

        return $resolver->resolve( $source, $args, $context, $info );
    }

    /**
     * Gets the post type object from the post type name
     *
     * @param string $post_type Name of the post type you want to retrieve the object for
     *
     * @return \WP_Post_Type object
     * @throws UserError
     * @since  0.0.5
     * @access public
     */
    public static function resolve_post_type( $post_type ) {

        /**
         * Get the allowed_post_types
         */
        $allowed_post_types = \WPGraphQL::get_allowed_post_types();

        /**
         * If the $post_type is one of the allowed_post_types
         */
        if ( in_array( $post_type, $allowed_post_types, true ) ) {
            return get_post_type_object( $post_type );
        } else {
            throw new UserError( sprintf( __( 'No post_type was found with the name %s', 'wp-graphql' ), $post_type ) );
        }

    }

    /**
     * Retrieves the taxonomy object for the name of the taxonomy passed
     *
     * @param string $taxonomy Name of the taxonomy you want to retrieve the taxonomy object for
     *
     * @return \WP_Taxonomy object
     * @throws UserError
     * @since  0.0.5
     * @access public
     */
    public static function resolve_taxonomy( $taxonomy ) {

        /**
         * Get the allowed_taxonomies
         */
        $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies();

        /**
         * If the $post_type is one of the allowed_post_types
         */
        if ( in_array( $taxonomy, $allowed_taxonomies, true ) ) {
            return get_taxonomy( $taxonomy );
        } else {
            throw new UserError( sprintf( __( 'No taxonomy was found with the name %s', 'wp-graphql' ), $taxonomy ) );
        }

    }

    /**
     * Get the term object for a term
     *
     * @param int    $id       ID of the term you are trying to retrieve the object for
     * @param string $taxonomy Name of the taxonomy the term is in
     *
     * @return mixed
     * @throws UserError
     * @since  0.0.5
     * @access public
     */
    public static function resolve_term_object( $id, $taxonomy ) {

        $term_object = \WP_Term::get_instance( $id, $taxonomy );
        if ( empty( $term_object ) ) {
            throw new UserError( sprintf( __( 'No %1$s was found with the ID: %2$s', 'wp-graphql' ), $taxonomy, $id ) );
        }

        return $term_object;

    }

    /**
     * Wrapper for TermObjectConnectionResolver::resolve
     *
     * @param              $source
     * @param array        $args     Array of args to be passed to the resolve method
     * @param AppContext   $context  The AppContext object to be passed down
     * @param ResolveInfo  $info     The ResolveInfo object
     * @param \WP_Taxonomy $taxonomy The WP_Taxonomy object of the taxonomy the term is connected to
     *
     * @return array
     * @since  0.0.5
     * @access public
     */
    public static function resolve_term_objects_connection( $source, array $args, $context, ResolveInfo $info, $taxonomy ) {
        $resolver = new TermObjectConnectionResolver( $taxonomy );

        return $resolver->resolve( $source, $args, $context, $info );
    }

    /**
     * Retrieves the theme object for the theme you are looking for
     *
     * @param string $stylesheet Directory name for the theme.
     *
     * @return \WP_Theme object
     * @throws UserError
     * @since  0.0.5
     * @access public
     */
    public static function resolve_theme( $stylesheet ) {
        $theme = wp_get_theme( $stylesheet );
        if ( $theme->exists() ) {
            return $theme;
        } else {
            throw new UserError( sprintf( __( 'No theme was found with the stylesheet: %s', 'wp-graphql' ), $stylesheet ) );
        }
    }

    /**
     * Wrapper for the ThemesConnectionResolver::resolve method
     *
     * @param             $source
     * @param array       $args    Passes an array of arguments to the resolve method
     * @param AppContext  $context The AppContext object to be passed down
     * @param ResolveInfo $info    The ResolveInfo object
     *
     * @return array
     * @since  0.0.5
     * @access public
     */
    public static function resolve_themes_connection( $source, array $args, $context, ResolveInfo $info ) {
        return ThemeConnectionResolver::resolve( $source, $args, $context, $info );
    }

    /**
     * Gets the user object for the user ID specified
     *
     * @param int $id ID of the user you want the object for
     *
     * @return Deferred
     * @since  0.0.5
     * @access public
     */
    public static function resolve_user( $id ) {

        Loader::addOne( 'user', $id );
        $loader = function() use ( $id ) {
            Loader::loadBuffered( 'user' );
            return Loader::loadOne( 'user', $id );
        };
        return new Deferred( $loader );
    }

    /**
     * Wrapper for the UsersConnectionResolver::resolve method
     *
     * @param             $source
     * @param array       $args    Array of args to be passed down to the resolve method
     * @param AppContext  $context The AppContext object to be passed down
     * @param ResolveInfo $info    The ResolveInfo object
     *
     * @return array
     * @since  0.0.5
     * @access public
     */
    public static function resolve_users_connection( $source, array $args, $context, ResolveInfo $info ) {
        return UserConnectionResolver::resolve( $source, $args, $context, $info );
    }

    /**
     * Get all of the registered settings in a
     * WP site and return the ones that match the
     * name of the $setting_type
     *
     * @access public
     * @param string $group
     *
     * @return array $fields
     */
    public static function get_setting_group_fields( $group ) {

        /**
         * Get all of the registered settings and define the setting_type_array
         * for storing the settings that match the given setting type (general, discussion, etc)
         * before we return them
         */
        $setting_groups = self::get_allowed_setting_types();

        return ! empty( $setting_groups[ $group ] ) ? $setting_groups[ $group ] : [];

    }

    /**
     * Get the $allowed_setting_types and filter them
     * so that they can be further whitelisted. This method is
     * used to build out the root query fields for the various
     * setting types
     *
     * @access public
     * @return array $allowed_setting_types
     */
    public static function get_allowed_setting_types() {

        /**
         * Get all registered settings
         */
        $registered_settings = get_registered_settings();

        /**
         * Loop through the $registered_settings array and build a list of
         * the setting_types ( general, reading, discussion, writing, reading, etc. )
         */
        foreach ( $registered_settings as $key => $setting ) {
            if ( ! isset( $setting['show_in_graphql'] ) ) {
                if ( isset( $setting['show_in_rest'] ) && false !== $setting['show_in_rest'] ) {
                    $setting['key'] = $key;
                    self::$allowed_setting_types[ $setting['group'] ][ $key ] = $setting;
                }
            } else if ( true === $setting['show_in_graphql'] ) {
                $setting['key'] = $key;
                self::$allowed_setting_types[ $setting['group'] ][ $key ] = $setting;
            }
        };

        /**
         * Set the Setting Groups that are allowed
         */
        self::$allowed_setting_groups = ! empty( self::$allowed_setting_types ) && is_array( self::$allowed_setting_types ) ? array_keys( self::$allowed_setting_types ) : [];
        self::$allowed_setting_types = ! empty( self::$allowed_setting_types ) && is_array( self::$allowed_setting_types ) ? self::$allowed_setting_types : [];

        /**
         * Filter the $registered_setting_types to allow some to be enabled or disabled from showing in
         * the GraphQL Schema.
         *
         * @param array $registered_setting_types
         *
         * @return array
         */
        self::$allowed_setting_types = apply_filters( 'graphql_allowed_setting_groups', self::$allowed_setting_types, $registered_settings );

        return self::$allowed_setting_types;

    }

    /**
     * We get the node interface and field from the relay library.
     *
     * The first method is the way we resolve an ID to its object. The second is the way we resolve
     * an object that implements node to its type.
     *
     * @return array
     * @throws UserError
     * @access public
     */
    public static function get_node_definition() {

        if ( null === self::$node_definition ) {

            $node_definition = Relay::nodeDefinitions(

            // The ID fetcher definition
                function( $global_id ) {

                    if ( empty( $global_id ) ) {
                        throw new UserError( __( 'An ID needs to be provided to resolve a node.', 'wp-graphql' ) );
                    }

                    /**
                     * Convert the encoded ID into an array we can work with
                     *
                     * @since 0.0.4
                     */
                    $id_components = Relay::fromGlobalId( $global_id );

                    /**
                     * If the $id_components is a proper array with a type and id
                     *
                     * @since 0.0.5
                     */
                    if ( is_array( $id_components ) && ! empty( $id_components['id'] ) && ! empty( $id_components['type'] ) ) {

                        /**
                         * Get the allowed_post_types and allowed_taxonomies
                         *
                         * @since 0.0.5
                         */
                        $allowed_post_types = \WPGraphQL::get_allowed_post_types();
                        $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies();

                        switch ( $id_components['type'] ) {
                            case in_array( $id_components['type'], $allowed_post_types, true ):
                                $node = self::resolve_post_object( $id_components['id'], $id_components['type'] );
                                break;
                            case in_array( $id_components['type'], $allowed_taxonomies, true ):
                                $node = self::resolve_term_object( $id_components['id'], $id_components['type'] );
                                break;
                            case 'comment':
                                $node = self::resolve_comment( $id_components['id'] );
                                break;
                            case 'commentAuthor':
                                $node = self::resolve_comment_author( $id_components['id'] );
                                break;
                            case 'plugin':
                                $node = self::resolve_plugin( $id_components['id'] );
                                break;
                            case 'postType':
                                $node = self::resolve_post_type( $id_components['id'] );
                                break;
                            case 'taxonomy':
                                $node = self::resolve_taxonomy( $id_components['id'] );
                                break;
                            case 'theme':
                                $node = self::resolve_theme( $id_components['id'] );
                                break;
                            case 'user':
                                $node = self::resolve_user( $id_components['id'] );
                                break;
                            default:
                                /**
                                 * Add a filter to allow externally registered node types to resolve based on
                                 * the id_components
                                 *
                                 * @param int    $id   The id of the node, from the global ID
                                 * @param string $type The type of node to resolve, from the global ID
                                 *
                                 * @since 0.0.6
                                 */
                                $node = apply_filters( 'graphql_resolve_node', null, $id_components['id'], $id_components['type'] );
                                break;

                        }

                        /**
                         * If the $node is not properly resolved, throw an exception
                         *
                         * @since 0.0.6
                         */
                        if ( null === $node ) {
                            throw new UserError( sprintf( __( 'No node could be found with global ID: %s', 'wp-graphql' ), $global_id ) );
                        }

                        /**
                         * Return the resolved $node
                         *
                         * @since 0.0.5
                         */
                        return $node;

                    } else {
                        throw new UserError( sprintf( __( 'The global ID isn\'t recognized ID: %s', 'wp-graphql' ), $global_id ) );
                    }
                },

                // Type resolver
                function( $node ) {

                    if ( true === is_object( $node ) ) {

                        switch ( true ) {
                            case $node instanceof \WP_Post:
                                $type = Types::post_object( $node->post_type );
                                break;
                            case $node instanceof \WP_Term:
                                $type = Types::term_object( $node->taxonomy );
                                break;
                            case $node instanceof \WP_Comment:
                                $type = Types::comment();
                                break;
                            case $node instanceof \WP_Post_Type:
                                $type = Types::post_type();
                                break;
                            case $node instanceof \WP_Taxonomy:
                                $type = Types::taxonomy();
                                break;
                            case $node instanceof \WP_Theme:
                                $type = Types::theme();
                                break;
                            case $node instanceof \WP_User:
                                $type = Types::user();
                                break;
                            default:
                                $type = null;
                        }

                        // Some nodes might return an array instead of an object
                    } elseif ( is_array( $node )  ) {

                        switch ( $node ) {
                            case array_key_exists( 'PluginURI', $node ):
                                $type = Types::plugin();
                                break;
                            case array_key_exists( 'is_comment_author', $node ):
                                $type = Types::comment_author();
                                break;
                            default:
                                $type = null;
                        }
                    }

                    /**
                     * Add a filter to allow externally registered node types to return the proper type
                     * based on the node_object that's returned
                     *
                     * @param mixed|object|array $type The type definition the node should resolve to.
                     * @param mixed|object|array $node The $node that is being resolved
                     *
                     * @since 0.0.6
                     */
                    $type = apply_filters( 'graphql_resolve_node_type', $type, $node );

                    /**
                     * If the $type is not properly resolved, throw an exception
                     *
                     * @since 0.0.6
                     */
                    if ( null === $type ) {
                        throw new UserError( __( 'No type was found matching the node', 'wp-graphql' ) );
                    }

                    /**
                     * Return the resolved $type for the $node
                     *
                     * @since 0.0.5
                     */
                    return $type;

                }
            );

            self::$node_definition = $node_definition;

        }

        return self::$node_definition;
    }

    /**
     * Cached version of get_page_by_path so that we're not making unnecessary SQL all the time
     *
     * This is a modified version of the cached function from WordPress.com VIP MU Plugins here.
     *
     * @param string $uri
     * @param string $output Optional. Output type; OBJECT*, ARRAY_N, or ARRAY_A.
     * @param string $post_type Optional. Post type; default is 'post'.
     * @return WP_Post|null WP_Post on success or null on failure
     * @see https://github.com/Automattic/vip-go-mu-plugins/blob/52549ae9a392fc1343b7ac9dba4ebcdca46e7d55/vip-helpers/vip-caching.php#L186
     * @link http://vip.wordpress.com/documentation/uncached-functions/ Uncached Functions
     */
    public static function get_post_object_by_uri( $uri, $output = OBJECT, $post_type = 'post' ) {

        if ( is_array( $post_type ) ) {
            $cache_key = sanitize_key( $uri ) . '_' . md5( serialize( $post_type ) );
        } else {
            $cache_key = $post_type . '_' . sanitize_key( $uri );
        }
        $post_id = wp_cache_get( $cache_key, 'get_post_object_by_path' );

        if ( false === $post_id ) {
            $post = get_page_by_path( $uri, $output, $post_type );
            $post_id = $post ? $post->ID : 0;
            if ( 0 === $post_id ) {
                wp_cache_set( $cache_key, $post_id, 'get_post_object_by_path', ( 1 * HOUR_IN_SECONDS + mt_rand( 0, HOUR_IN_SECONDS ) ) ); // We only store the ID to keep our footprint small
            } else {
                wp_cache_set( $cache_key, $post_id, 'get_post_object_by_path', 0 ); // We only store the ID to keep our footprint small
            }
        }
        if ( $post_id ) {
            return get_post( $post_id, $output );
        }
        return null;

    }
}
API documentation generated by ApiGen