HEX
Server: Apache/2.4.66 (Debian)
System: Linux 6dfabc3b2241 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User: (1000)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-graphql/src/Server/ValidationRules/DisableIntrospection.php
<?php

namespace WPGraphQL\Server\ValidationRules;

/**
 * Class DisableIntrospection
 *
 * @package WPGraphQL\Server\ValidationRules
 */
class DisableIntrospection extends \GraphQL\Validator\Rules\DisableIntrospection {

	/**
	 * DisableIntrospection constructor.
	 */
	public function __construct() {
		$should_be_enabled = $this->should_be_enabled();
		parent::__construct( $should_be_enabled ? self::ENABLED : self::DISABLED );
	}

	/**
	 * Determines whether the DisableIntrospection rule should be disabled.
	 */
	public function should_be_enabled(): bool {
		if ( ! get_current_user_id() && ! \WPGraphQL::debug() && 'off' === get_graphql_setting( 'public_introspection_enabled', 'off' ) ) {
			return true;
		}
		return false;
	}

	/**
	 * Returns a helpful message when introspection is disabled and an introspection query is attempted.
	 */
	public static function introspectionDisabledMessage(): string {
		return __( 'The query contained __schema or __type, however GraphQL introspection is not allowed for public requests by default. Public introspection can be enabled under the WPGraphQL Settings.', 'wp-graphql' );
	}
}