11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2023 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.
2424import graphql .schema .GraphQLCodeRegistry ;
2525import graphql .schema .GraphQLFieldDefinition ;
2626import graphql .schema .GraphQLFieldsContainer ;
27+ import graphql .schema .GraphQLObjectType ;
28+ import graphql .schema .GraphQLSchema ;
2729import graphql .schema .GraphQLSchemaElement ;
2830import graphql .schema .GraphQLTypeVisitor ;
2931import graphql .schema .GraphQLTypeVisitorStub ;
@@ -103,9 +105,13 @@ public Object get(DataFetchingEnvironment environment) throws Exception {
103105 * Static factory method to create {@link GraphQLTypeVisitor} that wraps
104106 * data fetchers with the {@link ContextDataFetcherDecorator}.
105107 */
106- static GraphQLTypeVisitor createVisitor (List <SubscriptionExceptionResolver > resolvers ) {
108+ static GraphQLTypeVisitor createVisitor (
109+ GraphQLSchema schema , List <SubscriptionExceptionResolver > resolvers ) {
107110
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 );
109115
110116 return new GraphQLTypeVisitorStub () {
111117 @ Override
@@ -117,8 +123,8 @@ public TraversalControl visitGraphQLFieldDefinition(
117123 DataFetcher <?> dataFetcher = codeRegistry .getDataFetcher (parent , fieldDefinition );
118124
119125 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 );
122128 codeRegistry .dataFetcher (parent , fieldDefinition , dataFetcher );
123129 }
124130
0 commit comments