diff --git a/gradle.properties b/gradle.properties index 1de00506..8caa23c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,9 +14,9 @@ # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -version=12.0.0-SNAPSHOT +version=12.0.1-SNAPSHOT ### Project Metadata group=com.graphql-java-kickstart PROJECT_NAME=graphql-spring-boot diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/CorsEnabledCondition.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/CorsEnabledCondition.java new file mode 100644 index 00000000..3342268d --- /dev/null +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/CorsEnabledCondition.java @@ -0,0 +1,23 @@ +package graphql.kickstart.autoconfigure.web.servlet; + +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.env.PropertyResolver; +import org.springframework.core.type.AnnotatedTypeMetadata; + +public class CorsEnabledCondition implements Condition { + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + PropertyResolver resolver = context.getEnvironment(); + Boolean kebabCorsEnabled = resolver.getProperty("graphql.servlet.cors-enabled", Boolean.class); + if (kebabCorsEnabled != null) { + return kebabCorsEnabled; + } + Boolean camelCorsEnabled = resolver.getProperty("graphql.servlet.corsEnabled", Boolean.class); + if (camelCorsEnabled != null) { + return camelCorsEnabled; + } + return true; + } +} diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java index 914c2750..c46df4ef 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java @@ -30,20 +30,24 @@ @ConfigurationProperties(prefix = "graphql.servlet") public class GraphQLServletProperties { - public final static Duration DEFAULT_SUBSCRIPTION_TIMEOUT = Duration.ZERO; + public static final Duration DEFAULT_SUBSCRIPTION_TIMEOUT = Duration.ZERO; private boolean enabled = true; private boolean corsEnabled = true; private String mapping = "/graphql"; private boolean exceptionHandlersEnabled = false; - /** - * Subscription timeout. If a duration suffix is not specified, millisecond will be used. - */ + /** Subscription timeout. If a duration suffix is not specified, millisecond will be used. */ @DurationUnit(ChronoUnit.MILLIS) private Duration subscriptionTimeout = DEFAULT_SUBSCRIPTION_TIMEOUT; + private ContextSetting contextSetting = ContextSetting.PER_QUERY_WITH_INSTRUMENTATION; - /** Asynchronous execution timeout. If a duration suffix is not specified, millisecond will be used. @deprecated Use graphql.servlet.async.timeout instead */ - @Deprecated @DurationUnit(ChronoUnit.MILLIS) private Duration asyncTimeout; + /** + * Asynchronous execution timeout. If a duration suffix is not specified, millisecond will be + * used. @deprecated Use graphql.servlet.async.timeout instead + */ + @Deprecated + @DurationUnit(ChronoUnit.MILLIS) + private Duration asyncTimeout; /** @deprecated Use graphql.servlet.async.enabled instead */ @Deprecated private Boolean asyncModeEnabled; diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java index 04018368..1e1356c5 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java @@ -73,6 +73,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; @@ -128,6 +129,7 @@ public GraphQLErrorStartupListener graphQLErrorStartupListener( @Bean @ConditionalOnClass(CorsFilter.class) + @Conditional(CorsEnabledCondition.class) @ConfigurationProperties("graphql.servlet.cors") public CorsConfiguration corsConfiguration() { return new CorsConfiguration(); @@ -135,10 +137,7 @@ public CorsConfiguration corsConfiguration() { @Bean @ConditionalOnClass(CorsFilter.class) - @ConditionalOnProperty( - value = "graphql.servlet.corsEnabled", - havingValue = "true", - matchIfMissing = true) + @Conditional(CorsEnabledCondition.class) public CorsFilter corsConfigurer(CorsConfiguration corsConfiguration) { Map corsConfigurations = new LinkedHashMap<>(1); if (corsConfiguration.getAllowedMethods() == null) { @@ -303,12 +302,17 @@ public GraphQLConfiguration graphQLServletConfiguration( @Autowired(required = false) GraphQLResponseCacheManager responseCacheManager, @Autowired(required = false) AsyncTaskDecorator asyncTaskDecorator, @Autowired(required = false) @Qualifier("graphqlAsyncTaskExecutor") Executor asyncExecutor) { - Duration asyncTimeout = Optional.ofNullable(asyncServletProperties.getTimeout()) // - .orElse(AsyncServletProperties.DEFAULT_TIMEOUT); - long asyncTimeoutMilliseconds = Optional.ofNullable(graphQLServletProperties.getAsyncTimeout()) // - .orElse(asyncTimeout).toMillis(); - long subscriptionTimeoutMilliseconds = Optional.ofNullable(graphQLServletProperties.getSubscriptionTimeout()) // - .orElse(GraphQLServletProperties.DEFAULT_SUBSCRIPTION_TIMEOUT).toMillis(); + Duration asyncTimeout = + Optional.ofNullable(asyncServletProperties.getTimeout()) // + .orElse(AsyncServletProperties.DEFAULT_TIMEOUT); + long asyncTimeoutMilliseconds = + Optional.ofNullable(graphQLServletProperties.getAsyncTimeout()) // + .orElse(asyncTimeout) + .toMillis(); + long subscriptionTimeoutMilliseconds = + Optional.ofNullable(graphQLServletProperties.getSubscriptionTimeout()) // + .orElse(GraphQLServletProperties.DEFAULT_SUBSCRIPTION_TIMEOUT) + .toMillis(); return GraphQLConfiguration.with(invocationInputFactory) .with(graphQLInvoker) .with(graphQLObjectMapper)