From cb886dc26d18e2352a3661b80d74a5bd494013d6 Mon Sep 17 00:00:00 2001 From: Andreas Marek Date: Sat, 21 Feb 2026 13:49:56 +1000 Subject: [PATCH] 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 --- src/jmh/java/benchmark/SchemaTransformerBenchmark.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/jmh/java/benchmark/SchemaTransformerBenchmark.java b/src/jmh/java/benchmark/SchemaTransformerBenchmark.java index 353dd0253e..49f3fc7ee9 100644 --- a/src/jmh/java/benchmark/SchemaTransformerBenchmark.java +++ b/src/jmh/java/benchmark/SchemaTransformerBenchmark.java @@ -1,5 +1,6 @@ package benchmark; +import graphql.introspection.Introspection.DirectiveLocation; import graphql.schema.GraphQLDirective; import graphql.schema.GraphQLFieldDefinition; import graphql.schema.GraphQLObjectType; @@ -42,6 +43,8 @@ public static class MyState { GraphQLDirective infoDirective = GraphQLDirective.newDirective() .name("Info") + .validLocation(DirectiveLocation.FIELD_DEFINITION) + .validLocation(DirectiveLocation.OBJECT) .build(); GraphQLTypeVisitor directiveAdder = new GraphQLTypeVisitorStub() { @Override @@ -94,6 +97,8 @@ public void setup() { try { String schemaString = BenchmarkUtils.loadResource("large-schema-3.graphqls"); schema = SchemaGenerator.createdMockedSchema(schemaString); + // Declare the Info directive on the schema so validation passes after transformation + schema = schema.transform(builder -> builder.additionalDirective(infoDirective)); txSchema = SchemaTransformer.transformSchema(schema, directiveAdder); } catch (Exception e) { throw new RuntimeException(e);