Skip to content

Commit 884234a

Browse files
authored
Merge branch 'master' into claude/build-and-run-tests-SByLK
2 parents 688b7b6 + 1e867c2 commit 884234a

4 files changed

Lines changed: 72 additions & 14 deletions

File tree

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ dependencies {
130130
testImplementation 'org.junit.jupiter:junit-jupiter:5.14.1'
131131

132132
testImplementation 'org.spockframework:spock-core:2.4-groovy-5.0'
133-
testImplementation 'net.bytebuddy:byte-buddy:1.18.1'
133+
testImplementation 'net.bytebuddy:byte-buddy:1.18.5'
134134
testImplementation 'org.objenesis:objenesis:3.5'
135135
testImplementation 'org.apache.groovy:groovy:5.0.4'
136136
testImplementation 'org.apache.groovy:groovy-json:5.0.4'
137137
testImplementation 'com.google.code.gson:gson:2.13.2'
138138
testImplementation 'org.eclipse.jetty:jetty-server:11.0.26'
139-
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.21.0'
139+
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.21.1'
140140
testImplementation 'org.awaitility:awaitility-groovy:4.3.0'
141141
testImplementation 'com.github.javafaker:javafaker:1.0.2'
142142

@@ -156,13 +156,13 @@ dependencies {
156156
// this is needed for the idea jmh plugin to work correctly
157157
jmh 'org.openjdk.jmh:jmh-core:1.37'
158158
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
159-
jmh 'me.bechberger:ap-loader-all:4.0-10'
159+
jmh 'me.bechberger:ap-loader-all:4.3-12'
160160

161161
// comment this in if you want to run JMH benchmarks from idea
162162
// jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
163163

164164
errorprone 'com.uber.nullaway:nullaway:0.12.10'
165-
errorprone 'com.google.errorprone:error_prone_core:2.44.0'
165+
errorprone 'com.google.errorprone:error_prone_core:2.47.0'
166166

167167
// just tests - no Kotlin otherwise
168168
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'

src/jmh/java/benchmark/IntrospectionBenchmark.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,58 @@
88
import org.openjdk.jmh.annotations.Benchmark;
99
import org.openjdk.jmh.annotations.BenchmarkMode;
1010
import org.openjdk.jmh.annotations.Fork;
11+
import org.openjdk.jmh.annotations.Level;
1112
import org.openjdk.jmh.annotations.Measurement;
1213
import org.openjdk.jmh.annotations.Mode;
14+
import org.openjdk.jmh.annotations.OutputTimeUnit;
15+
import org.openjdk.jmh.annotations.Param;
1316
import org.openjdk.jmh.annotations.Scope;
17+
import org.openjdk.jmh.annotations.Setup;
1418
import org.openjdk.jmh.annotations.State;
1519
import org.openjdk.jmh.annotations.Warmup;
1620
import org.openjdk.jmh.runner.Runner;
1721
import org.openjdk.jmh.runner.RunnerException;
1822
import org.openjdk.jmh.runner.options.Options;
1923
import org.openjdk.jmh.runner.options.OptionsBuilder;
2024

25+
import java.util.concurrent.TimeUnit;
26+
2127
@State(Scope.Benchmark)
2228
@Warmup(iterations = 2, time = 5)
2329
@Measurement(iterations = 3)
2430
@Fork(2)
2531
public class IntrospectionBenchmark {
2632

33+
@Param({
34+
"large-schema-2.graphqls",
35+
"large-schema-3.graphqls",
36+
"large-schema-4.graphqls",
37+
"large-schema-5.graphqls",
38+
"large-schema-federated-1.graphqls"
39+
})
40+
String schemaFile;
41+
42+
private GraphQL graphQL;
43+
44+
@Setup(Level.Trial)
45+
public void setup() {
46+
String schema = loadSchema(schemaFile);
47+
GraphQLSchema graphQLSchema = SchemaGenerator.createdMockedSchema(schema);
48+
graphQL = GraphQL.newGraphQL(graphQLSchema).build();
49+
}
50+
51+
private static String loadSchema(String schemaFile) {
52+
if (schemaFile.equals("large-schema-5.graphqls")) {
53+
// This schema is split across two files due to its size (11.3 MB)
54+
return BenchmarkUtils.loadResource("large-schema-5.graphqls.part1")
55+
+ BenchmarkUtils.loadResource("large-schema-5.graphqls.part2");
56+
}
57+
return BenchmarkUtils.loadResource(schemaFile);
58+
}
59+
2760
@Benchmark
2861
@BenchmarkMode(Mode.AverageTime)
62+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
2963
public ExecutionResult benchMarkIntrospectionAvgTime() {
3064
return graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY);
3165
}
@@ -36,16 +70,6 @@ public ExecutionResult benchMarkIntrospectionThroughput() {
3670
return graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY);
3771
}
3872

39-
private final GraphQL graphQL;
40-
41-
42-
public IntrospectionBenchmark() {
43-
String largeSchema = BenchmarkUtils.loadResource("large-schema-4.graphqls");
44-
GraphQLSchema graphQLSchema = SchemaGenerator.createdMockedSchema(largeSchema);
45-
graphQL = GraphQL.newGraphQL(graphQLSchema)
46-
.build();
47-
}
48-
4973
public static void main(String[] args) throws RunnerException {
5074
Options opt = new OptionsBuilder()
5175
.include("benchmark.IntrospectionBenchmark")

src/main/java/graphql/execution/DataFetcherResult.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ public static <T> Builder<T> newResult() {
175175
return new Builder<>();
176176
}
177177

178+
/**
179+
* Creates a new data fetcher result builder with associated data.
180+
* <p>Data may later be overwritten using {@link Builder#data(Object)}.
181+
*
182+
* @param data the data
183+
* @param <T> the type of the result
184+
*
185+
* @return a new builder
186+
*/
187+
public static <T> Builder<@Nullable T> newResult(@Nullable T data) {
188+
return new Builder<>(data);
189+
}
190+
178191
public static class Builder<T extends @Nullable Object> {
179192
private @Nullable T data;
180193
private @Nullable Object localContext;

src/test/groovy/graphql/execution/DataFetcherResultTest.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ class DataFetcherResultTest extends Specification {
2121
result.getErrors() == [error1, error2]
2222
}
2323

24+
def "building with generics"() {
25+
when:
26+
DataFetcherResult<String> result = DataFetcherResult.newResult("hello")
27+
.error(error1).errors([error2]).localContext("world").build()
28+
then:
29+
result.getData() == "hello"
30+
result.getLocalContext() == "world"
31+
result.getErrors() == [error1, error2]
32+
}
33+
34+
def "building with generics data can be overwritten in builder"() {
35+
when:
36+
DataFetcherResult<String> result = DataFetcherResult.newResult("someText")
37+
.data("hello")
38+
.error(error1).errors([error2]).localContext("world").build()
39+
then:
40+
result.getData() == "hello"
41+
result.getLocalContext() == "world"
42+
result.getErrors() == [error1, error2]
43+
}
44+
2445
def "hasErrors can be called"() {
2546
when:
2647
def builder = DataFetcherResult.newResult()

0 commit comments

Comments
 (0)