Deprecate @GraphQlController in favor of @Controller
This commit is contained in:
@@ -21,12 +21,12 @@ import java.util.List;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
public class SalaryController {
|
||||
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@@ -18,11 +18,11 @@ package io.spring.sample.graphql;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
public class SampleController {
|
||||
|
||||
private final DataRepository repository;
|
||||
|
||||
@@ -19,12 +19,12 @@ import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
public class SalaryController {
|
||||
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package io.spring.sample.graphql.greeting;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
|
||||
import static org.springframework.web.context.request.RequestAttributes.SCOPE_REQUEST;
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
public class GreetingController {
|
||||
|
||||
@QueryMapping
|
||||
|
||||
@@ -18,11 +18,11 @@ package io.spring.sample.graphql.project;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
public class ProjectController {
|
||||
|
||||
private final SpringProjectsClient client;
|
||||
|
||||
@@ -124,8 +124,8 @@ starter detects such beans adds them to <<execution-graphqlsource,GraphQlSource.
|
||||
Typically, however, applications will not implement ``DataFetcher`` directly and will
|
||||
instead create <<controllers,annotated controllers>>. The Boot
|
||||
starter declares a `RuntimeWiringConfigurer` called `AnnotatedDataFetcherConfigurer` that
|
||||
detects `@GraphQlController` classes with annotated handler methods and registers those
|
||||
as ``DataFetcher``s.
|
||||
detects `@Controller` classes with annotated handler methods and registers those as
|
||||
``DataFetcher``s.
|
||||
|
||||
|
||||
[[boot-repositories-querydsl]]
|
||||
|
||||
@@ -370,7 +370,7 @@ Such repositories are auto-detected in the <<boot-repositories-querydsl,Boot sta
|
||||
[[controllers]]
|
||||
== Annotated Controllers
|
||||
|
||||
Spring GraphQL provides an annotation-based programming model where `@GraphQlController`
|
||||
Spring GraphQL provides an annotation-based programming model where `@Controller`
|
||||
components use annotations to declare handler methods with flexible method signatures to
|
||||
fetch the data for specific GraphQL fields. For example:
|
||||
|
||||
@@ -396,13 +396,13 @@ Spring GraphQL uses `RuntimeWiring.Builder` to register the above handler method
|
||||
[[controllers-declaration]]
|
||||
=== Declaration
|
||||
|
||||
You can define `@GraphQlController` beans as standard Spring bean definitions. The
|
||||
`@GraphQlController` stereotype allows for auto-detection, aligned with Spring general
|
||||
You can define `@Controller` beans as standard Spring bean definitions. The
|
||||
`@Controller` stereotype allows for auto-detection, aligned with Spring general
|
||||
support for detecting `@Controller` and `@Component` classes on the classpath and
|
||||
auto-registering bean definitions for them. It also acts as a stereotype for the annotated
|
||||
class, indicating its role as a data fetching component in a GraphQL application.
|
||||
|
||||
`AnnotatedDataFetcherConfigurer` detects `@GraphQlController` beans and registers their
|
||||
`AnnotatedDataFetcherConfigurer` detects `@Controller` beans and registers their
|
||||
annotated handler methods as ``DataFetcher``s via `RuntimeWiring.Builder`. It is an
|
||||
implementation of `RuntimeWiringConfigurer` which can be added to `GraphQlSource.Builder`.
|
||||
The Spring Boot starter automatically declares `AnnotatedDataFetcherConfigurer` as a bean
|
||||
|
||||
@@ -41,13 +41,12 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
|
||||
import org.springframework.graphql.data.method.annotation.support.InputArgumentMethodArgumentResolver;
|
||||
import org.springframework.graphql.data.method.annotation.support.DataFetchingEnvironmentMethodArgumentResolver;
|
||||
import org.springframework.graphql.data.method.annotation.support.InputArgumentMethodArgumentResolver;
|
||||
import org.springframework.graphql.data.method.annotation.support.SourceMethodArgumentResolver;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -56,14 +55,15 @@ import org.springframework.http.codec.EncoderHttpMessageWriter;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link RuntimeWiringConfigurer} that detects {@link SchemaMapping @SchemaMapping}
|
||||
* annotated handler methods in {@link GraphQlController @GraphQlController}
|
||||
* classes and registers them as {@link DataFetcher}s.
|
||||
* annotated handler methods in {@link Controller @Controller} classes and
|
||||
* registers them as {@link DataFetcher}s.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
@@ -227,7 +227,7 @@ public class AnnotatedDataFetcherConfigurer
|
||||
}
|
||||
|
||||
private boolean isHandler(Class<?> beanType) {
|
||||
return (AnnotatedElementUtils.hasAnnotation(beanType, GraphQlController.class) ||
|
||||
return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) ||
|
||||
AnnotatedElementUtils.hasAnnotation(beanType, SchemaMapping.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,12 @@ import org.springframework.stereotype.Controller;
|
||||
* {@link QueryMapping}, {@link MutationMapping}, and {@link SubscriptionMapping}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
* @deprecated in favor of using {@link Controller @Controller}
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Controller
|
||||
@Deprecated
|
||||
public @interface GraphQlController {
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.graphql.Author;
|
||||
import org.springframework.graphql.Book;
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -100,7 +100,7 @@ public class AnnotatedDataFetcherConfigurerTests {
|
||||
}
|
||||
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
private static class BookController {
|
||||
|
||||
|
||||
|
||||
@@ -35,13 +35,13 @@ import org.springframework.graphql.Book;
|
||||
import org.springframework.graphql.BookCriteria;
|
||||
import org.springframework.graphql.BookSource;
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlController;
|
||||
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SchemaMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -204,7 +204,7 @@ public class AnnotatedDataFetcherInvocationTests {
|
||||
}
|
||||
|
||||
|
||||
@GraphQlController
|
||||
@Controller
|
||||
private static class BookController {
|
||||
|
||||
@QueryMapping
|
||||
|
||||
Reference in New Issue
Block a user