1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -51,6 +51,8 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService {
51
51
52
52
private final List <DataLoaderRegistrar > dataLoaderRegistrars = new ArrayList <>();
53
53
54
+ private boolean hasDataLoaderRegistrations ;
55
+
54
56
private final boolean isDefaultExecutionIdProvider ;
55
57
56
58
@@ -68,6 +70,13 @@ public DefaultExecutionGraphQlService(GraphQlSource graphQlSource) {
68
70
*/
69
71
public void addDataLoaderRegistrar (DataLoaderRegistrar registrar ) {
70
72
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 ();
71
80
}
72
81
73
82
@@ -87,7 +96,7 @@ public final Mono<ExecutionGraphQlResponse> execute(ExecutionGraphQlRequest requ
87
96
}
88
97
89
98
private ExecutionInput registerDataLoaders (ExecutionInput executionInput ) {
90
- if (! this .dataLoaderRegistrars . isEmpty () ) {
99
+ if (this .hasDataLoaderRegistrations ) {
91
100
GraphQLContext graphQLContext = executionInput .getGraphQLContext ();
92
101
DataLoaderRegistry existingRegistry = executionInput .getDataLoaderRegistry ();
93
102
if (existingRegistry == DataLoaderDispatcherInstrumentationState .EMPTY_DATALOADER_REGISTRY ) {
0 commit comments