Skip to content

Commit cb886dc

Browse files
andimarekclaude
andcommitted
Fix SchemaTransformerBenchmark to pass schema validation
The benchmark's `infoDirective` lacked valid locations, causing schema validation failures during `transformSchema`. Additionally, the directive was not declared on the schema, so the post-transformation validation would reject it. This meant the benchmark was measuring error-path behavior rather than the real transformation cost. - Add FIELD_DEFINITION and OBJECT valid locations to `infoDirective` - Declare `infoDirective` as an additional directive on the schema - Import `DirectiveLocation` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9ae83ab commit cb886dc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/jmh/java/benchmark/SchemaTransformerBenchmark.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package benchmark;
22

3+
import graphql.introspection.Introspection.DirectiveLocation;
34
import graphql.schema.GraphQLDirective;
45
import graphql.schema.GraphQLFieldDefinition;
56
import graphql.schema.GraphQLObjectType;
@@ -42,6 +43,8 @@ public static class MyState {
4243

4344
GraphQLDirective infoDirective = GraphQLDirective.newDirective()
4445
.name("Info")
46+
.validLocation(DirectiveLocation.FIELD_DEFINITION)
47+
.validLocation(DirectiveLocation.OBJECT)
4548
.build();
4649
GraphQLTypeVisitor directiveAdder = new GraphQLTypeVisitorStub() {
4750
@Override
@@ -94,6 +97,8 @@ public void setup() {
9497
try {
9598
String schemaString = BenchmarkUtils.loadResource("large-schema-3.graphqls");
9699
schema = SchemaGenerator.createdMockedSchema(schemaString);
100+
// Declare the Info directive on the schema so validation passes after transformation
101+
schema = schema.transform(builder -> builder.additionalDirective(infoDirective));
97102
txSchema = SchemaTransformer.transformSchema(schema, directiveAdder);
98103
} catch (Exception e) {
99104
throw new RuntimeException(e);

0 commit comments

Comments
 (0)