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 ;
@@ -103,9 +105,13 @@ public Object get(DataFetchingEnvironment environment) throws Exception {
103
105
* Static factory method to create {@link GraphQLTypeVisitor} that wraps
104
106
* data fetchers with the {@link ContextDataFetcherDecorator}.
105
107
*/
106
- static GraphQLTypeVisitor createVisitor (List <SubscriptionExceptionResolver > resolvers ) {
108
+ static GraphQLTypeVisitor createVisitor (
109
+ GraphQLSchema schema , List <SubscriptionExceptionResolver > resolvers ) {
107
110
108
- SubscriptionExceptionResolver compositeResolver = new CompositeSubscriptionExceptionResolver (resolvers );
111
+ GraphQLObjectType subscriptionType = schema .getSubscriptionType ();
112
+ String subscriptionTypeName = (subscriptionType != null ? subscriptionType .getName () : null );
113
+
114
+ SubscriptionExceptionResolver exceptionResolver = new CompositeSubscriptionExceptionResolver (resolvers );
109
115
110
116
return new GraphQLTypeVisitorStub () {
111
117
@ Override
@@ -117,8 +123,8 @@ public TraversalControl visitGraphQLFieldDefinition(
117
123
DataFetcher <?> dataFetcher = codeRegistry .getDataFetcher (parent , fieldDefinition );
118
124
119
125
if (applyDecorator (dataFetcher )) {
120
- boolean handlesSubscription = parent .getName ().equals ("Subscription" );
121
- dataFetcher = new ContextDataFetcherDecorator (dataFetcher , handlesSubscription , compositeResolver );
126
+ boolean handlesSubscription = parent .getName ().equals (subscriptionTypeName );
127
+ dataFetcher = new ContextDataFetcherDecorator (dataFetcher , handlesSubscription , exceptionResolver );
122
128
codeRegistry .dataFetcher (parent , fieldDefinition , dataFetcher );
123
129
}
124
130
0 commit comments