Skip to content

Commit 890ecb9

Browse files
committed
Added SeedQuery check for Faust.
1 parent c61606e commit 890ecb9

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

plugins/wpgraphql-logging/src/Logger/LoggingHelper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use WPGraphQL\Logging\Logger\Rules\QueryNullRule;
1212
use WPGraphQL\Logging\Logger\Rules\RuleManager;
1313
use WPGraphQL\Logging\Logger\Rules\SamplingRateRule;
14+
use WPGraphQL\Logging\Logger\Rules\SeedQueryRule;
1415

1516
/**
1617
* Trait for shared logging helper methods.
@@ -41,6 +42,7 @@ protected function get_rule_manager(): RuleManager {
4142
$this->rule_manager->add_rule( new AdminUserRule() );
4243
$this->rule_manager->add_rule( new IpRestrictionsRule() );
4344
$this->rule_manager->add_rule( new IntrospectionQueryRule() );
45+
$this->rule_manager->add_rule( new SeedQueryRule() );
4446
apply_filters( 'wpgraphql_logging_rule_manager', $this->rule_manager );
4547
return $this->rule_manager;
4648
}
@@ -53,10 +55,6 @@ protected function get_rule_manager(): RuleManager {
5355
protected function is_logging_enabled( array $config, ?string $query_string = null ): bool {
5456

5557
$is_enabled = $this->get_rule_manager()->all_rules_pass( $config, $query_string );
56-
wp_send_json_error( [
57-
'is_enabled' => $is_enabled,
58-
'query_string' => $query_string,
59-
], 200 );
6058

6159
/**
6260
* Filter the final decision on whether to log a request.

plugins/wpgraphql-logging/src/Logger/Rules/IntrospectionQueryRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class IntrospectionQueryRule implements LoggingRuleInterface {
2121
* @return bool True if the rule passes (logging should continue).
2222
*/
2323
public function passes(array $config, ?string $query_string = null): bool {
24+
if ( null === $query_string ) {
25+
return true;
26+
}
2427
return strpos( $query_string, '__schema' ) === false;
2528
}
2629

plugins/wpgraphql-logging/src/Logger/Rules/IpRestrictionsRule.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public function passes(array $config, ?string $query_string = null): bool {
2929
return true;
3030
}
3131
$allowed_ips = array_map( 'trim', explode( ',', $ip_restrictions ) );
32-
if ( empty( $allowed_ips ) ) {
33-
return true;
34-
}
3532
if ( ! isset( $_SERVER['REMOTE_ADDR'] ) ) { // @phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders
3633
return false;
3734
}
@@ -47,6 +44,6 @@ public function passes(array $config, ?string $query_string = null): bool {
4744
* Get the rule name for debugging.
4845
*/
4946
public function get_name(): string {
50-
return 'ip_restrictions_rule';
47+
return 'ip_restrictions';
5148
}
5249
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WPGraphQL\Logging\Logger\Rules;
6+
7+
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\Basic_Configuration_Tab;
8+
9+
/**
10+
* Rule to check if the query is a Faust.js Seed Query.
11+
*
12+
* @package WPGraphQL\Logging
13+
*
14+
* @link https://github.com/wpengine/faustjs/blob/8e8797b1758d34d489236266e08f0657c015ff9f/packages/faustwp-core/src/queries/seedQuery.ts
15+
*
16+
* @since 0.0.1
17+
*/
18+
class SeedQueryRule implements LoggingRuleInterface {
19+
/**
20+
* Check if the rule passes.
21+
*
22+
* @param array<string, mixed> $config The logging configuration.
23+
* @param string|null $query_string The GraphQL query string.
24+
*
25+
* @return bool True if the rule passes (logging should continue).
26+
*/
27+
public function passes(array $config, ?string $query_string = null): bool {
28+
29+
if ( null === $query_string ) {
30+
return true;
31+
}
32+
33+
$allow_query = (bool) $config[ Basic_Configuration_Tab::SEED_QUERY ];
34+
if ( ! $allow_query ) {
35+
return true;
36+
}
37+
return stripos( $query_string, 'SeedNode' ) === false;
38+
}
39+
40+
/**
41+
* Get the rule name for debugging.
42+
*/
43+
public function get_name(): string {
44+
return 'faustjs_seed_query_rule';
45+
}
46+
}

0 commit comments

Comments
 (0)