Skip to content

Commit 9a54c18

Browse files
committed
Merge remote-tracking branch 'origin/master' into async-many-materialized-list-optimization
2 parents 659fe34 + f8f9892 commit 9a54c18

File tree

86 files changed

+3268
-4185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3268
-4185
lines changed

src/jmh/java/benchmark/OverlappingFieldValidationBenchmark.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import graphql.schema.GraphQLSchema;
99
import graphql.schema.idl.SchemaGenerator;
1010
import graphql.validation.LanguageTraversal;
11-
import graphql.validation.RulesVisitor;
11+
import graphql.validation.OperationValidationRule;
12+
import graphql.validation.OperationValidator;
1213
import graphql.validation.ValidationContext;
1314
import graphql.validation.ValidationError;
1415
import graphql.validation.ValidationErrorCollector;
15-
import graphql.validation.rules.OverlappingFieldsCanBeMerged;
1616
import org.openjdk.jmh.annotations.Benchmark;
1717
import org.openjdk.jmh.annotations.BenchmarkMode;
1818
import org.openjdk.jmh.annotations.Fork;
@@ -25,7 +25,6 @@
2525
import org.openjdk.jmh.annotations.Warmup;
2626
import org.openjdk.jmh.infra.Blackhole;
2727

28-
import java.util.Collections;
2928
import java.util.List;
3029
import java.util.Locale;
3130
import java.util.concurrent.TimeUnit;
@@ -78,9 +77,10 @@ private List<ValidationError> validateQuery(GraphQLSchema schema, Document docum
7877
ValidationErrorCollector errorCollector = new ValidationErrorCollector();
7978
I18n i18n = I18n.i18n(I18n.BundleType.Validation, Locale.ENGLISH);
8079
ValidationContext validationContext = new ValidationContext(schema, document, i18n);
81-
OverlappingFieldsCanBeMerged overlappingFieldsCanBeMerged = new OverlappingFieldsCanBeMerged(validationContext, errorCollector);
80+
OperationValidator operationValidator = new OperationValidator(validationContext, errorCollector,
81+
rule -> rule == OperationValidationRule.OVERLAPPING_FIELDS_CAN_BE_MERGED);
8282
LanguageTraversal languageTraversal = new LanguageTraversal();
83-
languageTraversal.traverse(document, new RulesVisitor(validationContext, Collections.singletonList(overlappingFieldsCanBeMerged)));
83+
languageTraversal.traverse(document, operationValidator);
8484
return errorCollector.getErrors();
8585
}
8686
}

src/jmh/java/performance/OverlappingFieldValidationPerformance.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import graphql.schema.GraphQLSchema;
1010
import graphql.schema.idl.SchemaGenerator;
1111
import graphql.validation.LanguageTraversal;
12-
import graphql.validation.RulesVisitor;
12+
import graphql.validation.OperationValidationRule;
13+
import graphql.validation.OperationValidator;
1314
import graphql.validation.ValidationContext;
1415
import graphql.validation.ValidationError;
1516
import graphql.validation.ValidationErrorCollector;
16-
import graphql.validation.rules.OverlappingFieldsCanBeMerged;
1717
import org.openjdk.jmh.annotations.Benchmark;
1818
import org.openjdk.jmh.annotations.BenchmarkMode;
1919
import org.openjdk.jmh.annotations.Fork;
@@ -27,7 +27,6 @@
2727
import org.openjdk.jmh.annotations.Warmup;
2828
import org.openjdk.jmh.infra.Blackhole;
2929

30-
import java.util.Collections;
3130
import java.util.List;
3231
import java.util.Locale;
3332
import java.util.concurrent.TimeUnit;
@@ -151,9 +150,10 @@ private List<ValidationError> validateQuery(GraphQLSchema schema, Document docum
151150
ValidationErrorCollector errorCollector = new ValidationErrorCollector();
152151
I18n i18n = I18n.i18n(I18n.BundleType.Validation, Locale.ENGLISH);
153152
ValidationContext validationContext = new ValidationContext(schema, document, i18n);
154-
OverlappingFieldsCanBeMerged overlappingFieldsCanBeMerged = new OverlappingFieldsCanBeMerged(validationContext, errorCollector);
153+
OperationValidator operationValidator = new OperationValidator(validationContext, errorCollector,
154+
rule -> rule == OperationValidationRule.OVERLAPPING_FIELDS_CAN_BE_MERGED);
155155
LanguageTraversal languageTraversal = new LanguageTraversal();
156-
languageTraversal.traverse(document, new RulesVisitor(validationContext, Collections.singletonList(overlappingFieldsCanBeMerged)));
156+
languageTraversal.traverse(document, operationValidator);
157157
Assert.assertTrue(errorCollector.getErrors().size() == 0);
158158
return errorCollector.getErrors();
159159
}

src/main/java/graphql/GraphQL.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import graphql.execution.preparsed.PreparsedDocumentProvider;
2626
import graphql.language.Document;
2727
import graphql.schema.GraphQLSchema;
28+
import graphql.validation.OperationValidationRule;
2829
import graphql.validation.ValidationError;
2930
import org.jspecify.annotations.NullMarked;
3031
import org.jspecify.annotations.NullUnmarked;
@@ -598,7 +599,7 @@ private List<ValidationError> validate(ExecutionInput executionInput, Document d
598599
InstrumentationContext<List<ValidationError>> validationCtx = nonNullCtx(instrumentation.beginValidation(new InstrumentationValidationParameters(executionInput, document, graphQLSchema), instrumentationState));
599600
validationCtx.onDispatched();
600601

601-
Predicate<Class<?>> validationRulePredicate = executionInput.getGraphQLContext().getOrDefault(ParseAndValidate.INTERNAL_VALIDATION_PREDICATE_HINT, r -> true);
602+
Predicate<OperationValidationRule> validationRulePredicate = executionInput.getGraphQLContext().getOrDefault(ParseAndValidate.INTERNAL_VALIDATION_PREDICATE_HINT, r -> true);
602603
Locale locale = executionInput.getLocale();
603604
List<ValidationError> validationErrors = ParseAndValidate.validate(graphQLSchema, document, validationRulePredicate, locale);
604605

src/main/java/graphql/ParseAndValidate.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import graphql.parser.ParserEnvironment;
77
import graphql.parser.ParserOptions;
88
import graphql.schema.GraphQLSchema;
9+
import graphql.validation.OperationValidationRule;
910
import graphql.validation.ValidationError;
1011
import graphql.validation.Validator;
12+
import org.jspecify.annotations.NonNull;
1113
import org.jspecify.annotations.NullMarked;
1214

1315
import java.util.List;
@@ -28,7 +30,7 @@ public class ParseAndValidate {
2830

2931
/**
3032
* This {@link GraphQLContext} hint can be used to supply a Predicate to the Validator so that certain rules can be skipped.
31-
* <p>
33+
*
3234
* This is an internal capability that you should use at your own risk. While we intend for this to be present for some time, the validation
3335
* rule class names may change, as may this mechanism.
3436
*/
@@ -44,7 +46,7 @@ public class ParseAndValidate {
4446
*
4547
* @return a result object that indicates how this operation went
4648
*/
47-
public static ParseAndValidateResult parseAndValidate(GraphQLSchema graphQLSchema, ExecutionInput executionInput) {
49+
public static ParseAndValidateResult parseAndValidate(@NonNull GraphQLSchema graphQLSchema, @NonNull ExecutionInput executionInput) {
4850
ParseAndValidateResult result = parse(executionInput);
4951
if (!result.isFailure()) {
5052
List<ValidationError> errors = validate(graphQLSchema, assertNotNull(result.getDocument(), "Parse result document cannot be null when parse succeeded"), executionInput.getLocale());
@@ -60,7 +62,7 @@ public static ParseAndValidateResult parseAndValidate(GraphQLSchema graphQLSchem
6062
*
6163
* @return a result object that indicates how this operation went
6264
*/
63-
public static ParseAndValidateResult parse(ExecutionInput executionInput) {
65+
public static ParseAndValidateResult parse(@NonNull ExecutionInput executionInput) {
6466
try {
6567
//
6668
// we allow the caller to specify new parser options by context
@@ -89,8 +91,8 @@ public static ParseAndValidateResult parse(ExecutionInput executionInput) {
8991
*
9092
* @return a result object that indicates how this operation went
9193
*/
92-
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Locale locale) {
93-
return validate(graphQLSchema, parsedDocument, ruleClass -> true, locale);
94+
public static List<ValidationError> validate(@NonNull GraphQLSchema graphQLSchema, @NonNull Document parsedDocument, @NonNull Locale locale) {
95+
return validate(graphQLSchema, parsedDocument, rule -> true, locale);
9496
}
9597

9698
/**
@@ -101,8 +103,8 @@ public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Docume
101103
*
102104
* @return a result object that indicates how this operation went
103105
*/
104-
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument) {
105-
return validate(graphQLSchema, parsedDocument, ruleClass -> true, Locale.getDefault());
106+
public static List<ValidationError> validate(@NonNull GraphQLSchema graphQLSchema, @NonNull Document parsedDocument) {
107+
return validate(graphQLSchema, parsedDocument, rule -> true, Locale.getDefault());
106108
}
107109

108110
/**
@@ -115,7 +117,7 @@ public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Docume
115117
*
116118
* @return a result object that indicates how this operation went
117119
*/
118-
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate, Locale locale) {
120+
public static List<ValidationError> validate(@NonNull GraphQLSchema graphQLSchema, @NonNull Document parsedDocument, @NonNull Predicate<OperationValidationRule> rulePredicate, @NonNull Locale locale) {
119121
Validator validator = new Validator();
120122
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate, locale);
121123
}
@@ -129,7 +131,7 @@ public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Docume
129131
*
130132
* @return a result object that indicates how this operation went
131133
*/
132-
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate) {
134+
public static List<ValidationError> validate(@NonNull GraphQLSchema graphQLSchema, @NonNull Document parsedDocument, @NonNull Predicate<OperationValidationRule> rulePredicate) {
133135
Validator validator = new Validator();
134136
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate, Locale.getDefault());
135137
}

src/main/java/graphql/execution/MergedField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* </pre>
6262
* These examples make clear that you need to consider all merged fields together to have the full picture.
6363
* <p>
64-
* The actual logic when fields can be successfully merged together is implemented in {#graphql.validation.rules.OverlappingFieldsCanBeMerged}
64+
* The actual logic when fields can be successfully merged together is implemented in {#graphql.validation.OperationValidator}
6565
*/
6666
@PublicApi
6767
@NullMarked

src/main/java/graphql/normalized/ENFMerger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private static boolean compareWithoutChildren(ExecutableNormalizedField one, Exe
168168
return true;
169169
}
170170

171-
// copied from graphql.validation.rules.OverlappingFieldsCanBeMerged
171+
// copied from graphql.validation.OperationValidator
172172
private static boolean sameArguments(List<Argument> arguments1, List<Argument> arguments2) {
173173
if (arguments1.size() != arguments2.size()) {
174174
return false;

src/main/java/graphql/normalized/nf/NormalizedFieldsMerger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private static boolean compareWithoutChildren(NormalizedField one, NormalizedFie
166166
return true;
167167
}
168168

169-
// copied from graphql.validation.rules.OverlappingFieldsCanBeMerged
169+
// copied from graphql.validation.OperationValidator
170170
private static boolean sameArguments(List<Argument> arguments1, List<Argument> arguments2) {
171171
if (arguments1.size() != arguments2.size()) {
172172
return false;

src/main/java/graphql/schema/GraphQLSchema.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public Map<String, GraphQLDirective> getDirectivesByName() {
565565
*
566566
* @return the directive or null if there is not one with that name
567567
*/
568-
public GraphQLDirective getDirective(String directiveName) {
568+
public @Nullable GraphQLDirective getDirective(String directiveName) {
569569
return directiveDefinitionsHolder.getDirective(directiveName);
570570
}
571571

@@ -1215,6 +1215,7 @@ public FastBuilder(GraphQLCodeRegistry.Builder codeRegistryBuilder,
12151215
* multiple FastBuilder instances.
12161216
*
12171217
* @param type the named type to add
1218+
*
12181219
* @return this builder for chaining
12191220
*/
12201221
public FastBuilder addType(GraphQLNamedType type) {
@@ -1264,6 +1265,7 @@ public FastBuilder addType(GraphQLNamedType type) {
12641265
* All non-root types added via this method will be included in {@link GraphQLSchema#getAdditionalTypes()}.
12651266
*
12661267
* @param types the named types to add
1268+
*
12671269
* @return this builder for chaining
12681270
*/
12691271
public FastBuilder addTypes(Collection<? extends GraphQLNamedType> types) {
@@ -1275,6 +1277,7 @@ public FastBuilder addTypes(Collection<? extends GraphQLNamedType> types) {
12751277
* Adds a directive definition to the schema.
12761278
*
12771279
* @param directive the directive to add
1280+
*
12781281
* @return this builder for chaining
12791282
*/
12801283
public FastBuilder additionalDirective(GraphQLDirective directive) {
@@ -1296,6 +1299,7 @@ public FastBuilder additionalDirective(GraphQLDirective directive) {
12961299
* Adds multiple directive definitions to the schema.
12971300
*
12981301
* @param directives the directives to add
1302+
*
12991303
* @return this builder for chaining
13001304
*/
13011305
public FastBuilder additionalDirectives(Collection<? extends GraphQLDirective> directives) {
@@ -1307,6 +1311,7 @@ public FastBuilder additionalDirectives(Collection<? extends GraphQLDirective> d
13071311
* Adds a schema-level directive (deprecated, use applied directives).
13081312
*
13091313
* @param directive the directive to add
1314+
*
13101315
* @return this builder for chaining
13111316
*/
13121317
public FastBuilder withSchemaDirective(GraphQLDirective directive) {
@@ -1318,6 +1323,7 @@ public FastBuilder withSchemaDirective(GraphQLDirective directive) {
13181323
* Adds multiple schema-level directives.
13191324
*
13201325
* @param directives the directives to add
1326+
*
13211327
* @return this builder for chaining
13221328
*/
13231329
public FastBuilder withSchemaDirectives(Collection<? extends GraphQLDirective> directives) {
@@ -1329,6 +1335,7 @@ public FastBuilder withSchemaDirectives(Collection<? extends GraphQLDirective> d
13291335
* Adds a schema-level applied directive.
13301336
*
13311337
* @param applied the applied directive to add
1338+
*
13321339
* @return this builder for chaining
13331340
*/
13341341
public FastBuilder withSchemaAppliedDirective(GraphQLAppliedDirective applied) {
@@ -1342,6 +1349,7 @@ public FastBuilder withSchemaAppliedDirective(GraphQLAppliedDirective applied) {
13421349
* Adds multiple schema-level applied directives.
13431350
*
13441351
* @param appliedList the applied directives to add
1352+
*
13451353
* @return this builder for chaining
13461354
*/
13471355
public FastBuilder withSchemaAppliedDirectives(Collection<? extends GraphQLAppliedDirective> appliedList) {
@@ -1355,6 +1363,7 @@ public FastBuilder withSchemaAppliedDirectives(Collection<? extends GraphQLAppli
13551363
* Sets the schema definition (AST).
13561364
*
13571365
* @param def the schema definition
1366+
*
13581367
* @return this builder for chaining
13591368
*/
13601369
public FastBuilder definition(SchemaDefinition def) {
@@ -1366,6 +1375,7 @@ public FastBuilder definition(SchemaDefinition def) {
13661375
* Sets the schema extension definitions (AST).
13671376
*
13681377
* @param defs the extension definitions
1378+
*
13691379
* @return this builder for chaining
13701380
*/
13711381
public FastBuilder extensionDefinitions(List<SchemaExtensionDefinition> defs) {
@@ -1377,6 +1387,7 @@ public FastBuilder extensionDefinitions(List<SchemaExtensionDefinition> defs) {
13771387
* Sets the schema description.
13781388
*
13791389
* @param description the description
1390+
*
13801391
* @return this builder for chaining
13811392
*/
13821393
public FastBuilder description(String description) {
@@ -1388,6 +1399,7 @@ public FastBuilder description(String description) {
13881399
* Sets the introspection schema type.
13891400
*
13901401
* @param type the introspection schema type
1402+
*
13911403
* @return this builder for chaining
13921404
*/
13931405
public FastBuilder introspectionSchemaType(GraphQLObjectType type) {
@@ -1399,6 +1411,7 @@ public FastBuilder introspectionSchemaType(GraphQLObjectType type) {
13991411
* Enables or disables schema validation.
14001412
*
14011413
* @param enabled true to enable validation, false to disable
1414+
*
14021415
* @return this builder for chaining
14031416
*/
14041417
public FastBuilder withValidation(boolean enabled) {
@@ -1415,9 +1428,10 @@ public FastBuilder withValidation(boolean enabled) {
14151428
* should not be reused with another FastBuilder.
14161429
*
14171430
* @return the built schema
1431+
*
14181432
* @throws InvalidSchemaException if validation is enabled and the schema is invalid
1419-
* @throws AssertException if a type reference cannot be resolved or if an interface/union
1420-
* type is missing a type resolver
1433+
* @throws AssertException if a type reference cannot be resolved or if an interface/union
1434+
* type is missing a type resolver
14211435
*/
14221436
public GraphQLSchema build() {
14231437
// Validate type resolvers for all interfaces and unions

0 commit comments

Comments
 (0)