Skip to content

Commit

Permalink
Autoconfigure Generic wrapper for Mono fix graphql-java-kickstart#326
Browse files Browse the repository at this point in the history
  • Loading branch information
oliemansm committed Jan 16, 2021
1 parent 68359c2 commit 9400de3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@Slf4j
@Configuration
@ConditionalOnClass(SchemaParser.class)
@AutoConfigureAfter({JacksonAutoConfiguration.class})
@AutoConfigureAfter(JacksonAutoConfiguration.class)
@EnableConfigurationProperties(GraphQLToolsProperties.class)
public class GraphQLJavaToolsAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Slf4j
@Configuration
@ConditionalOnBean({GraphQLSchema.class})
@AutoConfigureAfter({GraphQLJavaToolsAutoConfiguration.class})
@ConditionalOnBean(GraphQLSchema.class)
@AutoConfigureAfter(GraphQLJavaToolsAutoConfiguration.class)
@Import({GraphQLController.class, ReactiveWebSocketSubscriptionsHandler.class})
public class GraphQLSpringWebfluxAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package graphql.kickstart.spring.webflux.boot;

import graphql.kickstart.tools.SchemaParser;
import graphql.kickstart.tools.SchemaParserOptions.GenericWrapper;
import graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

@Configuration
@ConditionalOnClass(SchemaParser.class)
@AutoConfigureBefore(GraphQLJavaToolsAutoConfiguration.class)
public class MonoAutoConfiguration {

@Bean
GenericWrapper monoWrapper(@Autowired(required = false) List<GenericWrapper> genericWrappers) {
if (notWrapsMono(genericWrappers)) {
return GenericWrapper.withTransformer(
Mono.class,
0,
Mono::toFuture,
t -> t
);
}
return null;
}

private boolean notWrapsMono(List<GenericWrapper> genericWrappers) {
return genericWrappers == null ||
genericWrappers.stream().noneMatch(it -> it.getType().isAssignableFrom(Mono.class));
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
graphql.kickstart.spring.webflux.boot.GraphQLSpringWebfluxAutoConfiguration
graphql.kickstart.spring.webflux.boot.GraphQLSpringWebfluxAutoConfiguration,\
graphql.kickstart.spring.webflux.boot.MonoAutoConfiguration

0 comments on commit 9400de3

Please sign in to comment.