Skip to content

Commit

Permalink
Merge branch 'master' into expose-raw-response
Browse files Browse the repository at this point in the history
  • Loading branch information
oliemansm authored Dec 18, 2023
2 parents eaf7ab3 + 5184822 commit fcc91c7
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
if: env.SONAR_TOKEN != null
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -43,7 +43,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ should be defined as `graphql.client.url` in your Spring Boot configuration file
| `oauth2.client-secret` | OAuth2 client secret |
| `oauth2.token-uri` | Token URI of the identity provider |
| `oauth2.authorization-grant-type` | By default the grant type `client_credentials` is used |

| `retry.strategy` | The retry strategy to auto configure for the `WebClient` _(possible values are `none`, `backoff`, `fixed_delay`, `indefinitely`, `max` and `max_in_row`)_. Default is `none`. |
| `retry.backoff.max-attempts` | The maximum number of retry attempts to allow _(only used when `retry.strategy` = `backoff`)_. |
| `retry.backoff.min-backoff` | The minimum duration for the first backoff _(only used when `retry.strategy` = `backoff`)_. Default is `0`. |
| `retry.backoff.max-backoff` | The maximum duration for the exponential backoffs _(only used when `retry.strategy` = `backoff`)_. Default is `Duration.ofMillis(Long.MAX_VALUE)`. |
| `retry.fixed-delay.max-attempts` | The maximum number of retry attempts to allow _(only used when `retry.strategy` = `fixed_delay`)_. |
| `retry.fixed-delay.delay` | The duration of the fixed delays between attempts _(only used when `retry.strategy` = `fixed_delay`)_. |
| `retry.max.max-attempts` | The maximum number of retry attempts to allow _(only used when `retry.strategy` = `max`)_. |
| `retry.max-in-row.max-attempts` | The maximum number of retry attempts to allow in a row _(only used when `retry.strategy` = `max_in_row`)_. |

### Max in memory size

In case you need to work with large responses you might run into the following error:
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ PROJECT_DEV_NAME = Michiel Oliemans

### Test libraries

LIB_GRAPHQL_TOOLS_VER = 13.1.0
LIB_GRAPHQL_SPRING_VER = 15.0.0
LIB_GRAPHQL_SERVLET_VER = 15.0.0
LIB_GRAPHQL_TOOLS_VER = 13.1.1
LIB_GRAPHQL_SPRING_VER = 15.1.0
LIB_GRAPHQL_SERVLET_VER = 15.1.0

### Gradle Plugins

LIB_SPRING_BOOT_VER = 3.1.5
LIB_SPRING_BOOT_VER = 3.2.0
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package graphql.kickstart.spring.webclient.boot;

import java.time.Duration;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Primary;

import lombok.Data;

@Data
@Primary
@ConfigurationProperties("graphql.client.retry")
public class GraphQLClientRetryProperties {

private RetryStrategy strategy = RetryStrategy.NONE;
private RetryBackoff backoff = new RetryBackoff();
private RetryFixedDelay fixedDelay = new RetryFixedDelay();
private RetryMax max = new RetryMax();
private RetryMaxInRow maxInRow = new RetryMaxInRow();

@Data
static class RetryBackoff {
private long maxAttempts = -1;
private Duration minBackoff = Duration.ofMillis(0);
private Duration maxBackoff = Duration.ofMillis(Long.MAX_VALUE);
}

@Data
static class RetryFixedDelay {
private long maxAttempts = -1;
private Duration delay = Duration.ofMillis(0);
}

@Data
static class RetryMax {
private long maxAttempts = -1;
}

@Data
static class RetryMaxInRow {
private long maxAttempts = -1;
}

enum RetryStrategy {
BACKOFF,
FIXED_DELAY,
INDEFINITELY,
MAX,
MAX_IN_ROW,
NONE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.util.retry.Retry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -28,11 +29,12 @@
OAuth2ClientAutoConfiguration.class,
WebFluxAutoConfiguration.class
})
@EnableConfigurationProperties(GraphQLClientProperties.class)
@EnableConfigurationProperties({ GraphQLClientProperties.class, GraphQLClientRetryProperties.class })
@ComponentScan(basePackageClasses = GraphQLWebClientImpl.class)
public class GraphQLWebClientAutoConfiguration {

private final GraphQLClientProperties graphqlClientProperties;
private final GraphQLClientRetryProperties graphqlClientRetryProperties;

@Bean
@ConditionalOnMissingBean
Expand Down Expand Up @@ -76,7 +78,42 @@ public ObjectMapper objectMapper() {

@Bean
@ConditionalOnMissingBean
public GraphQLWebClient graphQLWebClient(WebClient webClient, ObjectMapper objectMapper) {
return new GraphQLWebClientImpl(webClient, objectMapper);
public GraphQLWebClient graphQLWebClient(WebClient webClient, ObjectMapper objectMapper, GraphQLWebClientRetryProvider retryProvider) {
return new GraphQLWebClientImpl(webClient, objectMapper, retryProvider.get());
}

@Bean
@ConditionalOnMissingBean
public GraphQLWebClientRetryProvider graphQLWebClientRetryProvider(GraphQLWebClientRetryErrorFilterPredicate errorFilterPredicate) {
return () -> switch(graphqlClientRetryProperties.getStrategy()) {
case BACKOFF ->
Retry.backoff(graphqlClientRetryProperties.getBackoff().getMaxAttempts(), graphqlClientRetryProperties.getBackoff().getMinBackoff())
.maxBackoff(graphqlClientRetryProperties.getBackoff().getMaxBackoff())
.modifyErrorFilter(p -> p.and(errorFilterPredicate));

case FIXED_DELAY ->
Retry.fixedDelay(graphqlClientRetryProperties.getFixedDelay().getMaxAttempts(), graphqlClientRetryProperties.getFixedDelay().getDelay())
.modifyErrorFilter(p -> p.and(errorFilterPredicate));

case INDEFINITELY ->
Retry.indefinitely()
.modifyErrorFilter(p -> p.and(errorFilterPredicate));

case MAX ->
Retry.max(graphqlClientRetryProperties.getMax().getMaxAttempts())
.modifyErrorFilter(p -> p.and(errorFilterPredicate));

case MAX_IN_ROW ->
Retry.maxInARow(graphqlClientRetryProperties.getMaxInRow().getMaxAttempts())
.modifyErrorFilter(p -> p.and(errorFilterPredicate));

default -> null;
};
}

@Bean
@ConditionalOnMissingBean
public GraphQLWebClientRetryErrorFilterPredicate graphQLWebClientRetryErrorFilterPredicate() {
return t -> true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package graphql.kickstart.spring.webclient.boot;

import java.util.function.Predicate;

public interface GraphQLWebClientRetryErrorFilterPredicate extends Predicate<Throwable> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package graphql.kickstart.spring.webclient.boot;

import reactor.util.retry.Retry;

public interface GraphQLWebClientRetryProvider {
Retry get();
}
Loading

0 comments on commit fcc91c7

Please sign in to comment.