11/*
2- * Copyright 2002-2023 the original author or authors.
2+ * Copyright 2002-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -51,6 +51,8 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService {
5151
5252 private final List <DataLoaderRegistrar > dataLoaderRegistrars = new ArrayList <>();
5353
54+ private boolean hasDataLoaderRegistrations ;
55+
5456 private final boolean isDefaultExecutionIdProvider ;
5557
5658
@@ -68,6 +70,13 @@ public DefaultExecutionGraphQlService(GraphQlSource graphQlSource) {
6870 */
6971 public void addDataLoaderRegistrar (DataLoaderRegistrar registrar ) {
7072 this .dataLoaderRegistrars .add (registrar );
73+ this .hasDataLoaderRegistrations = (this .hasDataLoaderRegistrations || hasRegistrations (registrar ));
74+ }
75+
76+ private static boolean hasRegistrations (DataLoaderRegistrar registrar ) {
77+ DataLoaderRegistry registry = DataLoaderRegistry .newRegistry ().build ();
78+ registrar .registerDataLoaders (registry , GraphQLContext .newContext ().build ());
79+ return !registry .getDataLoaders ().isEmpty ();
7180 }
7281
7382
@@ -87,7 +96,7 @@ public final Mono<ExecutionGraphQlResponse> execute(ExecutionGraphQlRequest requ
8796 }
8897
8998 private ExecutionInput registerDataLoaders (ExecutionInput executionInput ) {
90- if (! this .dataLoaderRegistrars . isEmpty () ) {
99+ if (this .hasDataLoaderRegistrations ) {
91100 GraphQLContext graphQLContext = executionInput .getGraphQLContext ();
92101 DataLoaderRegistry existingRegistry = executionInput .getDataLoaderRegistry ();
93102 if (existingRegistry == DataLoaderDispatcherInstrumentationState .EMPTY_DATALOADER_REGISTRY ) {
0 commit comments