forked from graphql-java-kickstart/graphql-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autoconfigure Generic wrapper for Mono fix graphql-java-kickstart#326
- Loading branch information
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...re-webflux/src/main/java/graphql/kickstart/spring/webflux/boot/MonoAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
...-kickstart-spring-boot-autoconfigure-webflux/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |