Skip to content

Commit ba71a5d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 38bd765 + ab856e2 commit ba71a5d

175 files changed

Lines changed: 4943 additions & 1413 deletions

File tree

Some content is hidden

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

‎.github/workflows/pull_request.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
pull_request:
88
branches:
99
- master
10+
- 18.x
1011
jobs:
1112
buildAndTest:
1213
runs-on: ubuntu-latest

‎build.gradle‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
id "biz.aQute.bnd.builder" version "6.1.0"
1111
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
1212
id "groovy"
13+
id "me.champeau.jmh" version "0.6.6"
1314
}
1415

1516
def getDevelopmentVersion() {
@@ -87,7 +88,7 @@ dependencies {
8788
compileOnly 'org.jetbrains:annotations:23.0.0'
8889
implementation 'org.antlr:antlr4-runtime:' + antlrVersion
8990
implementation 'org.slf4j:slf4j-api:' + slf4jVersion
90-
api 'com.graphql-java:java-dataloader:3.1.2'
91+
api 'com.graphql-java:java-dataloader:3.2.0'
9192
api 'org.reactivestreams:reactive-streams:' + reactiveStreamsVersion
9293
antlr 'org.antlr:antlr4:' + antlrVersion
9394
implementation 'com.google.guava:guava:31.0.1-jre'
@@ -108,8 +109,10 @@ dependencies {
108109

109110
testImplementation 'org.testng:testng:6.1.1' // use for reactive streams test inheritance
110111

111-
testImplementation 'org.openjdk.jmh:jmh-core:1.34'
112-
testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.34'
112+
testImplementation 'org.openjdk.jmh:jmh-core:1.35'
113+
testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
114+
jmh 'org.openjdk.jmh:jmh-core:1.35'
115+
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
113116
}
114117

115118
shadowJar {
@@ -122,8 +125,10 @@ shadowJar {
122125
include 'com.google.common.math.*'
123126
include 'com.google.common.primitives.*'
124127
}
128+
relocate('org.antlr.v4.runtime', 'graphql.org.antlr.v4.runtime')
125129
dependencies {
126130
include(dependency('com.google.guava:guava:31.0.1-jre'))
131+
include(dependency('org.antlr:antlr4-runtime:' + antlrVersion))
127132
}
128133
from "LICENSE.md"
129134
from "src/main/antlr/Graphql.g4"
@@ -143,14 +148,14 @@ shadowJar {
143148
//Configure bnd for shadowJar
144149
// -exportcontents: graphql.* Adds all packages of graphql and below to the exported packages list
145150
// -removeheaders: Private-Package Removes the MANIFEST.MF header Private-Package, which contains all the internal packages and
146-
// also the repackaged pckages like guava, which would be wrong after repackaging.
151+
// also the repackaged packages like guava, which would be wrong after repackaging.
147152
// Import-Package: Changes the imported packages header, to exclude guava and dependencies from the import list (! excludes packages)
148153
// Guava was repackaged and included inside the jar, so we need remove it.
149154
// The last ,* copies all the existing imports from the other dependencies, which is required.
150155
bnd('''
151156
-exportcontents: graphql.*
152157
-removeheaders: Private-Package
153-
Import-Package: !com.google.*,!org.checkerframework.*,!javax.annotation.*,!graphql.com.google.*,*
158+
Import-Package: !com.google.*,!org.checkerframework.*,!javax.annotation.*,!graphql.com.google.*,!org.antlr.*,!graphql.org.antlr.*,*
154159
''')
155160
}
156161

@@ -238,15 +243,15 @@ publishing {
238243
classifier "javadoc"
239244
}
240245
pom.withXml {
241-
// The ANTLR-related code below--introduced in `1ac98bf`--addresses an issue with
246+
// Removing antlr4 below (introduced in `1ac98bf`) addresses an issue with
242247
// the Gradle ANTLR plugin. `1ac98bf` can be reverted and this comment removed once
243248
// that issue is fixed and Gradle upgraded. See https://goo.gl/L92KiF and https://goo.gl/FY0PVR.
244249
//
245-
// We are removing here guava because the classes we want to use is "shaded" into the jar itself
250+
// Removing antlr4-runtime and guava because the classes we want to use are "shaded" into the jar itself
246251
// via the shadowJar task
247252
def pomNode = asNode()
248253
pomNode.dependencies.'*'.findAll() {
249-
it.artifactId.text() == 'antlr4' || it.artifactId.text() == 'guava'
254+
it.artifactId.text() == 'antlr4' || it.artifactId.text() == 'antlr4-runtime' || it.artifactId.text() == 'guava'
250255
}.each() {
251256
it.parent().remove(it)
252257
}
@@ -308,4 +313,4 @@ tasks.withType(GenerateModuleMetadata) {
308313

309314
test {
310315
useJUnitPlatform()
311-
}
316+
}

‎src/main/java/graphql/ExecutionInput.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static class Builder {
225225
//
226226
private DataLoaderRegistry dataLoaderRegistry = DataLoaderDispatcherInstrumentationState.EMPTY_DATALOADER_REGISTRY;
227227
private CacheControl cacheControl = CacheControl.newCacheControl();
228-
private Locale locale;
228+
private Locale locale = Locale.getDefault();
229229
private ExecutionId executionId;
230230

231231
public Builder query(String query) {
@@ -367,7 +367,7 @@ public Builder root(Object root) {
367367
*/
368368
public Builder variables(Map<String, Object> rawVariables) {
369369
assertNotNull(rawVariables, () -> "variables map can't be null");
370-
this.rawVariables = new RawVariables(rawVariables);
370+
this.rawVariables = RawVariables.of(rawVariables);
371371
return this;
372372
}
373373

‎src/main/java/graphql/GraphQL.java‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import graphql.execution.instrumentation.Instrumentation;
1717
import graphql.execution.instrumentation.InstrumentationContext;
1818
import graphql.execution.instrumentation.InstrumentationState;
19+
import graphql.execution.instrumentation.NoContextChainedInstrumentation;
1920
import graphql.execution.instrumentation.SimpleInstrumentation;
2021
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
2122
import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters;
@@ -46,6 +47,7 @@
4647
import static graphql.Assert.assertNotNull;
4748
import static graphql.execution.ExecutionIdProvider.DEFAULT_EXECUTION_ID_PROVIDER;
4849
import static graphql.execution.instrumentation.SimpleInstrumentationContext.completeInstrumentationCtxCF;
50+
import static graphql.execution.instrumentation.SimpleInstrumentationContext.nonNullCtx;
4951

5052
/**
5153
* This class is where all graphql-java query execution begins. It combines the objects that are needed
@@ -512,22 +514,22 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
512514
InstrumentationState instrumentationState = instrumentation.createState(new InstrumentationCreateStateParameters(this.graphQLSchema, executionInput));
513515

514516
InstrumentationExecutionParameters inputInstrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState);
515-
executionInput = instrumentation.instrumentExecutionInput(executionInput, inputInstrumentationParameters);
517+
executionInput = instrumentation.instrumentExecutionInput(executionInput, inputInstrumentationParameters, instrumentationState);
516518

517519
CompletableFuture<ExecutionResult> beginExecutionCF = new CompletableFuture<>();
518520
InstrumentationExecutionParameters instrumentationParameters = new InstrumentationExecutionParameters(executionInput, this.graphQLSchema, instrumentationState);
519-
InstrumentationContext<ExecutionResult> executionInstrumentation = instrumentation.beginExecution(instrumentationParameters);
521+
InstrumentationContext<ExecutionResult> executionInstrumentation = nonNullCtx(instrumentation.beginExecution(instrumentationParameters, instrumentationState));
520522
executionInstrumentation.onDispatched(beginExecutionCF);
521523

522-
GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters);
524+
GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters, instrumentationState);
523525

524526
CompletableFuture<ExecutionResult> executionResult = parseValidateAndExecute(executionInput, graphQLSchema, instrumentationState);
525527
//
526528
// finish up instrumentation
527529
executionResult = executionResult.whenComplete(completeInstrumentationCtxCF(executionInstrumentation, beginExecutionCF));
528530
//
529531
// allow instrumentation to tweak the result
530-
executionResult = executionResult.thenCompose(result -> instrumentation.instrumentExecutionResult(result, instrumentationParameters));
532+
executionResult = executionResult.thenCompose(result -> instrumentation.instrumentExecutionResult(result, instrumentationParameters, instrumentationState));
531533
return executionResult;
532534
} catch (AbortExecutionException abortException) {
533535
return CompletableFuture.completedFuture(abortException.toExecutionResult());
@@ -589,7 +591,7 @@ private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput>
589591
final List<ValidationError> errors = validate(executionInput, document, graphQLSchema, instrumentationState);
590592
if (!errors.isEmpty()) {
591593
logNotSafe.warn("Query did not validate : '{}'", query);
592-
return new PreparsedDocumentEntry(errors);
594+
return new PreparsedDocumentEntry(document, errors);
593595
}
594596

595597
return new PreparsedDocumentEntry(document);
@@ -598,32 +600,32 @@ private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput>
598600

599601
private ParseAndValidateResult parse(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
600602
InstrumentationExecutionParameters parameters = new InstrumentationExecutionParameters(executionInput, graphQLSchema, instrumentationState);
601-
InstrumentationContext<Document> parseInstrumentation = instrumentation.beginParse(parameters);
603+
InstrumentationContext<Document> parseInstrumentationCtx = nonNullCtx(instrumentation.beginParse(parameters, instrumentationState));
602604
CompletableFuture<Document> documentCF = new CompletableFuture<>();
603-
parseInstrumentation.onDispatched(documentCF);
605+
parseInstrumentationCtx.onDispatched(documentCF);
604606

605607
ParseAndValidateResult parseResult = ParseAndValidate.parse(executionInput);
606608
if (parseResult.isFailure()) {
607-
parseInstrumentation.onCompleted(null, parseResult.getSyntaxException());
609+
parseInstrumentationCtx.onCompleted(null, parseResult.getSyntaxException());
608610
return parseResult;
609611
} else {
610612
documentCF.complete(parseResult.getDocument());
611-
parseInstrumentation.onCompleted(parseResult.getDocument(), null);
613+
parseInstrumentationCtx.onCompleted(parseResult.getDocument(), null);
612614

613615
DocumentAndVariables documentAndVariables = parseResult.getDocumentAndVariables();
614-
documentAndVariables = instrumentation.instrumentDocumentAndVariables(documentAndVariables, parameters);
616+
documentAndVariables = instrumentation.instrumentDocumentAndVariables(documentAndVariables, parameters, instrumentationState);
615617
return ParseAndValidateResult.newResult()
616618
.document(documentAndVariables.getDocument()).variables(documentAndVariables.getVariables()).build();
617619
}
618620
}
619621

620622
private List<ValidationError> validate(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
621-
InstrumentationContext<List<ValidationError>> validationCtx = instrumentation.beginValidation(new InstrumentationValidationParameters(executionInput, document, graphQLSchema, instrumentationState));
623+
InstrumentationContext<List<ValidationError>> validationCtx = nonNullCtx(instrumentation.beginValidation(new InstrumentationValidationParameters(executionInput, document, graphQLSchema, instrumentationState), instrumentationState));
622624
CompletableFuture<List<ValidationError>> cf = new CompletableFuture<>();
623625
validationCtx.onDispatched(cf);
624626

625627
Predicate<Class<?>> validationRulePredicate = executionInput.getGraphQLContext().getOrDefault(ParseAndValidate.INTERNAL_VALIDATION_PREDICATE_HINT, r -> true);
626-
List<ValidationError> validationErrors = ParseAndValidate.validate(graphQLSchema, document, validationRulePredicate);
628+
List<ValidationError> validationErrors = ParseAndValidate.validate(graphQLSchema, document, validationRulePredicate, executionInput.getLocale());
627629

628630
validationCtx.onCompleted(validationErrors, null);
629631
cf.complete(validationErrors);
@@ -663,6 +665,9 @@ private static Instrumentation checkInstrumentationDefaultState(Instrumentation
663665
if (instrumentation instanceof DataLoaderDispatcherInstrumentation) {
664666
return instrumentation;
665667
}
668+
if (instrumentation instanceof NoContextChainedInstrumentation) {
669+
return instrumentation;
670+
}
666671
if (instrumentation == null) {
667672
return new DataLoaderDispatcherInstrumentation();
668673
}
@@ -683,4 +688,4 @@ private static Instrumentation checkInstrumentationDefaultState(Instrumentation
683688
}
684689
return new ChainedInstrumentation(instrumentationList);
685690
}
686-
}
691+
}

‎src/main/java/graphql/ParseAndValidate.java‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import graphql.validation.Validator;
1010

1111
import java.util.List;
12+
import java.util.Locale;
1213
import java.util.function.Predicate;
1314

1415
/**
@@ -40,7 +41,7 @@ public class ParseAndValidate {
4041
public static ParseAndValidateResult parseAndValidate(GraphQLSchema graphQLSchema, ExecutionInput executionInput) {
4142
ParseAndValidateResult result = parse(executionInput);
4243
if (!result.isFailure()) {
43-
List<ValidationError> errors = validate(graphQLSchema, result.getDocument());
44+
List<ValidationError> errors = validate(graphQLSchema, result.getDocument(), executionInput.getLocale());
4445
return result.transform(builder -> builder.validationErrors(errors));
4546
}
4647
return result;
@@ -71,11 +72,24 @@ public static ParseAndValidateResult parse(ExecutionInput executionInput) {
7172
*
7273
* @param graphQLSchema the graphql schema to validate against
7374
* @param parsedDocument the previously parsed document
75+
* @param locale the current locale
76+
*
77+
* @return a result object that indicates how this operation went
78+
*/
79+
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Locale locale) {
80+
return validate(graphQLSchema, parsedDocument, ruleClass -> true, locale);
81+
}
82+
83+
/**
84+
* This can be called to validate a parsed graphql query, with the JVM default locale.
85+
*
86+
* @param graphQLSchema the graphql schema to validate against
87+
* @param parsedDocument the previously parsed document
7488
*
7589
* @return a result object that indicates how this operation went
7690
*/
7791
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument) {
78-
return validate(graphQLSchema, parsedDocument, ruleClass -> true);
92+
return validate(graphQLSchema, parsedDocument, ruleClass -> true, Locale.getDefault());
7993
}
8094

8195
/**
@@ -84,11 +98,26 @@ public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Docume
8498
* @param graphQLSchema the graphql schema to validate against
8599
* @param parsedDocument the previously parsed document
86100
* @param rulePredicate this predicate is used to decide what validation rules will be applied
101+
* @param locale the current locale
102+
*
103+
* @return a result object that indicates how this operation went
104+
*/
105+
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate, Locale locale) {
106+
Validator validator = new Validator();
107+
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate, locale);
108+
}
109+
110+
/**
111+
* This can be called to validate a parsed graphql query, with the JVM default locale.
112+
*
113+
* @param graphQLSchema the graphql schema to validate against
114+
* @param parsedDocument the previously parsed document
115+
* @param rulePredicate this predicate is used to decide what validation rules will be applied
87116
*
88117
* @return a result object that indicates how this operation went
89118
*/
90119
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate) {
91120
Validator validator = new Validator();
92-
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate);
121+
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate, Locale.getDefault());
93122
}
94123
}

‎src/main/java/graphql/analysis/MaxQueryComplexityInstrumentation.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ QueryTraverser newQueryTraverser(ExecutionContext executionContext) {
147147
.schema(executionContext.getGraphQLSchema())
148148
.document(executionContext.getDocument())
149149
.operationName(executionContext.getExecutionInput().getOperationName())
150-
.variables(executionContext.getVariables())
150+
.coercedVariables(executionContext.getCoercedVariables())
151151
.build();
152152
}
153153

‎src/main/java/graphql/analysis/MaxQueryDepthInstrumentation.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ QueryTraverser newQueryTraverser(ExecutionContext executionContext) {
8484
.schema(executionContext.getGraphQLSchema())
8585
.document(executionContext.getDocument())
8686
.operationName(executionContext.getExecutionInput().getOperationName())
87-
.variables(executionContext.getVariables())
87+
.coercedVariables(executionContext.getCoercedVariables())
8888
.build();
8989
}
9090

‎src/main/java/graphql/analysis/NodeVisitorWithTypeTracking.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@
4343
@Internal
4444
public class NodeVisitorWithTypeTracking extends NodeVisitorStub {
4545

46-
4746
private final QueryVisitor preOrderCallback;
4847
private final QueryVisitor postOrderCallback;
4948
private final Map<String, Object> variables;
5049
private final GraphQLSchema schema;
5150
private final Map<String, FragmentDefinition> fragmentsByName;
52-
5351
private final ConditionalNodes conditionalNodes = new ConditionalNodes();
54-
private final ValuesResolver valuesResolver = new ValuesResolver();
55-
5652

5753
public NodeVisitorWithTypeTracking(QueryVisitor preOrderCallback, QueryVisitor postOrderCallback, Map<String, Object> variables, GraphQLSchema schema, Map<String, FragmentDefinition> fragmentsByName) {
5854
this.preOrderCallback = preOrderCallback;
@@ -155,7 +151,7 @@ public TraversalControl visitField(Field field, TraverserContext<Node> context)
155151
boolean isTypeNameIntrospectionField = fieldDefinition == schema.getIntrospectionTypenameFieldDefinition();
156152
GraphQLFieldsContainer fieldsContainer = !isTypeNameIntrospectionField ? (GraphQLFieldsContainer) unwrapAll(parentEnv.getOutputType()) : null;
157153
GraphQLCodeRegistry codeRegistry = schema.getCodeRegistry();
158-
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), field.getArguments(), new CoercedVariables(variables));
154+
Map<String, Object> argumentValues = ValuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), field.getArguments(), CoercedVariables.of(variables));
159155
QueryVisitorFieldEnvironment environment = new QueryVisitorFieldEnvironmentImpl(isTypeNameIntrospectionField,
160156
field,
161157
fieldDefinition,

0 commit comments

Comments
 (0)