Support custom "subscription" type name
Closes gh-590
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -132,7 +132,7 @@ abstract class AbstractGraphQlSourceBuilder<B extends GraphQlSource.Builder<B>>
|
||||
}
|
||||
|
||||
private GraphQLSchema applyTypeVisitors(GraphQLSchema schema) {
|
||||
GraphQLTypeVisitor visitor = ContextDataFetcherDecorator.createVisitor(this.subscriptionExceptionResolvers);
|
||||
GraphQLTypeVisitor visitor = ContextDataFetcherDecorator.createVisitor(schema, this.subscriptionExceptionResolvers);
|
||||
List<GraphQLTypeVisitor> visitors = new ArrayList<>(this.typeVisitors);
|
||||
visitors.add(visitor);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,8 @@ import graphql.schema.DataFetchingEnvironment;
|
||||
import graphql.schema.GraphQLCodeRegistry;
|
||||
import graphql.schema.GraphQLFieldDefinition;
|
||||
import graphql.schema.GraphQLFieldsContainer;
|
||||
import graphql.schema.GraphQLObjectType;
|
||||
import graphql.schema.GraphQLSchema;
|
||||
import graphql.schema.GraphQLSchemaElement;
|
||||
import graphql.schema.GraphQLTypeVisitor;
|
||||
import graphql.schema.GraphQLTypeVisitorStub;
|
||||
@@ -97,9 +99,13 @@ final class ContextDataFetcherDecorator implements DataFetcher<Object> {
|
||||
* Static factory method to create {@link GraphQLTypeVisitor} that wraps
|
||||
* data fetchers with the {@link ContextDataFetcherDecorator}.
|
||||
*/
|
||||
static GraphQLTypeVisitor createVisitor(List<SubscriptionExceptionResolver> resolvers) {
|
||||
static GraphQLTypeVisitor createVisitor(
|
||||
GraphQLSchema schema, List<SubscriptionExceptionResolver> resolvers) {
|
||||
|
||||
SubscriptionExceptionResolver compositeResolver = new CompositeSubscriptionExceptionResolver(resolvers);
|
||||
GraphQLObjectType subscriptionType = schema.getSubscriptionType();
|
||||
String subscriptionTypeName = (subscriptionType != null ? subscriptionType.getName() : null);
|
||||
|
||||
SubscriptionExceptionResolver exceptionResolver = new CompositeSubscriptionExceptionResolver(resolvers);
|
||||
|
||||
return new GraphQLTypeVisitorStub() {
|
||||
@Override
|
||||
@@ -111,8 +117,8 @@ final class ContextDataFetcherDecorator implements DataFetcher<Object> {
|
||||
DataFetcher<?> dataFetcher = codeRegistry.getDataFetcher(parent, fieldDefinition);
|
||||
|
||||
if (applyDecorator(dataFetcher)) {
|
||||
boolean handlesSubscription = parent.getName().equals("Subscription");
|
||||
dataFetcher = new ContextDataFetcherDecorator(dataFetcher, handlesSubscription, compositeResolver);
|
||||
boolean handlesSubscription = parent.getName().equals(subscriptionTypeName);
|
||||
dataFetcher = new ContextDataFetcherDecorator(dataFetcher, handlesSubscription, exceptionResolver);
|
||||
codeRegistry.dataFetcher(parent, fieldDefinition, dataFetcher);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user