From 3e898f74fa16ce90fc32d8577a07f0d4528dedb0 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Sat, 30 Mar 2024 22:44:10 +0100 Subject: [PATCH] Remove APIs deprecated in 1.0.x Closes gh-941 --- .../graphql/ResponseField.java | 43 +------ .../client/DefaultClientResponseField.java | 14 +-- .../query/AutoRegistrationTypeVisitor.java | 111 ------------------ .../data/query/QueryByExampleDataFetcher.java | 40 ------- .../data/query/QuerydslDataFetcher.java | 45 ------- .../DataFetcherExceptionResolverAdapter.java | 20 ---- .../server/WebSocketGraphQlRequest.java | 2 +- .../webmvc/GraphQlWebSocketHandler.java | 2 +- .../support/AbstractGraphQlResponse.java | 23 +--- 9 files changed, 5 insertions(+), 295 deletions(-) delete mode 100644 spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java diff --git a/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java b/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java index 5f0b3e6f..45c20367 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -31,21 +31,6 @@ import org.springframework.lang.Nullable; */ public interface ResponseField { - /** - * Whether the field has a value. - * - * @deprecated as of 1.0.3 in favor of checking via {@link #getValue()} - */ - @Deprecated - boolean hasValue(); - /** * Return a String representation of the field path as described in * {@link ClientGraphQlResponse#field(String)}. @@ -67,32 +52,6 @@ public interface ResponseField { @Nullable T getValue(); - /** - * Return the error that provides the reason for a failed field. - *

When the field is {@code null}, this method looks for the first field - * error. According to the GraphQL spec, section 6.4.4, "Handling Field - * Errors", there should be only one error per field. The returned field - * error may be: - *

- *

As a fallback, this method also checks "request errors" in case the - * entire response is not {@link GraphQlResponse#isValid() valid}. If there - * are no errors at all, {@code null} is returned, and it implies the field - * value was set to {@code null} by its {@code DataFetcher}. - *

When the field does have a value, it is considered - * valid and this method returns {@code null}, although the field may be - * partial and contain {@link #getErrors() errors} on nested fields. - * @return return the error for this field, or {@code null} if there is no - * error with the same path as the field path - * @deprecated since 1.0.3 in favor of {@link #getErrors()} - */ - @Nullable - @Deprecated - ResponseError getError(); - /** * Return all errors that have a path, and it is at above, or below the field path. *

According to the GraphQL spec, section 6.4.4, "Handling Field Errors" diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java index 44646250..8cd78707 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -55,12 +55,6 @@ final class DefaultClientResponseField implements ClientResponseField { } - @SuppressWarnings("deprecation") - @Override - public boolean hasValue() { - return (this.field.getValue() != null); - } - @Override public String getPath() { return this.field.getPath(); @@ -76,12 +70,6 @@ final class DefaultClientResponseField implements ClientResponseField { return this.field.getValue(); } - @SuppressWarnings("deprecation") - @Override - public ResponseError getError() { - return this.field.getError(); - } - @Override public List getErrors() { return this.field.getErrors(); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java deleted file mode 100644 index a2d18ca4..00000000 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - * 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.data.query; - -import java.util.Map; -import java.util.function.Function; - -import graphql.schema.DataFetcher; -import graphql.schema.FieldCoordinates; -import graphql.schema.GraphQLCodeRegistry; -import graphql.schema.GraphQLFieldDefinition; -import graphql.schema.GraphQLFieldsContainer; -import graphql.schema.GraphQLList; -import graphql.schema.GraphQLNamedOutputType; -import graphql.schema.GraphQLSchemaElement; -import graphql.schema.GraphQLType; -import graphql.schema.GraphQLTypeVisitorStub; -import graphql.schema.PropertyDataFetcher; -import graphql.util.TraversalControl; -import graphql.util.TraverserContext; - -import org.springframework.lang.Nullable; - -/** - * Given a map of GraphQL type names and DataFetcher factories, find queries - * with a matching return type and register DataFetcher's for them, unless they - * already have registrations. - * - * @author Rossen Stoyanchev - * @deprecated in favor of {@link AutoRegistrationRuntimeWiringConfigurer} - */ -@Deprecated -class AutoRegistrationTypeVisitor extends GraphQLTypeVisitorStub { - - private final Map>> dataFetcherFactories; - - - /** - * Create an instance of the visitor. - * @param dataFetcherFactories map with GraphQL type names as keys and - * functions as values to create a DataFetcher for single or many values - */ - public AutoRegistrationTypeVisitor(Map>> dataFetcherFactories) { - this.dataFetcherFactories = dataFetcherFactories; - } - - - @Override - public TraversalControl visitGraphQLFieldDefinition( - GraphQLFieldDefinition fieldDefinition, TraverserContext context) { - - if (this.dataFetcherFactories.isEmpty()) { - return TraversalControl.QUIT; - } - - GraphQLType fieldType = fieldDefinition.getType(); - GraphQLFieldsContainer parent = (GraphQLFieldsContainer) context.getParentNode(); - if (!parent.getName().equals("Query")) { - return TraversalControl.ABORT; - } - - DataFetcher dataFetcher = (fieldType instanceof GraphQLList ? - getDataFetcher(((GraphQLList) fieldType).getWrappedType(), false) : - getDataFetcher(fieldType, true)); - - if (dataFetcher != null) { - GraphQLCodeRegistry.Builder registry = context.getVarFromParents(GraphQLCodeRegistry.Builder.class); - if (!hasDataFetcher(registry, parent, fieldDefinition)) { - FieldCoordinates coordinates = FieldCoordinates.coordinates(parent.getName(), fieldDefinition.getName()); - registry.dataFetcher(coordinates, dataFetcher); - } - } - - return TraversalControl.CONTINUE; - } - - @Nullable - private DataFetcher getDataFetcher(GraphQLType type, boolean single) { - if (type instanceof GraphQLNamedOutputType) { - String typeName = ((GraphQLNamedOutputType) type).getName(); - Function> factory = this.dataFetcherFactories.get(typeName); - if (factory != null) { - return factory.apply(single); - } - } - return null; - } - - private boolean hasDataFetcher( - GraphQLCodeRegistry.Builder registry, GraphQLFieldsContainer parent, - GraphQLFieldDefinition fieldDefinition) { - - FieldCoordinates coordinates = FieldCoordinates.coordinates(parent.getName(), fieldDefinition.getName()); - DataFetcher fetcher = registry.getDataFetcher(coordinates, fieldDefinition); - return (fetcher != null && !(fetcher instanceof PropertyDataFetcher)); - } - -} diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java index 352a8a99..36d5f5ae 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java @@ -27,7 +27,6 @@ import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import graphql.schema.DataFetchingFieldSelectionSet; import graphql.schema.GraphQLArgument; -import graphql.schema.GraphQLTypeVisitor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Flux; @@ -295,45 +294,6 @@ public abstract class QueryByExampleDataFetcher { return new AutoRegistrationRuntimeWiringConfigurer(factories); } - /** - * Create a {@link GraphQLTypeVisitor} that finds queries with a return type - * whose name matches to the domain type name of the given repositories and - * registers {@link DataFetcher}s for those queries. - *

Note: currently, this method will match only to - * queries under the top-level "Query" type in the GraphQL schema. - * - * @param executors repositories to consider for registration - * @param reactiveExecutors reactive repositories to consider for registration - * @return the created visitor - * @deprecated in favor of {@link #autoRegistrationConfigurer(List, List)} - */ - @Deprecated - public static GraphQLTypeVisitor autoRegistrationTypeVisitor( - List> executors, - List> reactiveExecutors) { - - Map>> factories = new HashMap<>(); - - for (QueryByExampleExecutor executor : executors) { - String typeName = RepositoryUtils.getGraphQlTypeName(executor); - if (typeName != null) { - Builder builder = customize(executor, builder(executor)); - factories.put(typeName, single -> single ? builder.single() : builder.many()); - } - } - - for (ReactiveQueryByExampleExecutor executor : reactiveExecutors) { - String typeName = RepositoryUtils.getGraphQlTypeName(executor); - if (typeName != null) { - ReactiveBuilder builder = customize(executor, builder(executor)); - factories.put(typeName, single -> single ? builder.single() : builder.many()); - } - } - - return new AutoRegistrationTypeVisitor(factories); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) private static Builder customize(QueryByExampleExecutor executor, Builder builder) { if(executor instanceof QueryByExampleBuilderCustomizer customizer){ diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java index 532aacae..ed233d8e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java @@ -28,7 +28,6 @@ import com.querydsl.core.types.Predicate; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import graphql.schema.DataFetchingFieldSelectionSet; -import graphql.schema.GraphQLTypeVisitor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Flux; @@ -326,50 +325,6 @@ public abstract class QuerydslDataFetcher { return new AutoRegistrationRuntimeWiringConfigurer(factories); } - /** - * Return a {@link GraphQLTypeVisitor} that auto-registers the given - * Querydsl repositories for queries that do not already have a registered - * {@code DataFetcher} and whose return type matches the simple name of the - * repository domain type. - * - *

Note: Auto-registration applies only to - * {@link GraphQlRepository @GraphQlRepository}-annotated repositories. - * If a repository is also an instance of {@link QuerydslBinderCustomizer}, - * this is transparently detected and applied through the - * {@code QuerydslDataFetcher} builder methods. - * - * @param executors repositories to consider for registration - * @param reactiveExecutors reactive repositories to consider for registration - * @return the created visitor - * @deprecated in favor of {@link #autoRegistrationConfigurer(List, List)} - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - @Deprecated - public static GraphQLTypeVisitor autoRegistrationTypeVisitor( - List> executors, - List> reactiveExecutors) { - - Map>> factories = new HashMap<>(); - - for (QuerydslPredicateExecutor executor : executors) { - String typeName = RepositoryUtils.getGraphQlTypeName(executor); - if (typeName != null) { - Builder builder = customize(executor, QuerydslDataFetcher.builder(executor).customizer(customizer(executor))); - factories.put(typeName, single -> single ? builder.single() : builder.many()); - } - } - - for (ReactiveQuerydslPredicateExecutor executor : reactiveExecutors) { - String typeName = RepositoryUtils.getGraphQlTypeName(executor); - if (typeName != null) { - ReactiveBuilder builder = customize(executor, QuerydslDataFetcher.builder(executor).customizer(customizer(executor))); - factories.put(typeName, single -> single ? builder.single() : builder.many()); - } - } - - return new AutoRegistrationTypeVisitor(factories); - } - @SuppressWarnings({"unchecked", "rawtypes"}) private static Builder customize(QuerydslPredicateExecutor executor, Builder builder) { if(executor instanceof QuerydslBuilderCustomizer customizer){ diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java index a855432e..67b7fae9 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java @@ -134,24 +134,4 @@ public abstract class DataFetcherExceptionResolverAdapter implements DataFetcher } - /** - * Factory method to create a {@link DataFetcherExceptionResolverAdapter} that - * resolves exceptions with the given {@code BiFunction}. - * @param resolver the resolver function to use - * @return the created instance - * @deprecated as of 1.0.1, please use {@link DataFetcherExceptionResolver#forSingleError(BiFunction)} - */ - @Deprecated - public static DataFetcherExceptionResolverAdapter from( - BiFunction resolver) { - - return new DataFetcherExceptionResolverAdapter() { - - @Override - protected GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env) { - return resolver.apply(ex, env); - } - }; - } - } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java index d3d1a388..1ee4ef26 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java @@ -45,7 +45,7 @@ public class WebSocketGraphQlRequest extends WebGraphQlRequest { * Create an instance. * @deprecated as of 1.1.3 in favor of the constructor with cookies */ - @Deprecated + @Deprecated(since = "1.1.3", forRemoval = true) public WebSocketGraphQlRequest( URI uri, HttpHeaders headers, Map body, String id, @Nullable Locale locale, WebSocketSessionInfo sessionInfo) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java index dfcb964f..c2131d08 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java @@ -148,7 +148,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub * propagate context. * @deprecated as of 1.1.0 in favor of {@link #initWebSocketHttpRequestHandler(HandshakeHandler)} */ - @Deprecated + @Deprecated(since = "1.1.0", forRemoval = true) public WebSocketHttpRequestHandler asWebSocketHttpRequestHandler(HandshakeHandler handshakeHandler) { return initWebSocketHttpRequestHandler(handshakeHandler); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java index 92a4de0f..6cbe888f 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -160,33 +160,12 @@ public abstract class AbstractGraphQlResponse implements GraphQlResponse { return this.parsedPath; } - @SuppressWarnings("deprecation") - @Override - public boolean hasValue() { - return (this.value != null); - } - @SuppressWarnings("unchecked") @Override public T getValue() { return (T) this.value; } - @SuppressWarnings("deprecation") - @Override - public ResponseError getError() { - if (getValue() != null) { - if (!this.fieldErrors.isEmpty()) { - return this.fieldErrors.get(0); - } - if (!this.response.getErrors().isEmpty()) { - return this.response.getErrors().get(0); - } - // No errors, set to null by DataFetcher - } - return null; - } - @Override public List getErrors() { return this.fieldErrors;