Skip to content
Open
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
19 changes: 18 additions & 1 deletion src/jmh/java/benchmark/TwitterBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLTypeReference;
import graphql.validation.QueryComplexityLimits;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -31,6 +32,7 @@
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static graphql.Assert.assertTrue;
import static graphql.Scalars.GraphQLString;

@Warmup(iterations = 2, time = 5)
Expand All @@ -44,6 +46,17 @@ public class TwitterBenchmark {
static Object queryId = "QUERY_ID";
static GraphQL graphQL = buildGraphQL();

// the query is deliberately deeper than the default max depth enforced by validation
private static final QueryComplexityLimits LIMITS = QueryComplexityLimits.newLimits()
.maxDepth(DEPTH + 1)
.build();

static {
// fail fast rather than silently benchmarking a validation error
ExecutionResult result = execute();
assertTrue(result.getErrors().isEmpty(), "TwitterBenchmark query failed: %s", result.getErrors());
}

@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
Expand All @@ -58,7 +71,11 @@ public void benchmarkAvgTime(Blackhole bh) {
}

private static ExecutionResult execute() {
return graphQL.execute(query);
ExecutionInput executionInput = ExecutionInput.newExecutionInput()
.query(query)
.graphQLContext(ctx -> ctx.put(QueryComplexityLimits.KEY, LIMITS))
.build();
return graphQL.execute(executionInput);
}

public static String mkQuery() {
Expand Down