Skip to content

Commit da40bdd

Browse files
authored
Merge pull request #342 from graphql-java-kickstart/bugfix/469-apply-async-timeout
Bugfix/469 apply async timeout
2 parents 159eb3d + efdb43f commit da40bdd

File tree

14 files changed

+240
-102
lines changed

14 files changed

+240
-102
lines changed

.github/workflows/pull-request.yml

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,6 @@ jobs:
1111
- uses: actions/checkout@v2
1212
- uses: gradle/wrapper-validation-action@v1
1313

14-
verify-google-java-format:
15-
name: Google Java Format Verification
16-
runs-on: ubuntu-latest
17-
needs: validation
18-
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v2
21-
- name: Setup Java
22-
uses: actions/setup-java@v2
23-
with:
24-
distribution: 'zulu'
25-
java-version: 15
26-
- name: Cache Gradle
27-
uses: actions/cache@v2
28-
env:
29-
java-version: 15
30-
with:
31-
path: |
32-
~/.gradle/caches
33-
~/.gradle/wrapper
34-
key: ${{ runner.os }}-${{ env.java-version }}-gradle-${{ hashFiles('**/*.gradle*') }}
35-
restore-keys: ${{ runner.os }}-${{ env.java-version }}-gradle-
36-
- name: Make gradlew executable
37-
run: chmod +x ./gradlew
38-
- name: Gradle Check
39-
run: ./gradlew --info build -x test
40-
4114
test:
4215
name: Test run
4316
strategy:
@@ -70,11 +43,11 @@ jobs:
7043
run: chmod +x ./gradlew
7144
- name: Gradle Check (non-Windows)
7245
if: matrix.os != 'windows-latest'
73-
run: ./gradlew --info check -x verifyGoogleJavaFormat
46+
run: ./gradlew --info check
7447
- name: Gradle Check (Windows)
7548
if: matrix.os == 'windows-latest'
7649
shell: cmd
77-
run: gradlew --info check -x verifyGoogleJavaFormat
50+
run: gradlew --info check
7851

7952
build:
8053
name: Sonar analysis
@@ -112,4 +85,4 @@ jobs:
11285
env:
11386
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
11487
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
115-
run: ./gradlew build jacocoTestReport sonarqube --info -x verifyGoogleJavaFormat
88+
run: ./gradlew build jacocoTestReport sonarqube --info

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Make gradlew executable
3636
run: chmod +x ./gradlew
3737
- name: Gradle Check
38-
run: ./gradlew --info check -x verifyGoogleJavaFormat
38+
run: ./gradlew --info check
3939

4040
build:
4141
name: Publish release

.github/workflows/snapshot.yml

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,6 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- uses: gradle/wrapper-validation-action@v1
1414

15-
verify-google-java-format:
16-
name: Google Java Format Verification
17-
runs-on: ubuntu-latest
18-
needs: validation
19-
steps:
20-
- name: Checkout
21-
uses: actions/checkout@v2
22-
- name: Setup Java
23-
uses: actions/setup-java@v2
24-
with:
25-
distribution: 'zulu'
26-
java-version: 15
27-
- name: Cache Gradle
28-
uses: actions/cache@v2
29-
env:
30-
java-version: 15
31-
with:
32-
path: |
33-
~/.gradle/caches
34-
~/.gradle/wrapper
35-
key: ${{ runner.os }}-${{ env.java-version }}-gradle-${{ hashFiles('**/*.gradle*') }}
36-
restore-keys: ${{ runner.os }}-${{ env.java-version }}-gradle-
37-
- name: Make gradlew executable
38-
run: chmod +x ./gradlew
39-
- name: Gradle Check
40-
run: ./gradlew --info build -x test
41-
4215
test:
4316
name: Test run
4417
needs: validation
@@ -65,7 +38,7 @@ jobs:
6538
- name: Make gradlew executable
6639
run: chmod +x ./gradlew
6740
- name: Gradle Check
68-
run: ./gradlew --info check -x verifyGoogleJavaFormat
41+
run: ./gradlew --info check
6942

7043
build:
7144
name: Publish snapshot
@@ -97,7 +70,7 @@ jobs:
9770
env:
9871
OSS_USER_TOKEN_KEY: ${{ secrets.OSS_USER_TOKEN_KEY }}
9972
OSS_USER_TOKEN_PASS: ${{ secrets.OSS_USER_TOKEN_PASS }}
100-
run: ./gradlew clean build publish -x test -x verifyGoogleJavaFormat
73+
run: ./gradlew clean build publish -x test
10174

10275
sonar:
10376
name: Sonar analysis
@@ -129,4 +102,4 @@ jobs:
129102
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
130103
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
131104
if: env.SONAR_TOKEN != null
132-
run: ./gradlew build jacocoTestReport sonarqube --info -x verifyGoogleJavaFormat
105+
run: ./gradlew build jacocoTestReport sonarqube --info

build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ plugins {
3131
id "org.sonarqube" version "3.2.0"
3232
id "jacoco"
3333
id 'io.codearte.nexus-staging' version '0.30.0'
34-
id 'com.github.sherter.google-java-format' version '0.9' apply false
3534
}
3635

3736
sonarqube {
@@ -49,7 +48,6 @@ subprojects {
4948
apply plugin: 'java'
5049
apply plugin: 'maven-publish'
5150
apply plugin: 'signing'
52-
apply plugin: 'com.github.sherter.google-java-format'
5351

5452
repositories {
5553
mavenLocal()
@@ -80,8 +78,6 @@ subprojects {
8078

8179
compileJava.dependsOn(processResources)
8280

83-
compileJava.mustRunAfter verifyGoogleJavaFormat
84-
8581
test {
8682
useJUnitPlatform()
8783

github-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ git config --global user.name "GitHub Actions"
4545
echo "Deploying release to Maven Central"
4646
removeSnapshots
4747

48-
./gradlew clean build publish closeAndReleaseRepository -x verifyGoogleJavaFormat
48+
./gradlew clean build publish closeAndReleaseRepository
4949

5050
commitRelease
5151
bumpVersion
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package graphql.kickstart.execution;
2+
3+
import graphql.ExecutionResult;
4+
import graphql.kickstart.execution.input.GraphQLInvocationInput;
5+
import java.util.List;
6+
import java.util.concurrent.CompletableFuture;
7+
import lombok.Getter;
8+
import lombok.RequiredArgsConstructor;
9+
10+
@RequiredArgsConstructor
11+
class FutureBatchedExecutionResult implements FutureExecutionResult {
12+
13+
@Getter
14+
private final GraphQLInvocationInput invocationInput;
15+
private final CompletableFuture<List<ExecutionResult>> batched;
16+
17+
@Override
18+
public CompletableFuture<GraphQLQueryResult> thenApplyQueryResult() {
19+
return batched.thenApply(GraphQLQueryResult::create);
20+
}
21+
22+
@Override
23+
public void cancel() {
24+
batched.cancel(true);
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package graphql.kickstart.execution;
2+
3+
import graphql.kickstart.execution.input.GraphQLInvocationInput;
4+
import java.util.concurrent.CompletableFuture;
5+
import lombok.RequiredArgsConstructor;
6+
7+
@RequiredArgsConstructor
8+
class FutureErrorExecutionResult implements FutureExecutionResult {
9+
10+
private final GraphQLErrorQueryResult errorQueryResult;
11+
12+
@Override
13+
public CompletableFuture<GraphQLQueryResult> thenApplyQueryResult() {
14+
return CompletableFuture.completedFuture(errorQueryResult);
15+
}
16+
17+
@Override
18+
public GraphQLInvocationInput getInvocationInput() {
19+
return null;
20+
}
21+
22+
@Override
23+
public void cancel() {
24+
// nothing to do
25+
}
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package graphql.kickstart.execution;
2+
3+
import graphql.ExecutionResult;
4+
import graphql.kickstart.execution.input.GraphQLInvocationInput;
5+
import java.util.List;
6+
import java.util.concurrent.CompletableFuture;
7+
8+
public interface FutureExecutionResult {
9+
10+
static FutureExecutionResult single(
11+
GraphQLInvocationInput invocationInput, CompletableFuture<ExecutionResult> single) {
12+
return new FutureSingleExecutionResult(invocationInput, single);
13+
}
14+
15+
static FutureExecutionResult batched(
16+
GraphQLInvocationInput invocationInput, CompletableFuture<List<ExecutionResult>> batched) {
17+
return new FutureBatchedExecutionResult(invocationInput, batched);
18+
}
19+
20+
static FutureExecutionResult error(GraphQLErrorQueryResult result) {
21+
return new FutureErrorExecutionResult(result);
22+
}
23+
24+
CompletableFuture<GraphQLQueryResult> thenApplyQueryResult();
25+
26+
GraphQLInvocationInput getInvocationInput();
27+
28+
void cancel();
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package graphql.kickstart.execution;
2+
3+
import graphql.ExecutionResult;
4+
import graphql.kickstart.execution.input.GraphQLInvocationInput;
5+
import java.util.concurrent.CompletableFuture;
6+
import lombok.Getter;
7+
import lombok.RequiredArgsConstructor;
8+
9+
@RequiredArgsConstructor
10+
class FutureSingleExecutionResult implements FutureExecutionResult {
11+
12+
@Getter
13+
private final GraphQLInvocationInput invocationInput;
14+
private final CompletableFuture<ExecutionResult> single;
15+
16+
@Override
17+
public CompletableFuture<GraphQLQueryResult> thenApplyQueryResult() {
18+
return single.thenApply(GraphQLQueryResult::create);
19+
}
20+
21+
@Override
22+
public void cancel() {
23+
single.cancel(true);
24+
}
25+
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLInvoker.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,25 @@
1212
import java.util.List;
1313
import java.util.concurrent.CompletableFuture;
1414
import lombok.RequiredArgsConstructor;
15+
import lombok.extern.slf4j.Slf4j;
1516

17+
@Slf4j
1618
@RequiredArgsConstructor
1719
public class GraphQLInvoker {
1820

1921
private final GraphQLBuilder graphQLBuilder;
2022
private final BatchedDataLoaderGraphQLBuilder batchedDataLoaderGraphQLBuilder;
2123
private final GraphQLInvokerProxy proxy = GraphQL::executeAsync;
2224

25+
public FutureExecutionResult execute(GraphQLInvocationInput invocationInput) {
26+
if (invocationInput instanceof GraphQLSingleInvocationInput) {
27+
return FutureExecutionResult.single(
28+
invocationInput, executeAsync((GraphQLSingleInvocationInput) invocationInput));
29+
}
30+
return FutureExecutionResult.batched(
31+
invocationInput, executeAsync((GraphQLBatchedInvocationInput) invocationInput));
32+
}
33+
2334
public CompletableFuture<ExecutionResult> executeAsync(
2435
GraphQLSingleInvocationInput invocationInput) {
2536
GraphQL graphQL = graphQLBuilder.build(invocationInput.getSchema());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package graphql.kickstart.servlet;
2+
3+
import java.io.IOException;
4+
import javax.servlet.AsyncEvent;
5+
import javax.servlet.AsyncListener;
6+
7+
interface AsyncTimeoutListener extends AsyncListener {
8+
9+
default void onComplete(AsyncEvent event) throws IOException {}
10+
11+
default void onError(AsyncEvent event) throws IOException {}
12+
13+
default void onStartAsync(AsyncEvent event) throws IOException {}
14+
}

0 commit comments

Comments
 (0)