From f17938e41e72f988c8de4c1414ca49eedcbedee6 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 15 Apr 2024 07:11:50 +0100 Subject: [PATCH] Polishing --- .../ConnectionFieldTypeVisitor.java | 4 +- .../execution/DefaultTypeVisitorHelper.java | 54 ------------------- .../graphql/execution/TypeVisitorHelper.java | 13 +++-- 3 files changed, 9 insertions(+), 62 deletions(-) delete mode 100644 spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java index 3644510a..464f8e7d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java @@ -110,7 +110,9 @@ public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub { return TraversalControl.CONTINUE; } - private static boolean isUnderSubscriptionOperation(TypeVisitorHelper visitorHelper, TraverserContext context) { + private static boolean isUnderSubscriptionOperation( + TypeVisitorHelper visitorHelper, TraverserContext context) { + return context.getBreadcrumbs().stream() .filter(GraphQLFieldsContainer.class::isInstance) .map(GraphQLFieldsContainer.class::cast) diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java deleted file mode 100644 index 46c1a5ec..00000000 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.graphql.execution; - -import graphql.schema.GraphQLNamedType; -import graphql.schema.GraphQLObjectType; -import graphql.schema.GraphQLSchema; - -import org.springframework.lang.Nullable; - -/** - * Default implementation of {@link TypeVisitorHelper} that performs checks - * against {@link GraphQLSchema}. - * - * @author Rossen Stoyanchev - */ -final class DefaultTypeVisitorHelper implements TypeVisitorHelper { - - @Nullable - private final String subscriptionTypeName; - - - /** - * Package private constructor. - */ - DefaultTypeVisitorHelper(GraphQLSchema schema) { - GraphQLObjectType subscriptionType = schema.getSubscriptionType(); - this.subscriptionTypeName = (subscriptionType != null) ? subscriptionType.getName() : null; - } - - - /** - * Whether the given type is the subscription type. - */ - @Override - public boolean isSubscriptionType(GraphQLNamedType type) { - return (type.getName().equals(this.subscriptionTypeName)); - } - -} diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java index b02be750..b451e921 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -16,15 +16,13 @@ package org.springframework.graphql.execution; -import java.util.List; - import graphql.schema.GraphQLNamedType; import graphql.schema.GraphQLSchema; /** - * Helper for {@link graphql.schema.GraphQLTypeVisitor}s registered via - * {@link GraphQlSource.Builder#typeVisitors(List)} that is exposed as a - * variable in {@link graphql.util.TraverserContext}. + * Helps {@link graphql.schema.GraphQLTypeVisitor}s to recognize whether a type + * is the subscription type. Exposed as a variable in + * {@link graphql.util.TraverserContext}. * * @author Rossen Stoyanchev * @since 1.2.1 @@ -43,7 +41,8 @@ public interface TypeVisitorHelper { * @param schema the GraphQL schema to use */ static TypeVisitorHelper create(GraphQLSchema schema) { - return new DefaultTypeVisitorHelper(schema); + String name = (schema.getSubscriptionType() != null) ? schema.getSubscriptionType().getName() : null; + return (candidate) -> candidate.getName().equals(name); } }