ID ) { return false; } return true; } /** * @param ValidationContext $context * * @return callable[]|mixed[] */ public function getVisitor( ValidationContext $context ) { $allowed_root_fields = []; /** * Filters the allowed * * @param array $allowed_root_fields The Root fields allowed to be requested without authentication * @param AppContext $context The AppContext of the field being executed. */ $allowed_root_fields = apply_filters( 'graphql_require_authentication_allowed_fields', $allowed_root_fields, $context ); return $this->invokeIfNeeded( $context, [ NodeKind::FIELD => static function ( FieldNode $node ) use ( $context, $allowed_root_fields ) { $parent_type = $context->getParentType(); if ( ! $parent_type instanceof Type || empty( $parent_type->name ) ) { return; } if ( ! in_array( $parent_type->name, [ 'RootQuery', 'RootSubscription', 'RootMutation' ], true ) ) { return; } if ( empty( $allowed_root_fields ) || ! is_array( $allowed_root_fields ) || ! in_array( $node->name->value, $allowed_root_fields, true ) ) { $context->reportError( new Error( sprintf( __( 'The field "%s" cannot be accessed without authentication.', 'wp-graphql' ), $context->getParentType() . '.' . $node->name->value ), //@phpstan-ignore-next-line [ $node ] ) ); } }, ] ); } }