Skip to content

Commit

Permalink
Added graphql context to ValidationEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
bbakerman committed Aug 24, 2023
1 parent fde06da commit 6f77b80
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/graphql/validation/rules/ValidationEnvironment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.validation.rules;

import graphql.GraphQLContext;
import graphql.PublicApi;
import graphql.execution.ResultPath;
import graphql.language.SourceLocation;
Expand Down Expand Up @@ -55,6 +56,8 @@ public enum ValidatedElement {
private final Object validatedValue;
private final GraphQLInputType validatedType;
private final ValidatedElement validatedElement;

private final GraphQLContext graphQLContext;
private final List<GraphQLAppliedDirective> directives;

private ValidationEnvironment(Builder builder) {
Expand All @@ -71,6 +74,7 @@ private ValidationEnvironment(Builder builder) {
this.location = builder.location;
this.validatedValue = builder.validatedValue;
this.validatedElement = builder.validatedElement;
this.graphQLContext = builder.graphQLContext;
this.directives = builder.directives;
}

Expand Down Expand Up @@ -135,6 +139,10 @@ public List<GraphQLAppliedDirective> getDirectives() {
return directives;
}

public GraphQLContext getGraphQLContext() {
return graphQLContext;
}

public ValidationEnvironment transform(Consumer<Builder> builderConsumer) {
Builder builder = newValidationEnvironment().validationEnvironment(this);
builderConsumer.accept(builder);
Expand All @@ -156,6 +164,7 @@ public static class Builder {
private GraphQLInputType validatedType;
private ValidatedElement validatedElement;
private List<GraphQLAppliedDirective> directives = Collections.emptyList();
private GraphQLContext graphQLContext = GraphQLContext.getDefault();

public Builder validationEnvironment(ValidationEnvironment validationEnvironment) {
this.argument = validationEnvironment.argument;
Expand All @@ -172,6 +181,7 @@ public Builder validationEnvironment(ValidationEnvironment validationEnvironment
this.validatedValue = validationEnvironment.validatedValue;
this.validatedElement = validationEnvironment.validatedElement;
this.directives = validationEnvironment.directives;
this.graphQLContext = validationEnvironment.graphQLContext;
return this;
}

Expand All @@ -184,6 +194,7 @@ public Builder dataFetchingEnvironment(DataFetchingEnvironment dataFetchingEnvir
location(dataFetchingEnvironment.getField().getSourceLocation());
argumentValues(dataFetchingEnvironment.getArguments());
validatedElement(ValidatedElement.FIELD);
graphQLContext(dataFetchingEnvironment.getGraphQlContext());
return this;
}

Expand Down Expand Up @@ -252,6 +263,11 @@ public Builder locale(Locale locale) {
return this;
}

public Builder graphQLContext(GraphQLContext graphQLContext) {
this.graphQLContext = graphQLContext;
return this;
}

public Builder directives(List<GraphQLAppliedDirective> directives) {
this.directives = directives;
return this;
Expand Down

0 comments on commit 6f77b80

Please sign in to comment.