This repository was archived by the owner on Dec 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +103
-1
lines changed
graphql-kickstart-spring-boot-autoconfigure-webflux
main/java/graphql/kickstart/spring/webflux/boot
java/graphql/kickstart/spring/webflux/boot
graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/spring/web/boot Expand file tree Collapse file tree 10 files changed +103
-1
lines changed Original file line number Diff line number Diff line change @@ -5,4 +5,7 @@ dependencies {
5
5
implementation " org.springframework.boot:spring-boot-autoconfigure"
6
6
implementation " com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER "
7
7
implementation " org.springframework.boot:spring-boot-starter-webflux"
8
+
9
+ testImplementation " org.springframework.boot:spring-boot-starter-test"
10
+ testImplementation(project(" :graphql-kickstart-spring-boot-starter-tools" ))
8
11
}
Original file line number Diff line number Diff line change 1
1
package graphql .kickstart .spring .webflux .boot ;
2
2
3
3
import static graphql .kickstart .execution .GraphQLObjectMapper .newBuilder ;
4
+ import static org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication .Type .REACTIVE ;
4
5
5
6
import graphql .execution .instrumentation .dataloader .DataLoaderDispatcherInstrumentationOptions ;
6
7
import graphql .kickstart .execution .BatchedDataLoaderGraphQLBuilder ;
39
40
import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
40
41
import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
41
42
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
43
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
42
44
import org .springframework .context .annotation .Bean ;
43
45
import org .springframework .context .annotation .Configuration ;
44
46
import org .springframework .context .annotation .Import ;
50
52
@ SuppressWarnings ("SpringJavaInjectionPointsAutowiringInspection" )
51
53
@ Slf4j
52
54
@ Configuration
55
+ @ ConditionalOnWebApplication (type = REACTIVE )
53
56
@ ConditionalOnBean (GraphQLSchema .class )
54
57
@ AutoConfigureAfter (GraphQLJavaToolsAutoConfiguration .class )
55
58
@ Import ({GraphQLController .class , ReactiveWebSocketSubscriptionsHandler .class })
Original file line number Diff line number Diff line change 1
1
package graphql .kickstart .spring .webflux .boot ;
2
2
3
+ import static org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication .Type .REACTIVE ;
4
+
3
5
import graphql .kickstart .tools .SchemaParser ;
4
6
import graphql .kickstart .tools .SchemaParserOptions .GenericWrapper ;
5
7
import graphql .kickstart .tools .boot .GraphQLJavaToolsAutoConfiguration ;
6
8
import java .util .List ;
7
9
import org .springframework .beans .factory .annotation .Autowired ;
8
10
import org .springframework .boot .autoconfigure .AutoConfigureBefore ;
9
11
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
12
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
10
13
import org .springframework .context .annotation .Bean ;
11
14
import org .springframework .context .annotation .Configuration ;
12
15
import reactor .core .publisher .Mono ;
13
16
14
17
@ Configuration
15
18
@ ConditionalOnClass (SchemaParser .class )
19
+ @ ConditionalOnWebApplication (type = REACTIVE )
16
20
@ AutoConfigureBefore (GraphQLJavaToolsAutoConfiguration .class )
17
21
public class MonoAutoConfiguration {
18
22
Original file line number Diff line number Diff line change
1
+ package graphql .kickstart .spring .webflux .boot ;
2
+
3
+ import graphql .kickstart .tools .GraphQLQueryResolver ;
4
+ import org .springframework .stereotype .Component ;
5
+ import reactor .core .publisher .Mono ;
6
+
7
+ @ Component
8
+ class HelloQuery implements GraphQLQueryResolver {
9
+
10
+ public Mono <String > hello () {
11
+ return Mono .just ("Hello world" );
12
+ }
13
+
14
+ }
Original file line number Diff line number Diff line change
1
+ package graphql .kickstart .spring .webflux .boot ;
2
+
3
+ import static org .assertj .core .api .Assertions .assertThat ;
4
+
5
+ import java .io .IOException ;
6
+ import lombok .RequiredArgsConstructor ;
7
+ import lombok .val ;
8
+ import org .junit .jupiter .api .Test ;
9
+ import org .junit .jupiter .api .extension .ExtendWith ;
10
+ import org .springframework .beans .factory .annotation .Autowired ;
11
+ import org .springframework .boot .test .context .SpringBootTest ;
12
+ import org .springframework .http .MediaType ;
13
+ import org .springframework .test .context .junit .jupiter .SpringExtension ;
14
+ import org .springframework .test .web .reactive .server .WebTestClient ;
15
+
16
+ @ SuppressWarnings ("ALL" )
17
+ @ RequiredArgsConstructor
18
+ @ ExtendWith (SpringExtension .class )
19
+ @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
20
+ class MonoAutoConfigurationTest {
21
+
22
+ @ Autowired
23
+ private WebTestClient webTestClient ;
24
+
25
+ @ Test
26
+ void monoWrapper () throws IOException {
27
+ val result = webTestClient .post ()
28
+ .uri ("/graphql" )
29
+ .contentType (MediaType .APPLICATION_JSON )
30
+ .bodyValue ("{ \" query\" : \" query { hello } \" }" )
31
+ .exchange ()
32
+ .returnResult (String .class );
33
+ val response = result .getResponseBody ().blockFirst ();
34
+ assertThat (response ).isEqualTo ("{\" data\" :{\" hello\" :\" Hello world\" }}" );
35
+ }
36
+
37
+ }
Original file line number Diff line number Diff line change
1
+ package graphql .kickstart .spring .webflux .boot ;
2
+
3
+ import graphql .kickstart .tools .GraphQLSubscriptionResolver ;
4
+ import graphql .schema .DataFetchingEnvironment ;
5
+ import java .time .Duration ;
6
+ import org .reactivestreams .Publisher ;
7
+ import org .springframework .stereotype .Service ;
8
+ import reactor .core .publisher .Flux ;
9
+
10
+ @ Service
11
+ class MySubscriptionResolver implements GraphQLSubscriptionResolver {
12
+
13
+ Publisher <Integer > hello (DataFetchingEnvironment env ) {
14
+ return Flux .range (0 , 100 ).delayElements (Duration .ofSeconds (1 ));
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ package graphql .kickstart .spring .webflux .boot ;
2
+
3
+ import org .springframework .boot .SpringApplication ;
4
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
+
6
+ @ SpringBootApplication
7
+ public class WebfluxApplication {
8
+
9
+ public static void main (String [] args ) {
10
+ SpringApplication .run (WebfluxApplication .class , args );
11
+ }
12
+
13
+ }
Original file line number Diff line number Diff line change
1
+ query {
2
+ hello
3
+ }
Original file line number Diff line number Diff line change
1
+ type Query {
2
+ hello : String
3
+ }
4
+
5
+ type Subscription {
6
+ hello : Int
7
+ }
Original file line number Diff line number Diff line change 72
72
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
73
73
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
74
74
import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
75
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication .Type ;
75
76
import org .springframework .boot .autoconfigure .jackson .JacksonAutoConfiguration ;
76
77
import org .springframework .boot .context .properties .ConfigurationProperties ;
77
78
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
92
93
@ Slf4j
93
94
@ Configuration
94
95
@ RequiredArgsConstructor
95
- @ ConditionalOnWebApplication
96
+ @ ConditionalOnWebApplication ( type = Type . SERVLET )
96
97
@ ConditionalOnClass (DispatcherServlet .class )
97
98
@ Conditional (OnSchemaOrSchemaProviderBean .class )
98
99
@ SuppressWarnings ("SpringJavaInjectionPointsAutowiringInspection" )
You can’t perform that action at this time.
0 commit comments