Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Move milliseconds and seconds to duration #647

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private Map<String, String> getReplacements(
}
replacements.put(
"subscriptionClientTimeout",
String.valueOf(graphiQLProperties.getSubscriptions().getTimeout() * 1000));
String.valueOf(graphiQLProperties.getSubscriptions().getTimeout().toMillis()));
replacements.put(
"subscriptionClientReconnect",
String.valueOf(graphiQLProperties.getSubscriptions().isReconnect()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package graphql.kickstart.autoconfigure.editor.graphiql;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;

@Data
@ConfigurationProperties("graphql.graphiql")
Expand Down Expand Up @@ -65,7 +68,11 @@ static class Cdn {
@Data
static class Subscriptions {

private int timeout = 30;
/**
* Subscription timeout. If a duration suffix is not specified, second will be used.
*/
@DurationUnit(ChronoUnit.SECONDS)
private Duration timeout = Duration.ofSeconds(30);
private boolean reconnect = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package graphql.kickstart.autoconfigure.web.servlet;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;

@Data
@ConfigurationProperties(prefix = "graphql.servlet.async")
public class AsyncServletProperties {

public static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(30);

private boolean enabled = true;
private long timeout = 30000;
/**
* Asynchronous execution timeout. If a duration suffix is not specified, millisecond will be used.
*/
@DurationUnit(ChronoUnit.MILLIS)
private Duration timeout = DEFAULT_TIMEOUT;
private boolean delegateSecurityContext = true;
private Threads threads = new Threads();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,31 @@
package graphql.kickstart.autoconfigure.web.servlet;

import graphql.kickstart.execution.context.ContextSetting;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;

/** @author Michiel Oliemans */
@Data
@ConfigurationProperties(prefix = "graphql.servlet")
public class GraphQLServletProperties {

public final static Duration DEFAULT_SUBSCRIPTION_TIMEOUT = Duration.ZERO;

private boolean enabled = true;
private boolean corsEnabled = true;
private String mapping = "/graphql";
private boolean exceptionHandlersEnabled = false;
private long subscriptionTimeout = 0;
/**
* 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;
/** @deprecated Use <tt>graphql.servlet.async.timeout</tt> instead */
@Deprecated private Long asyncTimeout;
/** Asynchronous execution timeout. If a duration suffix is not specified, millisecond will be used. @deprecated Use <tt>graphql.servlet.async.timeout</tt> instead */
@Deprecated @DurationUnit(ChronoUnit.MILLIS) private Duration asyncTimeout;
/** @deprecated Use <tt>graphql.servlet.async.enabled</tt> instead */
@Deprecated private Boolean asyncModeEnabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@
import graphql.kickstart.spring.error.ErrorHandlerSupplier;
import graphql.kickstart.spring.error.GraphQLErrorStartupListener;
import graphql.schema.GraphQLSchema;
import java.time.Duration;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.Executor;
import javax.servlet.MultipartConfigElement;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -301,19 +303,21 @@ public GraphQLConfiguration graphQLServletConfiguration(
@Autowired(required = false) GraphQLResponseCacheManager responseCacheManager,
@Autowired(required = false) AsyncTaskDecorator asyncTaskDecorator,
@Autowired(required = false) @Qualifier("graphqlAsyncTaskExecutor") Executor asyncExecutor) {
long asyncTimeout =
graphQLServletProperties.getAsyncTimeout() != null
? graphQLServletProperties.getAsyncTimeout()
: asyncServletProperties.getTimeout();
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)
.with(listeners)
.with(graphQLServletProperties.getSubscriptionTimeout())
.with(subscriptionTimeoutMilliseconds)
.with(batchInputPreProcessor)
.with(graphQLServletProperties.getContextSetting())
.with(responseCacheManager)
.asyncTimeout(asyncTimeout)
.asyncTimeout(asyncTimeoutMilliseconds)
.with(asyncTaskDecorator)
.asyncCorePoolSize(asyncServletProperties.getThreads().getMin())
.asyncCorePoolSize(asyncServletProperties.getThreads().getMax())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.graphql.spring.boot.test.GraphQLResponse;
import com.graphql.spring.boot.test.GraphQLTestSubscription;
import java.time.Duration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,7 +26,7 @@ void testSubscription() {
graphQLTestSubscription
.init()
.start("annotations/subscriptions/test-subscription.graphql")
.awaitAndGetNextResponse(10000);
.awaitAndGetNextResponse(Duration.ofSeconds(10));
// THEN
assertThat(graphQLResponse.get("$.data.testSubscription")).isEqualTo("some value");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.graphql.spring.boot.test;

import java.io.IOException;
import java.time.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
Expand All @@ -19,7 +20,7 @@ void assertThatTestSubscriptionWorksCorrectly() {
// WHEN - THEN
testSubscription
.start("test-subscription.graphql")
.awaitAndGetNextResponse(1000)
.awaitAndGetNextResponse(Duration.ofSeconds(1))
.assertThatNoErrorsArePresent()
.assertThatField("$.data.testSubscription")
.asString()
Expand Down
Loading