You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2026/09/30 14:47:44 UTC
(grails-core) 02/06: Deduplicate the log-if-prevented logic shared by the interceptor invokers
This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch refactor/graphql-fetcher
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit ad02f582388afeed4693901dbc2fba1f2827e7b0
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sat Aug 22 21:47:49 2026 -0500
Deduplicate the log-if-prevented logic shared by the interceptor invokers
CustomInterceptorInvoker#invoke and ProvidedInterceptorInvoker#invoke
were identical 9-line fragments: resolve the operation name, run the
subclass-specific invocation, log when it returns false, return the
result. Extract the shared name/log/return steps into a
logIfPrevented(name, result) template method on the common
InterceptorInvoker base (which now carries the @Slf4j/@CompileStatic
annotations instead of each sibling declaring its own logger), and
have both invoke() overrides call it. Behavior is unchanged; the
existing Query/Mutation/CustomQuery/CustomMutation InterceptorInvoker
specs already cover both the allowed and prevented-by-interceptor
branches.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../interceptor/CustomInterceptorInvoker.groovy | 8 +-------
.../fetcher/interceptor/InterceptorInvoker.groovy | 19 +++++++++++++++++++
.../interceptor/ProvidedInterceptorInvoker.groovy | 9 +--------
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy
index 4f44b4fb87..5e4196d45c 100644
--- a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy
+++ b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy
@@ -21,7 +21,6 @@ package org.grails.gorm.graphql.fetcher.interceptor
import graphql.schema.DataFetchingEnvironment
import groovy.transform.CompileStatic
-import groovy.util.logging.Slf4j
import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType
import org.grails.gorm.graphql.interceptor.GraphQLFetcherInterceptor
@@ -32,17 +31,12 @@ import org.grails.gorm.graphql.interceptor.GraphQLFetcherInterceptor
* @since 1.0.0
*/
@CompileStatic
-@Slf4j
abstract class CustomInterceptorInvoker extends InterceptorInvoker {
@Override
final boolean invoke(GraphQLFetcherInterceptor interceptor, DataFetchingEnvironment environment, GraphQLDataFetcherType type) {
final String name = getName(environment)
- boolean result = invoke(interceptor, name, environment)
- if (!result) {
- log.info("Execution of ${name} was prevented by an interceptor")
- }
- result
+ logIfPrevented(name, invoke(interceptor, name, environment))
}
abstract boolean invoke(GraphQLFetcherInterceptor interceptor, String name, DataFetchingEnvironment environment)
diff --git a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/InterceptorInvoker.groovy b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/InterceptorInvoker.groovy
index a7f0ce9303..08ed2f810a 100644
--- a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/InterceptorInvoker.groovy
+++ b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/InterceptorInvoker.groovy
@@ -20,6 +20,8 @@
package org.grails.gorm.graphql.fetcher.interceptor
import graphql.schema.DataFetchingEnvironment
+import groovy.transform.CompileStatic
+import groovy.util.logging.Slf4j
import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType
import org.grails.gorm.graphql.interceptor.GraphQLFetcherInterceptor
@@ -30,11 +32,28 @@ import org.grails.gorm.graphql.interceptor.GraphQLFetcherInterceptor
* @author James Kleeh
* @since 1.0.0
*/
+@CompileStatic
+@Slf4j
abstract class InterceptorInvoker {
protected String getName(DataFetchingEnvironment environment) {
environment.fields.empty ? 'UNKNOWN' : environment.fields[0].name
}
+ /**
+ * Logs when an interceptor prevents execution, shared by every
+ * {@link #invoke} implementation.
+ *
+ * @param name The name used to identify the operation in the log message
+ * @param result Whether the interceptor allowed execution to proceed
+ * @return {@code result}, unchanged
+ */
+ protected final boolean logIfPrevented(String name, boolean result) {
+ if (!result) {
+ log.info("Execution of ${name} was prevented by an interceptor")
+ }
+ result
+ }
+
abstract boolean invoke(GraphQLFetcherInterceptor interceptor, DataFetchingEnvironment environment, GraphQLDataFetcherType type)
}
diff --git a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy
index c56cdc3f4a..6bb0dc1c2e 100644
--- a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy
+++ b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy
@@ -21,7 +21,6 @@ package org.grails.gorm.graphql.fetcher.interceptor
import graphql.schema.DataFetchingEnvironment
import groovy.transform.CompileStatic
-import groovy.util.logging.Slf4j
import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType
import org.grails.gorm.graphql.interceptor.GraphQLFetcherInterceptor
@@ -32,17 +31,11 @@ import org.grails.gorm.graphql.interceptor.GraphQLFetcherInterceptor
* @since 1.0.0
*/
@CompileStatic
-@Slf4j
abstract class ProvidedInterceptorInvoker extends InterceptorInvoker {
@Override
final boolean invoke(GraphQLFetcherInterceptor interceptor, DataFetchingEnvironment environment, GraphQLDataFetcherType type) {
- final String name = getName(environment)
- boolean result = call(interceptor, environment, type)
- if (!result) {
- log.info("Execution of ${name} was prevented by an interceptor")
- }
- result
+ logIfPrevented(getName(environment), call(interceptor, environment, type))
}
abstract boolean call(GraphQLFetcherInterceptor interceptor, DataFetchingEnvironment environment, GraphQLDataFetcherType type)