1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 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.
24
24
import graphql .schema .GraphQLCodeRegistry ;
25
25
import graphql .schema .GraphQLFieldDefinition ;
26
26
import graphql .schema .GraphQLFieldsContainer ;
27
+ import graphql .schema .GraphQLObjectType ;
28
+ import graphql .schema .GraphQLSchema ;
27
29
import graphql .schema .GraphQLSchemaElement ;
28
30
import graphql .schema .GraphQLTypeVisitor ;
29
31
import graphql .schema .GraphQLTypeVisitorStub ;
@@ -97,9 +99,13 @@ public Object get(DataFetchingEnvironment environment) throws Exception {
97
99
* Static factory method to create {@link GraphQLTypeVisitor} that wraps
98
100
* data fetchers with the {@link ContextDataFetcherDecorator}.
99
101
*/
100
- static GraphQLTypeVisitor createVisitor (List <SubscriptionExceptionResolver > resolvers ) {
102
+ static GraphQLTypeVisitor createVisitor (
103
+ GraphQLSchema schema , List <SubscriptionExceptionResolver > resolvers ) {
101
104
102
- SubscriptionExceptionResolver compositeResolver = new CompositeSubscriptionExceptionResolver (resolvers );
105
+ GraphQLObjectType subscriptionType = schema .getSubscriptionType ();
106
+ String subscriptionTypeName = (subscriptionType != null ? subscriptionType .getName () : null );
107
+
108
+ SubscriptionExceptionResolver exceptionResolver = new CompositeSubscriptionExceptionResolver (resolvers );
103
109
104
110
return new GraphQLTypeVisitorStub () {
105
111
@ Override
@@ -111,8 +117,8 @@ public TraversalControl visitGraphQLFieldDefinition(
111
117
DataFetcher <?> dataFetcher = codeRegistry .getDataFetcher (parent , fieldDefinition );
112
118
113
119
if (applyDecorator (dataFetcher )) {
114
- boolean handlesSubscription = parent .getName ().equals ("Subscription" );
115
- dataFetcher = new ContextDataFetcherDecorator (dataFetcher , handlesSubscription , compositeResolver );
120
+ boolean handlesSubscription = parent .getName ().equals (subscriptionTypeName );
121
+ dataFetcher = new ContextDataFetcherDecorator (dataFetcher , handlesSubscription , exceptionResolver );
116
122
codeRegistry .dataFetcher (parent , fieldDefinition , dataFetcher );
117
123
}
118
124
0 commit comments