Skip to content

Commit 9a92a9c

Browse files
committed
Add AutoConfigureGraphQl test annotation
This commit adds the `@AutoConfigureGraphQl` test annotation. It can be used to import the relevant auto-configurations when testing a GraphQL application. Currently, it will get the main `GraphQlAutoConfiguration`, but also what's required for configuring codecs and validation support. See gh-29140
1 parent 6dbcd0e commit 9a92a9c

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

spring-boot-project/spring-boot-test-autoconfigure/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
optional("org.springframework.data:spring-data-neo4j")
5656
optional("org.springframework.data:spring-data-r2dbc")
5757
optional("org.springframework.data:spring-data-redis")
58+
optional("org.springframework.graphql:spring-graphql-test")
5859
optional("org.springframework.restdocs:spring-restdocs-mockmvc") {
5960
exclude group: "javax.servlet", module: "javax.servlet-api"
6061
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.test.autoconfigure.graphql;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Inherited;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
27+
28+
/**
29+
* {@link ImportAutoConfiguration Auto-configuration imports} for typical Spring GraphQL
30+
* tests. Most tests should consider using {@link GraphQlTest @GraphQlTest} rather than
31+
* using this annotation directly.
32+
*
33+
* @author Brian Clozel
34+
* @since 2.7.0
35+
* @see GraphQlTest
36+
* @see org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration
37+
* @see org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
38+
* @see org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration
39+
*/
40+
@Target(ElementType.TYPE)
41+
@Retention(RetentionPolicy.RUNTIME)
42+
@Documented
43+
@Inherited
44+
@ImportAutoConfiguration
45+
public @interface AutoConfigureGraphQl {
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2020-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Auto-configuration for GraphQL testing.
19+
*/
20+
package org.springframework.boot.test.autoconfigure.graphql;

spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories

+6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfigurati
188188
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
189189
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
190190

191+
# AutoConfigureGraphQl auto-configuration imports
192+
org.springframework.boot.test.autoconfigure.graphql.AutoConfigureGraphQl=\
193+
org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
194+
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
195+
org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration
196+
191197
# AutoConfigureWebServiceClient
192198
org.springframework.boot.test.autoconfigure.webservices.client.AutoConfigureWebServiceClient=\
193199
org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTemplateAutoConfiguration,\

0 commit comments

Comments
 (0)