Skip to content

Commit c6bb935

Browse files
committed
Merge branch 'master' into pretty-printer
2 parents 6030b3a + 35ff68d commit c6bb935

File tree

157 files changed

+19369
-1282
lines changed

Some content is hidden

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

157 files changed

+19369
-1282
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ on:
77
pull_request:
88
branches:
99
- master
10+
- 19.x
1011
- 18.x
12+
- 17.x
1113
jobs:
1214
buildAndTest:
1315
runs-on: ubuntu-latest

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ dependencies {
8888
compileOnly 'org.jetbrains:annotations:23.0.0'
8989
implementation 'org.antlr:antlr4-runtime:' + antlrVersion
9090
implementation 'org.slf4j:slf4j-api:' + slf4jVersion
91-
api 'com.graphql-java:java-dataloader:3.1.4'
91+
api 'com.graphql-java:java-dataloader:3.2.0'
9292
api 'org.reactivestreams:reactive-streams:' + reactiveStreamsVersion
9393
antlr 'org.antlr:antlr4:' + antlrVersion
9494
implementation 'com.google.guava:guava:31.0.1-jre'

src/main/java/graphql/ExecutionInput.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ public DataLoaderRegistry getDataLoaderRegistry() {
120120

121121
/**
122122
* @return the cache control helper associated with this execution
123+
*
124+
* @deprecated - Apollo has deprecated the Cache Control specification
123125
*/
126+
@Deprecated
124127
public CacheControl getCacheControl() {
125128
return cacheControl;
126129
}
@@ -225,7 +228,7 @@ public static class Builder {
225228
//
226229
private DataLoaderRegistry dataLoaderRegistry = DataLoaderDispatcherInstrumentationState.EMPTY_DATALOADER_REGISTRY;
227230
private CacheControl cacheControl = CacheControl.newCacheControl();
228-
private Locale locale;
231+
private Locale locale = Locale.getDefault();
229232
private ExecutionId executionId;
230233

231234
public Builder query(String query) {
@@ -390,6 +393,7 @@ public Builder dataLoaderRegistry(DataLoaderRegistry dataLoaderRegistry) {
390393
return this;
391394
}
392395

396+
@Deprecated
393397
public Builder cacheControl(CacheControl cacheControl) {
394398
this.cacheControl = assertNotNull(cacheControl);
395399
return this;

src/main/java/graphql/GraphQL.java

Lines changed: 16 additions & 11 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());
@@ -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
}

src/main/java/graphql/ParseAndValidate.java

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

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

15+
import static java.util.Optional.ofNullable;
16+
1417
/**
1518
* This class allows you to parse and validate a graphql query without executing it. It will tell you
1619
* if it's syntactically valid and also semantically valid according to the graphql specification
@@ -40,7 +43,7 @@ public class ParseAndValidate {
4043
public static ParseAndValidateResult parseAndValidate(GraphQLSchema graphQLSchema, ExecutionInput executionInput) {
4144
ParseAndValidateResult result = parse(executionInput);
4245
if (!result.isFailure()) {
43-
List<ValidationError> errors = validate(graphQLSchema, result.getDocument());
46+
List<ValidationError> errors = validate(graphQLSchema, result.getDocument(), executionInput.getLocale());
4447
return result.transform(builder -> builder.validationErrors(errors));
4548
}
4649
return result;
@@ -58,6 +61,8 @@ public static ParseAndValidateResult parse(ExecutionInput executionInput) {
5861
//
5962
// we allow the caller to specify new parser options by context
6063
ParserOptions parserOptions = executionInput.getGraphQLContext().get(ParserOptions.class);
64+
// we use the query parser options by default if they are not specified
65+
parserOptions = ofNullable(parserOptions).orElse(ParserOptions.getDefaultOperationParserOptions());
6166
Parser parser = new Parser();
6267
Document document = parser.parseDocument(executionInput.getQuery(), parserOptions);
6368
return ParseAndValidateResult.newResult().document(document).variables(executionInput.getVariables()).build();
@@ -71,11 +76,24 @@ public static ParseAndValidateResult parse(ExecutionInput executionInput) {
7176
*
7277
* @param graphQLSchema the graphql schema to validate against
7378
* @param parsedDocument the previously parsed document
79+
* @param locale the current locale
80+
*
81+
* @return a result object that indicates how this operation went
82+
*/
83+
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Locale locale) {
84+
return validate(graphQLSchema, parsedDocument, ruleClass -> true, locale);
85+
}
86+
87+
/**
88+
* This can be called to validate a parsed graphql query, with the JVM default locale.
89+
*
90+
* @param graphQLSchema the graphql schema to validate against
91+
* @param parsedDocument the previously parsed document
7492
*
7593
* @return a result object that indicates how this operation went
7694
*/
7795
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument) {
78-
return validate(graphQLSchema, parsedDocument, ruleClass -> true);
96+
return validate(graphQLSchema, parsedDocument, ruleClass -> true, Locale.getDefault());
7997
}
8098

8199
/**
@@ -84,11 +102,26 @@ public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Docume
84102
* @param graphQLSchema the graphql schema to validate against
85103
* @param parsedDocument the previously parsed document
86104
* @param rulePredicate this predicate is used to decide what validation rules will be applied
105+
* @param locale the current locale
106+
*
107+
* @return a result object that indicates how this operation went
108+
*/
109+
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate, Locale locale) {
110+
Validator validator = new Validator();
111+
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate, locale);
112+
}
113+
114+
/**
115+
* This can be called to validate a parsed graphql query, with the JVM default locale.
116+
*
117+
* @param graphQLSchema the graphql schema to validate against
118+
* @param parsedDocument the previously parsed document
119+
* @param rulePredicate this predicate is used to decide what validation rules will be applied
87120
*
88121
* @return a result object that indicates how this operation went
89122
*/
90123
public static List<ValidationError> validate(GraphQLSchema graphQLSchema, Document parsedDocument, Predicate<Class<?>> rulePredicate) {
91124
Validator validator = new Validator();
92-
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate);
125+
return validator.validateDocument(graphQLSchema, parsedDocument, rulePredicate, Locale.getDefault());
93126
}
94127
}

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(), CoercedVariables.of(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,

src/main/java/graphql/analysis/QueryTraverser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private QueryTraverser(GraphQLSchema schema,
7070
this.fragmentsByName = getOperationResult.fragmentsByName;
7171
this.roots = singletonList(getOperationResult.operationDefinition);
7272
this.rootParentType = getRootTypeFromOperation(getOperationResult.operationDefinition);
73-
this.coercedVariables = new ValuesResolver().coerceVariableValues(schema, variableDefinitions, rawVariables);
73+
this.coercedVariables = ValuesResolver.coerceVariableValues(schema, variableDefinitions, rawVariables);
7474
}
7575

7676
private QueryTraverser(GraphQLSchema schema,

0 commit comments

Comments
 (0)