Skip to content

Commit 1c7daf8

Browse files
committed
Added field to exclude queries rather than multiple rules.
1 parent ecafd46 commit 1c7daf8

File tree

4 files changed

+24
-61
lines changed

4 files changed

+24
-61
lines changed

plugins/wpgraphql-logging/src/Admin/Settings/Fields/Tab/Basic_Configuration_Tab.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class Basic_Configuration_Tab implements Settings_Tab_Interface {
5353
public const EVENT_LOG_SELECTION = 'event_log_selection';
5454

5555
/**
56-
* The field ID for the seed query exclusion for Faust.js.
56+
* The field ID for the exclude query text input.
5757
*
5858
* @var string
5959
*/
60-
public const SEED_QUERY = 'seed_query';
60+
public const EXCLUDE_QUERY = 'exclude_query';
6161

6262
/**
6363
* The field ID for whether to log the response from the WPGGraphQL query into the context object.
@@ -107,6 +107,15 @@ public function get_fields(): array {
107107
__( 'e.g., 192.168.1.1, 10.0.0.1', 'wpgraphql-logging' )
108108
);
109109

110+
$fields[ self::EXCLUDE_QUERY ] = new Text_Input_Field(
111+
self::EXCLUDE_QUERY,
112+
$this->get_name(),
113+
__( 'Exclude Query', 'wpgraphql-logging' ),
114+
'',
115+
__( 'Comma-separated list of GraphQL query names to exclude from logging.', 'wpgraphql-logging' ),
116+
__( 'e.g., __schema,SeedNode,__typename', 'wpgraphql-logging' )
117+
);
118+
110119
$fields[ self::ADMIN_USER_LOGGING ] = new Checkbox_Field(
111120
self::ADMIN_USER_LOGGING,
112121
$this->get_name(),
@@ -148,15 +157,6 @@ public function get_fields(): array {
148157
true
149158
);
150159

151-
152-
$fields[ self::SEED_QUERY ] = new Checkbox_Field(
153-
self::SEED_QUERY,
154-
$this->get_name(),
155-
__( 'Log Seed Query', 'wpgraphql-logging' ),
156-
'',
157-
__( 'Whether or not to log the Faust.js seed query.', 'wpgraphql-logging' ),
158-
);
159-
160160
$fields[ self::LOG_RESPONSE ] = new Checkbox_Field(
161161
self::LOG_RESPONSE,
162162
$this->get_name(),

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
use WPGraphQL\Logging\Logger\Rules\AdminUserRule;
88
use WPGraphQL\Logging\Logger\Rules\EnabledRule;
9-
use WPGraphQL\Logging\Logger\Rules\IntrospectionQueryRule;
9+
use WPGraphQL\Logging\Logger\Rules\ExcludeQueryRule;
1010
use WPGraphQL\Logging\Logger\Rules\IpRestrictionsRule;
1111
use WPGraphQL\Logging\Logger\Rules\LogResponseRule;
1212
use WPGraphQL\Logging\Logger\Rules\QueryNullRule;
1313
use WPGraphQL\Logging\Logger\Rules\RuleManager;
1414
use WPGraphQL\Logging\Logger\Rules\SamplingRateRule;
15-
use WPGraphQL\Logging\Logger\Rules\SeedQueryRule;
1615

1716
/**
1817
* Trait for shared logging helper methods.
@@ -54,8 +53,7 @@ protected function get_rule_manager(): RuleManager {
5453
$this->rule_manager->add_rule( new EnabledRule() );
5554
$this->rule_manager->add_rule( new AdminUserRule() );
5655
$this->rule_manager->add_rule( new IpRestrictionsRule() );
57-
$this->rule_manager->add_rule( new IntrospectionQueryRule() );
58-
$this->rule_manager->add_rule( new SeedQueryRule() );
56+
$this->rule_manager->add_rule( new ExcludeQueryRule() );
5957
apply_filters( 'wpgraphql_logging_rule_manager', $this->rule_manager );
6058
return $this->rule_manager;
6159
}

plugins/wpgraphql-logging/src/Logger/Rules/SeedQueryRule.php renamed to plugins/wpgraphql-logging/src/Logger/Rules/ExcludeQueryRule.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
use WPGraphQL\Logging\Admin\Settings\Fields\Tab\Basic_Configuration_Tab;
88

99
/**
10-
* Rule to check if the query is a Faust.js Seed Query.
10+
* Rule to check if the query is excluded from logging.
1111
*
1212
* @package WPGraphQL\Logging
1313
*
14-
* @link https://github.com/wpengine/faustjs/blob/8e8797b1758d34d489236266e08f0657c015ff9f/packages/faustwp-core/src/queries/seedQuery.ts
15-
*
1614
* @since 0.0.1
1715
*/
18-
class SeedQueryRule implements LoggingRuleInterface {
16+
class ExcludeQueryRule implements LoggingRuleInterface {
1917
/**
2018
* Check if the rule passes.
2119
*
@@ -25,22 +23,25 @@ class SeedQueryRule implements LoggingRuleInterface {
2523
* @return bool True if the rule passes (logging should continue).
2624
*/
2725
public function passes(array $config, ?string $query_string = null): bool {
28-
26+
$queries = $config[ Basic_Configuration_Tab::EXCLUDE_QUERY ] ?? '';
2927
if ( null === $query_string ) {
3028
return true;
3129
}
3230

33-
$allow_query = (bool) $config[ Basic_Configuration_Tab::SEED_QUERY ];
34-
if ( ! $allow_query ) {
35-
return true;
31+
$excluded_queries = array_map( 'trim', explode( ',', $queries ) );
32+
foreach ( $excluded_queries as $excluded_query ) {
33+
if ( stripos( $query_string, $excluded_query ) !== false ) {
34+
return false;
35+
}
3636
}
37-
return stripos( $query_string, 'SeedNode' ) === false;
37+
38+
return true;
3839
}
3940

4041
/**
4142
* Get the rule name for debugging.
4243
*/
4344
public function get_name(): string {
44-
return 'faustjs_seed_query_rule';
45+
return 'exclude_query_rule';
4546
}
4647
}

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

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)